summaryrefslogtreecommitdiffstats
path: root/Python
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 /Python
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 'Python')
-rw-r--r--Python/ceval.c131
-rw-r--r--Python/compile.c80
-rw-r--r--Python/sysmodule.c3
3 files changed, 3 insertions, 211 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index eea87a8..be804ad 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -111,9 +111,6 @@ static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
static int maybe_call_line_trace(Py_tracefunc, PyObject *,
PyFrameObject *, int *, int *, int *);
-static PyObject * apply_slice(PyObject *, PyObject *, PyObject *);
-static int assign_slice(PyObject *, PyObject *,
- PyObject *, PyObject *);
static PyObject * cmp_outcome(int, PyObject *, PyObject *);
static PyObject * import_from(PyObject *, PyObject *);
static int import_all_from(PyObject *, PyObject *);
@@ -1416,70 +1413,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
if (x != NULL) continue;
break;
- case SLICE+0:
- case SLICE+1:
- case SLICE+2:
- case SLICE+3:
- if ((opcode-SLICE) & 2)
- w = POP();
- else
- w = NULL;
- if ((opcode-SLICE) & 1)
- v = POP();
- else
- v = NULL;
- u = TOP();
- x = apply_slice(u, v, w);
- Py_DECREF(u);
- Py_XDECREF(v);
- Py_XDECREF(w);
- SET_TOP(x);
- if (x != NULL) continue;
- break;
-
- case STORE_SLICE+0:
- case STORE_SLICE+1:
- case STORE_SLICE+2:
- case STORE_SLICE+3:
- if ((opcode-STORE_SLICE) & 2)
- w = POP();
- else
- w = NULL;
- if ((opcode-STORE_SLICE) & 1)
- v = POP();
- else
- v = NULL;
- u = POP();
- t = POP();
- err = assign_slice(u, v, w, t); /* u[v:w] = t */
- Py_DECREF(t);
- Py_DECREF(u);
- Py_XDECREF(v);
- Py_XDECREF(w);
- if (err == 0) continue;
- break;
-
- case DELETE_SLICE+0:
- case DELETE_SLICE+1:
- case DELETE_SLICE+2:
- case DELETE_SLICE+3:
- if ((opcode-DELETE_SLICE) & 2)
- w = POP();
- else
- w = NULL;
- if ((opcode-DELETE_SLICE) & 1)
- v = POP();
- else
- v = NULL;
- u = POP();
- err = assign_slice(u, v, w, (PyObject *)NULL);
- /* del u[v:w] */
- Py_DECREF(u);
- Py_XDECREF(v);
- Py_XDECREF(w);
- if (err == 0) continue;
- break;
-
case STORE_SUBSCR:
w = TOP();
v = SECOND();
@@ -3895,70 +3828,6 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
return 1;
}
-#undef ISINDEX
-#define ISINDEX(x) ((x) == NULL || \
- PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))
-
-static PyObject *
-apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
-{
- PyTypeObject *tp = u->ob_type;
- PySequenceMethods *sq = tp->tp_as_sequence;
-
- if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {
- Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
- if (!_PyEval_SliceIndex(v, &ilow))
- return NULL;
- if (!_PyEval_SliceIndex(w, &ihigh))
- return NULL;
- return PySequence_GetSlice(u, ilow, ihigh);
- }
- else {
- PyObject *slice = PySlice_New(v, w, NULL);
- if (slice != NULL) {
- PyObject *res = PyObject_GetItem(u, slice);
- Py_DECREF(slice);
- return res;
- }
- else
- return NULL;
- }
-}
-
-static int
-assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
- /* u[v:w] = x */
-{
- PyTypeObject *tp = u->ob_type;
- PySequenceMethods *sq = tp->tp_as_sequence;
-
- if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {
- Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
- if (!_PyEval_SliceIndex(v, &ilow))
- return -1;
- if (!_PyEval_SliceIndex(w, &ihigh))
- return -1;
- if (x == NULL)
- return PySequence_DelSlice(u, ilow, ihigh);
- else
- return PySequence_SetSlice(u, ilow, ihigh, x);
- }
- else {
- PyObject *slice = PySlice_New(v, w, NULL);
- if (slice != NULL) {
- int res;
- if (x != NULL)
- res = PyObject_SetItem(u, slice, x);
- else
- res = PyObject_DelItem(u, slice);
- Py_DECREF(slice);
- return res;
- }
- else
- return -1;
- }
-}
-
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
"BaseException is not allowed"
diff --git a/Python/compile.c b/Python/compile.c
index d2bfe86..3a21127 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -707,33 +707,6 @@ opcode_stack_effect(int opcode, int oparg)
case INPLACE_TRUE_DIVIDE:
return -1;
- case SLICE+0:
- return 1;
- case SLICE+1:
- return 0;
- case SLICE+2:
- return 0;
- case SLICE+3:
- return -1;
-
- case STORE_SLICE+0:
- return -2;
- case STORE_SLICE+1:
- return -3;
- case STORE_SLICE+2:
- return -3;
- case STORE_SLICE+3:
- return -4;
-
- case DELETE_SLICE+0:
- return -1;
- case DELETE_SLICE+1:
- return -2;
- case DELETE_SLICE+2:
- return -2;
- case DELETE_SLICE+3:
- return -3;
-
case INPLACE_ADD:
case INPLACE_SUBTRACT:
case INPLACE_MULTIPLY:
@@ -3508,57 +3481,6 @@ compiler_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
}
static int
-compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
-{
- int op = 0, slice_offset = 0, stack_count = 0;
-
- assert(s->v.Slice.step == NULL);
- if (s->v.Slice.lower) {
- slice_offset++;
- stack_count++;
- if (ctx != AugStore)
- VISIT(c, expr, s->v.Slice.lower);
- }
- if (s->v.Slice.upper) {
- slice_offset += 2;
- stack_count++;
- if (ctx != AugStore)
- VISIT(c, expr, s->v.Slice.upper);
- }
-
- if (ctx == AugLoad) {
- switch (stack_count) {
- case 0: ADDOP(c, DUP_TOP); break;
- case 1: ADDOP_I(c, DUP_TOPX, 2); break;
- case 2: ADDOP_I(c, DUP_TOPX, 3); break;
- }
- }
- else if (ctx == AugStore) {
- switch (stack_count) {
- case 0: ADDOP(c, ROT_TWO); break;
- case 1: ADDOP(c, ROT_THREE); break;
- case 2: ADDOP(c, ROT_FOUR); break;
- }
- }
-
- switch (ctx) {
- case AugLoad: /* fall through to Load */
- case Load: op = SLICE; break;
- case AugStore:/* fall through to Store */
- case Store: op = STORE_SLICE; break;
- case Del: op = DELETE_SLICE; break;
- case Param:
- default:
- PyErr_SetString(PyExc_SystemError,
- "param invalid in simple slice");
- return 0;
- }
-
- ADDOP(c, op + slice_offset);
- return 1;
-}
-
-static int
compiler_visit_nested_slice(struct compiler *c, slice_ty s,
expr_context_ty ctx)
{
@@ -3590,8 +3512,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
break;
case Slice_kind:
kindname = "slice";
- if (!s->v.Slice.step)
- return compiler_simple_slice(c, s, ctx);
if (ctx != AugStore) {
if (!compiler_slice(c, s, ctx))
return 0;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 6ccd3e9..c3eb68e 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -875,6 +875,7 @@ PyDoc_STR(
Static objects:\n\
\n\
maxint -- the largest supported integer (the smallest is -maxint-1)\n\
+maxsize -- the largest supported length of containers.\n\
maxunicode -- the largest supported character\n\
builtin_module_names -- tuple of module names built into this interpreter\n\
version -- the version of this interpreter as a string\n\
@@ -1087,6 +1088,8 @@ _PySys_Init(void)
PyUnicode_FromString(Py_GetExecPrefix()));
SET_SYS_FROM_STRING("maxint",
PyInt_FromLong(PyInt_GetMax()));
+ SET_SYS_FROM_STRING("maxsize",
+ PyInt_FromLong(PY_SSIZE_T_MAX));
SET_SYS_FROM_STRING("maxunicode",
PyInt_FromLong(PyUnicode_GetMax()));
SET_SYS_FROM_STRING("builtin_module_names",