summaryrefslogtreecommitdiffstats
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-28 02:07:53 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-28 02:07:53 (GMT)
commitd7e1b2bd17cee31bb581a71fff20101be0b34bc6 (patch)
treea30973b18a8b5bf84e25eae590181cce9a59a217 /Objects/complexobject.c
parent908caac52e8e62baa1ee54e4e650e1cd3ac37907 (diff)
downloadcpython-d7e1b2bd17cee31bb581a71fff20101be0b34bc6.zip
cpython-d7e1b2bd17cee31bb581a71fff20101be0b34bc6.tar.gz
cpython-d7e1b2bd17cee31bb581a71fff20101be0b34bc6.tar.bz2
static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c13
1 files changed, 7 insertions, 6 deletions
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 @@ PyComplex_AsCComplex(PyObject *op)
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 @@ PyComplex_AsCComplex(PyObject *op)
/* 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) {