[Python-checkins] python/dist/src/Python bltinmodule.c,2.259,2.260 compile.c,2.245,2.246 dynload_aix.c,2.11,2.12
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 14 Jun 2002 13:41:19 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv18223/Python
Modified Files:
bltinmodule.c compile.c dynload_aix.c
Log Message:
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]
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.259
retrieving revision 2.260
diff -C2 -d -r2.259 -r2.260
*** bltinmodule.c 13 Jun 2002 20:33:02 -0000 2.259
--- bltinmodule.c 14 Jun 2002 20:41:16 -0000 2.260
***************
*** 108,132 ****
static PyObject *
- builtin_buffer(PyObject *self, PyObject *args)
- {
- PyObject *ob;
- int offset = 0;
- int size = Py_END_OF_BUFFER;
-
- if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) )
- return NULL;
- return PyBuffer_FromObject(ob, offset, size);
- }
-
- PyDoc_STRVAR(buffer_doc,
- "buffer(object [, offset[, size]]) -> object\n\
- \n\
- Create a new buffer object which references the given object.\n\
- The buffer will reference a slice of the target object from the\n\
- start of the object (or at the specified offset). The slice will\n\
- extend to the end of the target object (or with the specified size).");
-
-
- static PyObject *
builtin_callable(PyObject *self, PyObject *v)
{
--- 108,111 ----
***************
*** 1080,1108 ****
static PyObject *
- builtin_slice(PyObject *self, PyObject *args)
- {
- 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]) -> slice object\n\
- \n\
- Create a slice object. This is used for slicing by the Numeric extensions.");
-
-
- static PyObject *
builtin_locals(PyObject *self)
{
--- 1059,1062 ----
***************
*** 1776,1780 ****
{"abs", builtin_abs, METH_O, abs_doc},
{"apply", builtin_apply, METH_VARARGS, apply_doc},
- {"buffer", builtin_buffer, METH_VARARGS, buffer_doc},
{"callable", builtin_callable, METH_O, callable_doc},
{"chr", builtin_chr, METH_VARARGS, chr_doc},
--- 1730,1733 ----
***************
*** 1814,1818 ****
{"round", builtin_round, METH_VARARGS, round_doc},
{"setattr", builtin_setattr, METH_VARARGS, setattr_doc},
- {"slice", builtin_slice, METH_VARARGS, slice_doc},
#ifdef Py_USING_UNICODE
{"unichr", builtin_unichr, METH_VARARGS, unichr_doc},
--- 1767,1770 ----
***************
*** 1850,1853 ****
--- 1802,1806 ----
SETBUILTIN("basestring", &PyBaseString_Type);
SETBUILTIN("bool", &PyBool_Type);
+ SETBUILTIN("buffer", &PyBuffer_Type);
SETBUILTIN("classmethod", &PyClassMethod_Type);
#ifndef WITHOUT_COMPLEX
***************
*** 1862,1865 ****
--- 1815,1819 ----
SETBUILTIN("long", &PyLong_Type);
SETBUILTIN("object", &PyBaseObject_Type);
+ SETBUILTIN("slice", &PySlice_Type);
SETBUILTIN("staticmethod", &PyStaticMethod_Type);
SETBUILTIN("str", &PyString_Type);
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.245
retrieving revision 2.246
diff -C2 -d -r2.245 -r2.246
*** compile.c 31 May 2002 14:08:29 -0000 2.245
--- compile.c 14 Jun 2002 20:41:16 -0000 2.246
***************
*** 92,95 ****
--- 92,158 ----
};
+ PyDoc_STRVAR(code_doc,
+ "code(argcount, nlocals, stacksize, flags, codestring, constants, names,\n\
+ varnames, filename, name, firstlineno, lnotab[, freevars[, cellvars]])\n\
+ \n\
+ Create a code object. Not for the faint of heart.");
+
+ static PyObject *
+ code_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+ {
+ int argcount;
+ int nlocals;
+ int stacksize;
+ int flags;
+ PyObject *code;
+ PyObject *consts;
+ PyObject *names;
+ PyObject *varnames;
+ PyObject *freevars = NULL;
+ PyObject *cellvars = NULL;
+ PyObject *filename;
+ PyObject *name;
+ int firstlineno;
+ PyObject *lnotab;
+
+ if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code",
+ &argcount, &nlocals, &stacksize, &flags,
+ &code,
+ &PyTuple_Type, &consts,
+ &PyTuple_Type, &names,
+ &PyTuple_Type, &varnames,
+ &filename, &name,
+ &firstlineno, &lnotab,
+ &PyTuple_Type, &freevars,
+ &PyTuple_Type, &cellvars))
+ return NULL;
+
+ if (freevars == NULL || cellvars == NULL) {
+ PyObject *empty = PyTuple_New(0);
+ if (empty == NULL)
+ return NULL;
+ if (freevars == NULL) {
+ freevars = empty;
+ Py_INCREF(freevars);
+ }
+ if (cellvars == NULL) {
+ cellvars = empty;
+ Py_INCREF(cellvars);
+ }
+ Py_DECREF(empty);
+ }
+
+ if (!PyObject_CheckReadBuffer(code)) {
+ PyErr_SetString(PyExc_TypeError,
+ "bytecode object must be a single-segment read-only buffer");
+ return NULL;
+ }
+
+ return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags,
+ code, consts, names, varnames,
+ freevars, cellvars, filename, name,
+ firstlineno, lnotab);
+ }
+
static void
code_dealloc(PyCodeObject *co)
***************
*** 201,205 ****
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! 0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
--- 264,268 ----
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
! code_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
***************
*** 218,222 ****
0, /* tp_init */
0, /* tp_alloc */
! 0, /* tp_new */
};
--- 281,285 ----
0, /* tp_init */
0, /* tp_alloc */
! code_new, /* tp_new */
};
Index: dynload_aix.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/dynload_aix.c,v
retrieving revision 2.11
retrieving revision 2.12
diff -C2 -d -r2.11 -r2.12
*** dynload_aix.c 28 Nov 2001 21:35:49 -0000 2.11
--- dynload_aix.c 14 Jun 2002 20:41:16 -0000 2.12
***************
*** 105,121 ****
}
- static int
- aix_bindnewmodule(void *newmoduleptr, void *modlistptr)
- {
- register ModulePtr modptr;
-
- /*
- -- Bind the new module with the list of loaded modules.
- */
- for (modptr = (ModulePtr)modlistptr; modptr; modptr = modptr->next)
- if (loadbind(0, modptr->entry, newmoduleptr) != 0)
- return -1;
- return 0;
- }
static void
--- 105,108 ----
***************
*** 190,197 ****
p = (dl_funcptr) aix_load((char *)pathname, L_NOAUTODEFER, 0);
if (p == NULL) {
- aix_loaderror(pathname);
- return NULL;
- }
- if (aix_bindnewmodule((void *)p, staticmodlistptr) == -1) {
aix_loaderror(pathname);
return NULL;
--- 177,180 ----