1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Python 3 doesn't support slice assignment.
12 Solution: Implement slices. (Brett Overesch, Roland Puntaier)
13 Files: src/if_python3.c
16 *** ../vim-7.3.306/src/if_python3.c 2011-08-28 16:00:14.000000000 +0200
17 --- src/if_python3.c 2011-09-14 15:01:26.000000000 +0200
21 static Py_ssize_t BufferLength(PyObject *);
22 static PyObject *BufferItem(PyObject *, Py_ssize_t);
23 ! static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
24 ! static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val);
27 /* Line range type - Implementation functions
30 static Py_ssize_t BufferLength(PyObject *);
31 static PyObject *BufferItem(PyObject *, Py_ssize_t);
32 ! static PyObject* BufferSubscript(PyObject *self, PyObject *idx);
33 ! static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
36 /* Line range type - Implementation functions
40 #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
42 ! static PyObject* RangeSubscript(PyObject *self, PyObject* idx);
43 static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
45 /* Current objects type - Implementation functions
46 * -----------------------------------------------
49 #define RangeType_Check(obj) ((obj)->ob_base.ob_type == &RangeType)
51 ! static PyObject* RangeSubscript(PyObject *self, PyObject *idx);
52 static Py_ssize_t RangeAsItem(PyObject *, Py_ssize_t, PyObject *);
53 + static Py_ssize_t RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val);
55 /* Current objects type - Implementation functions
56 * -----------------------------------------------
59 &step, &slicelen) < 0) {
62 ! return BufferSlice(self,start,stop);
64 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
67 &step, &slicelen) < 0) {
70 ! return BufferSlice(self, start, stop);
72 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
76 PyMappingMethods RangeAsMapping = {
77 /* mp_length */ (lenfunc)RangeLength,
78 /* mp_subscript */ (binaryfunc)RangeSubscript,
79 ! /* mp_ass_subscript */ (objobjargproc)0,
82 /* Line range object - Implementation
84 PyMappingMethods RangeAsMapping = {
85 /* mp_length */ (lenfunc)RangeLength,
86 /* mp_subscript */ (binaryfunc)RangeSubscript,
87 ! /* mp_ass_subscript */ (objobjargproc)RangeAsSubscript,
90 /* Line range object - Implementation
94 &((RangeObject *)(self))->end);
98 + RangeAsSlice(PyObject *self, Py_ssize_t lo, Py_ssize_t hi, PyObject *val)
100 + return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
101 + ((RangeObject *)(self))->start,
102 + ((RangeObject *)(self))->end,
103 + &((RangeObject *)(self))->end);
107 RangeSubscript(PyObject *self, PyObject* idx)
111 &step, &slicelen) < 0) {
114 ! return RangeSlice(self,start,stop+1);
116 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
121 /* Buffer list object - Definitions
125 &step, &slicelen) < 0) {
128 ! return RangeSlice(self, start, stop);
130 PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
136 + RangeAsSubscript(PyObject *self, PyObject *idx, PyObject *val)
138 + if (PyLong_Check(idx)) {
139 + long n = PyLong_AsLong(idx);
140 + return RangeAsItem(self, n, val);
141 + } else if (PySlice_Check(idx)) {
142 + Py_ssize_t start, stop, step, slicelen;
144 + if (PySlice_GetIndicesEx((PySliceObject *)idx,
145 + ((RangeObject *)(self))->end-((RangeObject *)(self))->start+1,
147 + &step, &slicelen) < 0) {
150 + return RangeAsSlice(self, start, stop, val);
152 + PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
158 /* Buffer list object - Definitions
161 *** ../vim-7.3.306/src/version.c 2011-09-14 14:43:21.000000000 +0200
162 --- src/version.c 2011-09-14 14:58:16.000000000 +0200
166 { /* Add new patch number below this line */
172 The process for understanding customers primarily involves sitting around with
173 other marketing people and talking about what you would to if you were dumb
174 enough to be a customer.
175 (Scott Adams - The Dilbert principle)
177 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
178 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
179 \\\ an exciting new programming language -- http://www.Zimbu.org ///
180 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///