From bea18ccde6bc12e061c21bb6b944379d8b123845 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 14 Jun 2002 20:41:17 +0000 Subject: 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] --- Python/compile.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'Python/compile.c') diff --git a/Python/compile.c b/Python/compile.c index 4bbe44f7c9..b0e125de8e 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -91,6 +91,69 @@ static PyMemberDef code_memberlist[] = { {NULL} /* Sentinel */ }; +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) { @@ -200,7 +263,7 @@ PyTypeObject PyCode_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT, /* tp_flags */ - 0, /* tp_doc */ + code_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -217,7 +280,7 @@ PyTypeObject PyCode_Type = { 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - 0, /* tp_new */ + code_new, /* tp_new */ }; #define NAME_CHARS \ -- cgit v1.2.1