diff src/if_py_both.h @ 4389:736b8e18a3bc v7.3.943

updated for version 7.3.943 Problem: Python: Negative indices were failing. Solution: Fix negative indices. Add tests. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Sun, 12 May 2013 21:16:23 +0200
parents 358c10968c7f
children 80eea7a9d6b9
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -2394,6 +2394,9 @@ RBItem(BufferObject *self, PyInt n, PyIn
     if (end == -1)
 	end = self->buf->b_ml.ml_line_count;
 
+    if (n < 0)
+	n += end - start + 1;
+
     if (n < 0 || n > end - start)
     {
 	PyErr_SetString(PyExc_IndexError, _("line number out of range"));
@@ -2441,6 +2444,9 @@ RBAsItem(BufferObject *self, PyInt n, Py
     if (end == -1)
 	end = self->buf->b_ml.ml_line_count;
 
+    if (n < 0)
+	n += end - start + 1;
+
     if (n < 0 || n > end - start)
     {
 	PyErr_SetString(PyExc_IndexError, _("line number out of range"));