diff src/if_py_both.h @ 4387:358c10968c7f v7.3.942

updated for version 7.3.942 Problem: Python: SEGV in Buffer functions. Solution: Call CheckBuffer() at the right time. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Sun, 12 May 2013 20:36:14 +0200
parents da71e66dc1d4
children 736b8e18a3bc
line wrap: on
line diff
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -2391,6 +2391,9 @@ RBItem(BufferObject *self, PyInt n, PyIn
     if (CheckBuffer(self))
 	return NULL;
 
+    if (end == -1)
+	end = self->buf->b_ml.ml_line_count;
+
     if (n < 0 || n > end - start)
     {
 	PyErr_SetString(PyExc_IndexError, _("line number out of range"));
@@ -2408,6 +2411,9 @@ RBSlice(BufferObject *self, PyInt lo, Py
     if (CheckBuffer(self))
 	return NULL;
 
+    if (end == -1)
+	end = self->buf->b_ml.ml_line_count;
+
     size = end - start + 1;
 
     if (lo < 0)
@@ -2432,6 +2438,9 @@ RBAsItem(BufferObject *self, PyInt n, Py
     if (CheckBuffer(self))
 	return -1;
 
+    if (end == -1)
+	end = self->buf->b_ml.ml_line_count;
+
     if (n < 0 || n > end - start)
     {
 	PyErr_SetString(PyExc_IndexError, _("line number out of range"));
@@ -2457,6 +2466,9 @@ RBAsSlice(BufferObject *self, PyInt lo, 
     if (CheckBuffer(self))
 	return -1;
 
+    if (end == -1)
+	end = self->buf->b_ml.ml_line_count;
+
     /* Sort out the slice range */
     size = end - start + 1;
 
@@ -2493,6 +2505,9 @@ RBAppend(BufferObject *self, PyObject *a
     if (CheckBuffer(self))
 	return NULL;
 
+    if (end == -1)
+	end = self->buf->b_ml.ml_line_count;
+
     max = n = end - start + 1;
 
     if (!PyArg_ParseTuple(args, "O|n", &lines, &n))
@@ -2700,15 +2715,13 @@ BufferLength(PyObject *self)
     static PyObject *
 BufferItem(PyObject *self, PyInt n)
 {
-    return RBItem((BufferObject *)(self), n, 1,
-		  (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
+    return RBItem((BufferObject *)(self), n, 1, -1);
 }
 
     static PyObject *
 BufferSlice(PyObject *self, PyInt lo, PyInt hi)
 {
-    return RBSlice((BufferObject *)(self), lo, hi, 1,
-		   (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count);
+    return RBSlice((BufferObject *)(self), lo, hi, 1, -1);
 }
 
     static PyObject *
@@ -2732,9 +2745,7 @@ BufferAttr(BufferObject *this, char *nam
     static PyObject *
 BufferAppend(PyObject *self, PyObject *args)
 {
-    return RBAppend((BufferObject *)(self), args, 1,
-		    (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
-		    NULL);
+    return RBAppend((BufferObject *)(self), args, 1, -1, NULL);
 }
 
     static PyObject *