static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 4c8ef83..830fe82 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2142,7 +2142,7 @@
PyObject *bases;
if (__bases__ == NULL) {
- __bases__ = PyString_FromString("__bases__");
+ __bases__ = PyString_InternFromString("__bases__");
if (__bases__ == NULL)
return NULL;
}
@@ -2220,7 +2220,7 @@
int retval = 0;
if (__class__ == NULL) {
- __class__ = PyString_FromString("__class__");
+ __class__ = PyString_InternFromString("__class__");
if (__class__ == NULL)
return -1;
}
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 03b80c8..4777ed1 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -261,14 +261,19 @@
return ((PyComplexObject *)op)->cval;
}
/* If not, use op's __complex__ method, if it exists */
-
+
/* return -1 on failure */
cv.real = -1.;
cv.imag = 0.;
+
+ if (complex_str == NULL) {
+ if (!(complex_str = PyString_InternFromString("__complex__")))
+ return cv;
+ }
if (PyInstance_Check(op)) {
/* this can go away in python 3000 */
- if (PyObject_HasAttrString(op, "__complex__")) {
+ if (PyObject_HasAttr(op, complex_str)) {
newop = PyObject_CallMethod(op, "__complex__", NULL);
if (!newop)
return cv;
@@ -276,10 +281,6 @@
/* else try __float__ */
} else {
PyObject *complexfunc;
- if (!complex_str) {
- if (!(complex_str = PyString_FromString("__complex__")))
- return cv;
- }
complexfunc = _PyType_Lookup(op->ob_type, complex_str);
/* complexfunc is a borrowed reference */
if (complexfunc) {
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index a5a42fc..eb05cda 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -1965,7 +1965,7 @@
assert(type != NULL && type->tp_alloc != NULL);
if (not_yet_string == NULL) {
- not_yet_string = PyString_FromString("<uninitialized file>");
+ not_yet_string = PyString_InternFromString("<uninitialized file>");
if (not_yet_string == NULL)
return NULL;
}