diff Objects/funcobject.c @ 31780:d448cc261f69 legacy-trunk

Intern __name__.
author Martin v. Löwis <martin@v.loewis.de>
date Tue, 23 Mar 2004 18:40:15 +0000
parents f6d503de45bd
children 87d196e1c2d0
line wrap: on
line diff
--- a/Objects/funcobject.c	Tue Mar 23 16:28:13 2004 +0000
+++ b/Objects/funcobject.c	Tue Mar 23 18:40:15 2004 +0000
@@ -11,6 +11,7 @@
 {
 	PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
 					    &PyFunction_Type);
+	static PyObject *__name__ = 0;
 	if (op != NULL) {
 		PyObject *doc;
 		PyObject *consts;
@@ -40,7 +41,14 @@
 		/* __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;