summaryrefslogtreecommitdiffstats
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-06-14 20:41:17 (GMT)
committerGuido van Rossum <guido@python.org>2002-06-14 20:41:17 (GMT)
commitbea18ccde6bc12e061c21bb6b944379d8b123845 (patch)
treed5366d2bba31bde0cf6d05e1b55cde64cf3d3864 /Objects/sliceobject.c
parent57454e57f83b407dd2653cbfcead7c9801beeff0 (diff)
downloadcpython-bea18ccde6bc12e061c21bb6b944379d8b123845.zip
cpython-bea18ccde6bc12e061c21bb6b944379d8b123845.tar.gz
cpython-bea18ccde6bc12e061c21bb6b944379d8b123845.tar.bz2
SF patch 568629 by Oren Tirosh: types made callable.
These built-in functions are replaced by their (now callable) type: slice() buffer() and these types can also be called (but have no built-in named function named after them) classobj (type name used to be "class") code function instance instancemethod (type name used to be "instance method") The module "new" has been replaced with a small backward compatibility placeholder in Python. A large portion of the patch simply removes the new module from various platform-specific build recipes. The following binary Mac project files still have references to it: Mac/Build/PythonCore.mcp Mac/Build/PythonStandSmall.mcp Mac/Build/PythonStandalone.mcp [I've tweaked the code layout and the doc strings here and there, and added a comment to types.py about StringTypes vs. basestring. --Guido]
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 9a268b7..a43644d 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -164,6 +164,30 @@ PySlice_GetIndicesEx(PySliceObject *r, int length,
return 0;
}
+static PyObject *
+slice_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+{
+ PyObject *start, *stop, *step;
+
+ start = stop = step = NULL;
+
+ if (!PyArg_ParseTuple(args, "O|OO:slice", &start, &stop, &step))
+ return NULL;
+
+ /* This swapping of stop and start is to maintain similarity with
+ range(). */
+ if (stop == NULL) {
+ stop = start;
+ start = NULL;
+ }
+ return PySlice_New(start, stop, step);
+}
+
+PyDoc_STRVAR(slice_doc,
+"slice([start,] stop[, step])\n\
+\n\
+Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
+
static void
slice_dealloc(PySliceObject *r)
{
@@ -240,7 +264,7 @@ PyTypeObject PySlice_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
- 0, /* tp_doc */
+ slice_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -252,4 +276,10 @@ PyTypeObject PySlice_Type = {
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ slice_new, /* tp_new */
};