Intern __name__.

This commit is contained in:
Martin v. Löwis 2004-03-23 18:40:15 +00:00
parent 83969eeeeb
commit 321c9ab74c
1 changed files with 9 additions and 1 deletions

View File

@ -11,6 +11,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
{
PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
&PyFunction_Type);
static PyObject *__name__ = 0;
if (op != NULL) {
PyObject *doc;
PyObject *consts;
@ -40,7 +41,14 @@ PyFunction_New(PyObject *code, PyObject *globals)
/* __module__: If module name is in globals, use it.
Otherwise, use None.
*/
module = PyDict_GetItemString(globals, "__name__");
if (!__name__) {
__name__ = PyString_InternFromString("__name__");
if (!__name__) {
Py_DECREF(op);
return NULL;
}
}
module = PyDict_GetItem(globals, __name__);
if (module) {
Py_INCREF(module);
op->func_module = module;