summaryrefslogtreecommitdiff
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-06-14 20:41:17 +0000
committerGuido van Rossum <guido@python.org>2002-06-14 20:41:17 +0000
commit41d000767f5c179763692a56b6a8f03bbd6e1bee (patch)
treed178060f1f73d735dd989134fc6191ddc781699d /Objects/sliceobject.c
parent0fca3b36022781f1854256f296f30807095cefc0 (diff)
downloadcpython-41d000767f5c179763692a56b6a8f03bbd6e1bee.tar.gz
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 9a268b715c..a43644d18f 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 */
};