[Python-checkins] python/dist/src/Modules newmodule.c,2.37.8.1,2.37.8.2
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
2003年5月22日 11:11:23 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv28591/Modules
Modified Files:
Tag: release22-maint
newmodule.c
Log Message:
Backport fix for SF bug 692776.
Add a tp_new slot to function objects that handles the case of a
function requiring a closure. Put the function type in the new
module, rather than having a function new.function(). Add tests.
Index: newmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/Attic/newmodule.c,v
retrieving revision 2.37.8.1
retrieving revision 2.37.8.2
diff -C2 -d -r2.37.8.1 -r2.37.8.2
*** newmodule.c 28 Jan 2002 15:03:36 -0000 2.37.8.1
--- newmodule.c 22 May 2003 18:11:20 -0000 2.37.8.2
***************
*** 54,99 ****
}
- static char new_function_doc[] =
- "Create a function object from (CODE, GLOBALS, [NAME [, ARGDEFS]]).";
-
- static PyObject *
- new_function(PyObject* unused, PyObject* args)
- {
- PyObject* code;
- PyObject* globals;
- PyObject* name = Py_None;
- PyObject* defaults = Py_None;
- PyFunctionObject* newfunc;
-
- if (!PyArg_ParseTuple(args, "O!O!|OO!:function",
- &PyCode_Type, &code,
- &PyDict_Type, &globals,
- &name,
- &PyTuple_Type, &defaults))
- return NULL;
- if (name != Py_None && !PyString_Check(name)) {
- PyErr_SetString(PyExc_TypeError,
- "arg 3 (name) must be None or string");
- return NULL;
- }
-
- newfunc = (PyFunctionObject *)PyFunction_New(code, globals);
- if (newfunc == NULL)
- return NULL;
-
- if (name != Py_None) {
- Py_XINCREF(name);
- Py_XDECREF(newfunc->func_name);
- newfunc->func_name = name;
- }
- if (defaults != Py_None) {
- Py_XINCREF(defaults);
- Py_XDECREF(newfunc->func_defaults);
- newfunc->func_defaults = defaults;
- }
-
- return (PyObject *)newfunc;
- }
-
static char new_code_doc[] =
"Create a code object from (ARGCOUNT, NLOCALS, STACKSIZE, FLAGS, CODESTRING,\n"
--- 54,57 ----
***************
*** 192,197 ****
{"instancemethod", new_instancemethod,
METH_VARARGS, new_im_doc},
- {"function", new_function,
- METH_VARARGS, new_function_doc},
{"code", new_code,
METH_VARARGS, new_code_doc},
--- 150,153 ----
***************
*** 211,215 ****
initnew(void)
{
! Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
! PYTHON_API_VERSION);
}
--- 167,174 ----
initnew(void)
{
! PyObject *m;
! m = Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
! PYTHON_API_VERSION);
! if (m)
! PyModule_AddObject(m, "function", &PyFunction_Type);
}