summaryrefslogtreecommitdiff
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
committerThomas Wouters <thomas@python.org>2006-04-21 10:40:58 +0000
commit66cac891ab67e9460620df27246918805f291990 (patch)
tree63521472f86287a79d85cfad1b44c4e97eb91c93 /Objects/sliceobject.c
parent3e3958e8e08cb62877e8aac097ce9a95ae682124 (diff)
downloadcpython-66cac891ab67e9460620df27246918805f291990.tar.gz
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c75
1 files changed, 47 insertions, 28 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 3b37dbb40b..271a9ad62d 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -24,26 +24,26 @@ ellipsis_repr(PyObject *op)
static PyTypeObject PyEllipsis_Type = {
PyObject_HEAD_INIT(&PyType_Type)
- 0, /* ob_size */
- "ellipsis", /* tp_name */
- 0, /* tp_basicsize */
- 0, /* tp_itemsize */
- 0, /*never called*/ /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc)ellipsis_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- PyObject_GenericGetAttr, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* ob_size */
+ "ellipsis", /* tp_name */
+ 0, /* tp_basicsize */
+ 0, /* tp_itemsize */
+ 0, /*never called*/ /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ ellipsis_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
};
PyObject _Py_EllipsisObject = {
@@ -79,6 +79,25 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
return (PyObject *) obj;
}
+PyObject *
+_PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop)
+{
+ PyObject *start, *end, *slice;
+ start = PyInt_FromSsize_t(istart);
+ if (!start)
+ return NULL;
+ end = PyInt_FromSsize_t(istop);
+ if (!end) {
+ Py_DECREF(start);
+ return NULL;
+ }
+
+ slice = PySlice_New(start, end, NULL);
+ Py_DECREF(start);
+ Py_DECREF(end);
+ return slice;
+}
+
int
PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)
@@ -87,21 +106,21 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
if (r->step == Py_None) {
*step = 1;
} else {
- if (!PyInt_Check(r->step)) return -1;
- *step = PyInt_AsLong(r->step);
+ if (!PyInt_Check(r->step) && !PyLong_Check(r->step)) return -1;
+ *step = PyInt_AsSsize_t(r->step);
}
if (r->start == Py_None) {
*start = *step < 0 ? length-1 : 0;
} else {
- if (!PyInt_Check(r->start)) return -1;
- *start = PyInt_AsLong(r->start);
+ if (!PyInt_Check(r->start) && !PyLong_Check(r->step)) return -1;
+ *start = PyInt_AsSsize_t(r->start);
if (*start < 0) *start += length;
}
if (r->stop == Py_None) {
*stop = *step < 0 ? -1 : length;
} else {
- if (!PyInt_Check(r->stop)) return -1;
- *stop = PyInt_AsLong(r->stop);
+ if (!PyInt_Check(r->stop) && !PyLong_Check(r->step)) return -1;
+ *stop = PyInt_AsSsize_t(r->stop);
if (*stop < 0) *stop += length;
}
if (*stop > length) return -1;
@@ -233,7 +252,7 @@ slice_indices(PySliceObject* self, PyObject* len)
{
Py_ssize_t ilen, start, stop, step, slicelength;
- ilen = PyInt_AsLong(len);
+ ilen = PyInt_AsSsize_t(len);
if (ilen == -1 && PyErr_Occurred()) {
return NULL;
@@ -244,7 +263,7 @@ slice_indices(PySliceObject* self, PyObject* len)
return NULL;
}
- return Py_BuildValue("(iii)", start, stop, step);
+ return Py_BuildValue("(nnn)", start, stop, step);
}
PyDoc_STRVAR(slice_indices_doc,