summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-08-30 22:57:53 (GMT)
committerThomas Wouters <thomas@python.org>2007-08-30 22:57:53 (GMT)
commitd2cf20eea2338a0369d4a5707adb01b201f7dfb2 (patch)
tree59fd4a094906997ae2b0cd520ff09010457da680 /Modules
parent582b5866174d20f7c027cbb6fb757fefb382f96f (diff)
downloadcpython-d2cf20eea2338a0369d4a5707adb01b201f7dfb2.zip
cpython-d2cf20eea2338a0369d4a5707adb01b201f7dfb2.tar.gz
cpython-d2cf20eea2338a0369d4a5707adb01b201f7dfb2.tar.bz2
Remove the simple slicing API. All slicing is now done with slice objects.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c94
-rw-r--r--Modules/arraymodule.c4
-rw-r--r--Modules/mmapmodule.c61
3 files changed, 7 insertions, 152 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index ced02c9..75792ad 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3702,52 +3702,6 @@ Array_item(PyObject *_self, Py_ssize_t index)
}
static PyObject *
-Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
-{
- CDataObject *self = (CDataObject *)_self;
- StgDictObject *stgdict, *itemdict;
- PyObject *proto;
- PyListObject *np;
- Py_ssize_t i, len;
-
- if (ilow < 0)
- ilow = 0;
- else if (ilow > self->b_length)
- ilow = self->b_length;
- if (ihigh < ilow)
- ihigh = ilow;
- else if (ihigh > self->b_length)
- ihigh = self->b_length;
- len = ihigh - ilow;
-
- stgdict = PyObject_stgdict((PyObject *)self);
- assert(stgdict); /* Cannot be NULL for array object instances */
- proto = stgdict->proto;
- itemdict = PyType_stgdict(proto);
- assert(itemdict); /* proto is the item type of the array, a ctypes
- type, so this cannot be NULL */
- if (itemdict->getfunc == getentry("c")->getfunc) {
- char *ptr = (char *)self->b_ptr;
- return PyString_FromStringAndSize(ptr + ilow, len);
-#ifdef CTYPES_UNICODE
- } else if (itemdict->getfunc == getentry("u")->getfunc) {
- wchar_t *ptr = (wchar_t *)self->b_ptr;
- return PyUnicode_FromWideChar(ptr + ilow, len);
-#endif
- }
-
- np = (PyListObject *) PyList_New(len);
- if (np == NULL)
- return NULL;
-
- for (i = 0; i < len; i++) {
- PyObject *v = Array_item(_self, i+ilow);
- PyList_SET_ITEM(np, i, v);
- }
- return (PyObject *)np;
-}
-
-static PyObject *
Array_subscript(PyObject *_self, PyObject *item)
{
CDataObject *self = (CDataObject *)_self;
@@ -3989,9 +3943,9 @@ static PySequenceMethods Array_as_sequence = {
0, /* sq_concat; */
0, /* sq_repeat; */
Array_item, /* sq_item; */
- Array_slice, /* sq_slice; */
+ 0, /* sq_slice; */
Array_ass_item, /* sq_ass_item; */
- Array_ass_slice, /* sq_ass_slice; */
+ 0, /* sq_ass_slice; */
0, /* sq_contains; */
0, /* sq_inplace_concat; */
@@ -4427,48 +4381,6 @@ Pointer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
static PyObject *
-Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
-{
- CDataObject *self = (CDataObject *)_self;
- PyListObject *np;
- StgDictObject *stgdict, *itemdict;
- PyObject *proto;
- Py_ssize_t i, len;
-
- if (ilow < 0)
- ilow = 0;
- if (ihigh < ilow)
- ihigh = ilow;
- len = ihigh - ilow;
-
- stgdict = PyObject_stgdict((PyObject *)self);
- assert(stgdict); /* Cannot be NULL fr pointer instances */
- proto = stgdict->proto;
- assert(proto);
- itemdict = PyType_stgdict(proto);
- assert(itemdict);
- if (itemdict->getfunc == getentry("c")->getfunc) {
- char *ptr = *(char **)self->b_ptr;
- return PyString_FromStringAndSize(ptr + ilow, len);
-#ifdef CTYPES_UNICODE
- } else if (itemdict->getfunc == getentry("u")->getfunc) {
- wchar_t *ptr = *(wchar_t **)self->b_ptr;
- return PyUnicode_FromWideChar(ptr + ilow, len);
-#endif
- }
-
- np = (PyListObject *) PyList_New(len);
- if (np == NULL)
- return NULL;
-
- for (i = 0; i < len; i++) {
- PyObject *v = Pointer_item(_self, i+ilow);
- PyList_SET_ITEM(np, i, v);
- }
- return (PyObject *)np;
-}
-
-static PyObject *
Pointer_subscript(PyObject *_self, PyObject *item)
{
CDataObject *self = (CDataObject *)_self;
@@ -4606,7 +4518,7 @@ static PySequenceMethods Pointer_as_sequence = {
0, /* binaryfunc sq_concat; */
0, /* intargfunc sq_repeat; */
Pointer_item, /* intargfunc sq_item; */
- Pointer_slice, /* intintargfunc sq_slice; */
+ 0, /* intintargfunc sq_slice; */
Pointer_ass_item, /* intobjargproc sq_ass_item; */
0, /* intintobjargproc sq_ass_slice; */
0, /* objobjproc sq_contains; */
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index e79847f..afe4587 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1835,9 +1835,9 @@ static PySequenceMethods array_as_sequence = {
(binaryfunc)array_concat, /*sq_concat*/
(ssizeargfunc)array_repeat, /*sq_repeat*/
(ssizeargfunc)array_item, /*sq_item*/
- (ssizessizeargfunc)array_slice, /*sq_slice*/
+ 0, /*sq_slice*/
(ssizeobjargproc)array_ass_item, /*sq_ass_item*/
- (ssizessizeobjargproc)array_ass_slice, /*sq_ass_slice*/
+ 0, /*sq_ass_slice*/
(objobjproc)array_contains, /*sq_contains*/
(binaryfunc)array_inplace_concat, /*sq_inplace_concat*/
(ssizeargfunc)array_inplace_repeat /*sq_inplace_repeat*/
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index f3727e3..77f64bc 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -642,24 +642,6 @@ mmap_item(mmap_object *self, Py_ssize_t i)
}
static PyObject *
-mmap_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh)
-{
- CHECK_VALID(NULL);
- if (ilow < 0)
- ilow = 0;
- else if ((size_t)ilow > self->size)
- ilow = self->size;
- if (ihigh < 0)
- ihigh = 0;
- if (ihigh < ilow)
- ihigh = ilow;
- else if ((size_t)ihigh > self->size)
- ihigh = self->size;
-
- return PyBytes_FromStringAndSize(self->data + ilow, ihigh-ilow);
-}
-
-static PyObject *
mmap_subscript(mmap_object *self, PyObject *item)
{
CHECK_VALID(NULL);
@@ -732,45 +714,6 @@ mmap_repeat(mmap_object *self, Py_ssize_t n)
}
static int
-mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
-{
- const char *buf;
-
- CHECK_VALID(-1);
- if (ilow < 0)
- ilow = 0;
- else if ((size_t)ilow > self->size)
- ilow = self->size;
- if (ihigh < 0)
- ihigh = 0;
- if (ihigh < ilow)
- ihigh = ilow;
- else if ((size_t)ihigh > self->size)
- ihigh = self->size;
-
- if (v == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "mmap object doesn't support slice deletion");
- return -1;
- }
- if (! (PyBytes_Check(v)) ) {
- PyErr_SetString(PyExc_IndexError,
- "mmap slice assignment must be bytes");
- return -1;
- }
- if (PyBytes_Size(v) != (ihigh - ilow)) {
- PyErr_SetString(PyExc_IndexError,
- "mmap slice assignment is wrong size");
- return -1;
- }
- if (!is_writeable(self))
- return -1;
- buf = PyBytes_AsString(v);
- memcpy(self->data + ilow, buf, ihigh-ilow);
- return 0;
-}
-
-static int
mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
const char *buf;
@@ -892,9 +835,9 @@ static PySequenceMethods mmap_as_sequence = {
(binaryfunc)mmap_concat, /*sq_concat*/
(ssizeargfunc)mmap_repeat, /*sq_repeat*/
(ssizeargfunc)mmap_item, /*sq_item*/
- (ssizessizeargfunc)mmap_slice, /*sq_slice*/
+ 0, /*sq_slice*/
(ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
- (ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/
+ 0, /*sq_ass_slice*/
};
static PyMappingMethods mmap_as_mapping = {