Commit 51099fbe authored by Martin v. Löwis's avatar Martin v. Löwis

Intern __name__.

parent 5d97182d
...@@ -11,6 +11,7 @@ PyFunction_New(PyObject *code, PyObject *globals) ...@@ -11,6 +11,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
{ {
PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
&PyFunction_Type); &PyFunction_Type);
static PyObject *__name__ = 0;
if (op != NULL) { if (op != NULL) {
PyObject *doc; PyObject *doc;
PyObject *consts; PyObject *consts;
...@@ -40,7 +41,14 @@ PyFunction_New(PyObject *code, PyObject *globals) ...@@ -40,7 +41,14 @@ PyFunction_New(PyObject *code, PyObject *globals)
/* __module__: If module name is in globals, use it. /* __module__: If module name is in globals, use it.
Otherwise, use None. 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) { if (module) {
Py_INCREF(module); Py_INCREF(module);
op->func_module = module; op->func_module = module;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment