summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2011-09-14 15:01:58 +0200
committerBram Moolenaar <Bram@vim.org>2011-09-14 15:01:58 +0200
commitba4897e6e50ba3ce8c8744c0fb33a732af72147a (patch)
tree9e49bb98f6d5061bc64d0520c2fa92beb1c08eac
parenta971b82b160aca28cff7e318d4553df5349b5103 (diff)
downloadvim-git-ba4897e6e50ba3ce8c8744c0fb33a732af72147a.tar.gz
updated for version 7.3.307v7.3.307
Problem: Python 3 doesn't support slice assignment. Solution: Implement slices. (Brett Overesch, Roland Puntaier)
-rw-r--r--src/if_python3.c45
-rw-r--r--src/version.c2
2 files changed, 41 insertions, 6 deletions
diff --git a/src/if_python3.c b/src/if_python3.c
index 644cf188a..ebf402a4b 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -855,8 +855,8 @@ PythonIO_Fini(void)
static Py_ssize_t BufferLength(PyObject *);
static PyObject *BufferItem(PyObject *, Py_ssize_t);
-static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
-static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val);
+static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
+static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
/* Line range type - Implementation functions
@@ -865,8 +865,9 @@ static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val
#define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
-static PyObject* RangeSubscript(PyObject *self, PyObject* idx);
+static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
+static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
/* Current objects type - Implementation functions
* -----------------------------------------------
@@ -1035,7 +1036,7 @@ BufferSubscript(PyObject *self, PyObject* idx)
&step, &slicelen) < 0) {
return NULL;
}
- return BufferSlice(self,start,stop);
+ return BufferSlice(self, start, stop);
} else {
PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
return NULL;
@@ -1084,7 +1085,7 @@ static PySequenceMethods RangeAsSeq = {
PyMappingMethods RangeAsMapping = {
/* mp_length */ (lenfunc)RangeLength,
/* mp_subscript */ (binaryfunc)RangeSubscript,
- /* mp_ass_subscript */ (objobjargproc)0,
+ /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript,
};
/* Line range object - Implementation
@@ -1123,6 +1124,15 @@ RangeAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
&((RangeObject *)(self))->end);
}
+ static Py_ssize_t
+RangeAsSlice(PyObject *self, Py_ssize_t lo, Py_ssize_t hi, PyObject *val)
+{
+ return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
+ ((RangeObject *)(self))->start,
+ ((RangeObject *)(self))->end,
+ &((RangeObject *)(self))->end);
+}
+
static PyObject *
RangeSubscript(PyObject *self, PyObject* idx)
{
@@ -1138,13 +1148,36 @@ RangeSubscript(PyObject *self, PyObject* idx)
&step, &slicelen) < 0) {
return NULL;
}
- return RangeSlice(self,start,stop+1);
+ return RangeSlice(self, start, stop);
} else {
PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
return NULL;
}
}
+ static Py_ssize_t
+RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
+{
+ if (PyLong_Check(idx)) {
+ long n = PyLong_AsLong(idx);
+ return RangeAsItem(self, n, val);
+ } else if (PySlice_Check(idx)) {
+ Py_ssize_t start, stop, step, slicelen;
+
+ if (PySlice_GetIndicesEx((PySliceObject *)idx,
+ ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
+ &start, &stop,
+ &step, &slicelen) < 0) {
+ return -1;
+ }
+ return RangeAsSlice(self, start, stop, val);
+ } else {
+ PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ return -1;
+ }
+}
+
+
/* Buffer list object - Definitions
*/
diff --git a/src/version.c b/src/version.c
index 74ed44da4..74c27baae 100644
--- a/src/version.c
+++ b/src/version.c
@@ -710,6 +710,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 307,
+/**/
306,
/**/
305,