mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var.
This commit is contained in:
parent
908caac52e
commit
d7e1b2bd17
6 changed files with 17 additions and 16 deletions
|
@ -1529,9 +1529,9 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
|
||||||
|
|
||||||
if (suffix == NULL)
|
if (suffix == NULL)
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
suffix = PyString_FromString("_le");
|
suffix = PyString_InternFromString("_le");
|
||||||
#else
|
#else
|
||||||
suffix = PyString_FromString("_be");
|
suffix = PyString_InternFromString("_be");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Py_INCREF(name);
|
Py_INCREF(name);
|
||||||
|
@ -4416,7 +4416,7 @@ Simple_repr(CDataObject *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == NULL) {
|
if (format == NULL) {
|
||||||
format = PyString_FromString("%s(%r)");
|
format = PyString_InternFromString("%s(%r)");
|
||||||
if (format == NULL)
|
if (format == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,7 +368,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
||||||
static PyObject *context;
|
static PyObject *context;
|
||||||
|
|
||||||
if (context == NULL)
|
if (context == NULL)
|
||||||
context = PyString_FromString("_ctypes.DllGetClassObject");
|
context = PyString_InternFromString("_ctypes.DllGetClassObject");
|
||||||
|
|
||||||
mod = PyImport_ImportModuleNoBlock("ctypes");
|
mod = PyImport_ImportModuleNoBlock("ctypes");
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
|
@ -447,7 +447,7 @@ long Call_CanUnloadNow(void)
|
||||||
static PyObject *context;
|
static PyObject *context;
|
||||||
|
|
||||||
if (context == NULL)
|
if (context == NULL)
|
||||||
context = PyString_FromString("_ctypes.DllCanUnloadNow");
|
context = PyString_InternFromString("_ctypes.DllCanUnloadNow");
|
||||||
|
|
||||||
mod = PyImport_ImportModuleNoBlock("ctypes");
|
mod = PyImport_ImportModuleNoBlock("ctypes");
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
|
|
|
@ -2142,7 +2142,7 @@ abstract_get_bases(PyObject *cls)
|
||||||
PyObject *bases;
|
PyObject *bases;
|
||||||
|
|
||||||
if (__bases__ == NULL) {
|
if (__bases__ == NULL) {
|
||||||
__bases__ = PyString_FromString("__bases__");
|
__bases__ = PyString_InternFromString("__bases__");
|
||||||
if (__bases__ == NULL)
|
if (__bases__ == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2220,7 +2220,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
if (__class__ == NULL) {
|
if (__class__ == NULL) {
|
||||||
__class__ = PyString_FromString("__class__");
|
__class__ = PyString_InternFromString("__class__");
|
||||||
if (__class__ == NULL)
|
if (__class__ == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,14 +261,19 @@ PyComplex_AsCComplex(PyObject *op)
|
||||||
return ((PyComplexObject *)op)->cval;
|
return ((PyComplexObject *)op)->cval;
|
||||||
}
|
}
|
||||||
/* If not, use op's __complex__ method, if it exists */
|
/* If not, use op's __complex__ method, if it exists */
|
||||||
|
|
||||||
/* return -1 on failure */
|
/* return -1 on failure */
|
||||||
cv.real = -1.;
|
cv.real = -1.;
|
||||||
cv.imag = 0.;
|
cv.imag = 0.;
|
||||||
|
|
||||||
|
if (complex_str == NULL) {
|
||||||
|
if (!(complex_str = PyString_InternFromString("__complex__")))
|
||||||
|
return cv;
|
||||||
|
}
|
||||||
|
|
||||||
if (PyInstance_Check(op)) {
|
if (PyInstance_Check(op)) {
|
||||||
/* this can go away in python 3000 */
|
/* this can go away in python 3000 */
|
||||||
if (PyObject_HasAttrString(op, "__complex__")) {
|
if (PyObject_HasAttr(op, complex_str)) {
|
||||||
newop = PyObject_CallMethod(op, "__complex__", NULL);
|
newop = PyObject_CallMethod(op, "__complex__", NULL);
|
||||||
if (!newop)
|
if (!newop)
|
||||||
return cv;
|
return cv;
|
||||||
|
@ -276,10 +281,6 @@ PyComplex_AsCComplex(PyObject *op)
|
||||||
/* else try __float__ */
|
/* else try __float__ */
|
||||||
} else {
|
} else {
|
||||||
PyObject *complexfunc;
|
PyObject *complexfunc;
|
||||||
if (!complex_str) {
|
|
||||||
if (!(complex_str = PyString_FromString("__complex__")))
|
|
||||||
return cv;
|
|
||||||
}
|
|
||||||
complexfunc = _PyType_Lookup(op->ob_type, complex_str);
|
complexfunc = _PyType_Lookup(op->ob_type, complex_str);
|
||||||
/* complexfunc is a borrowed reference */
|
/* complexfunc is a borrowed reference */
|
||||||
if (complexfunc) {
|
if (complexfunc) {
|
||||||
|
|
|
@ -1965,7 +1965,7 @@ file_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
assert(type != NULL && type->tp_alloc != NULL);
|
assert(type != NULL && type->tp_alloc != NULL);
|
||||||
|
|
||||||
if (not_yet_string == 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)
|
if (not_yet_string == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1153,7 +1153,7 @@ compiler_mod(struct compiler *c, mod_ty mod)
|
||||||
int addNone = 1;
|
int addNone = 1;
|
||||||
static PyObject *module;
|
static PyObject *module;
|
||||||
if (!module) {
|
if (!module) {
|
||||||
module = PyString_FromString("<module>");
|
module = PyString_InternFromString("<module>");
|
||||||
if (!module)
|
if (!module)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2001,7 +2001,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
|
||||||
if (Py_OptimizeFlag)
|
if (Py_OptimizeFlag)
|
||||||
return 1;
|
return 1;
|
||||||
if (assertion_error == NULL) {
|
if (assertion_error == NULL) {
|
||||||
assertion_error = PyString_FromString("AssertionError");
|
assertion_error = PyString_InternFromString("AssertionError");
|
||||||
if (assertion_error == NULL)
|
if (assertion_error == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue