Skip to content

Commit fe82e77

Browse files
committed
Merged revisions 60379-60382 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60381 | christian.heimes | 2008-01-28 03:07:53 +0100 (Mon, 28 Jan 2008) | 1 line static PyObject* variables should use PyString_InternFromString() instead of PyObject_FromString() to store a python string in a function level static var. ........
1 parent 2685563 commit fe82e77

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,9 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
15301530

15311531
if (suffix == NULL)
15321532
#ifdef WORDS_BIGENDIAN
1533-
suffix = PyUnicode_FromString("_le");
1533+
suffix = PyUnicode_InternFromString("_le");
15341534
#else
1535-
suffix = PyUnicode_FromString("_be");
1535+
suffix = PyUnicode_InternFromString("_be");
15361536
#endif
15371537

15381538
newname = PyUnicode_Concat(name, suffix);
@@ -4276,7 +4276,7 @@ Simple_repr(CDataObject *self)
42764276
}
42774277

42784278
if (format == NULL) {
4279-
format = PyUnicode_FromString("%s(%r)");
4279+
format = PyUnicode_InternFromString("%s(%r)");
42804280
if (format == NULL)
42814281
return NULL;
42824282
}

Modules/_ctypes/callbacks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
365365
static PyObject *context;
366366

367367
if (context == NULL)
368-
context = PyUnicode_FromString("_ctypes.DllGetClassObject");
368+
context = PyUnicode_InternFromString("_ctypes.DllGetClassObject");
369369

370370
mod = PyImport_ImportModuleNoBlock("ctypes");
371371
if (!mod) {
@@ -444,7 +444,7 @@ long Call_CanUnloadNow(void)
444444
static PyObject *context;
445445

446446
if (context == NULL)
447-
context = PyUnicode_FromString("_ctypes.DllCanUnloadNow");
447+
context = PyUnicode_InternFromString("_ctypes.DllCanUnloadNow");
448448

449449
mod = PyImport_ImportModuleNoBlock("ctypes");
450450
if (!mod) {

Modules/mathmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static PyObject * math_ceil(PyObject *self, PyObject *number) {
131131
PyObject *method;
132132

133133
if (ceil_str == NULL) {
134-
ceil_str = PyUnicode_FromString("__ceil__");
134+
ceil_str = PyUnicode_InternFromString("__ceil__");
135135
if (ceil_str == NULL)
136136
return NULL;
137137
}
@@ -171,7 +171,7 @@ static PyObject * math_floor(PyObject *self, PyObject *number) {
171171
PyObject *method;
172172

173173
if (floor_str == NULL) {
174-
floor_str = PyUnicode_FromString("__floor__");
174+
floor_str = PyUnicode_InternFromString("__floor__");
175175
if (floor_str == NULL)
176176
return NULL;
177177
}

Objects/abstract.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ abstract_get_bases(PyObject *cls)
23332333
PyObject *bases;
23342334

23352335
if (__bases__ == NULL) {
2336-
__bases__ = PyUnicode_FromString("__bases__");
2336+
__bases__ = PyUnicode_InternFromString("__bases__");
23372337
if (__bases__ == NULL)
23382338
return NULL;
23392339
}
@@ -2413,7 +2413,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
24132413
int retval = 0;
24142414

24152415
if (__class__ == NULL) {
2416-
__class__ = PyUnicode_FromString("__class__");
2416+
__class__ = PyUnicode_InternFromString("__class__");
24172417
if (__class__ == NULL)
24182418
return -1;
24192419
}

Objects/complexobject.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,14 @@ PyComplex_AsCComplex(PyObject *op)
265265
/* return -1 on failure */
266266
cv.real = -1.;
267267
cv.imag = 0.;
268-
268+
269+
if (complex_str == NULL) {
270+
if (!(complex_str = PyUnicode_FromString("__complex__")))
271+
return cv;
272+
}
273+
269274
{
270275
PyObject *complexfunc;
271-
if (!complex_str) {
272-
if (!(complex_str = PyUnicode_FromString("__complex__")))
273-
return cv;
274-
}
275276
complexfunc = _PyType_Lookup(op->ob_type, complex_str);
276277
/* complexfunc is a borrowed reference */
277278
if (complexfunc) {

Python/bltinmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
14631463
}
14641464

14651465
if (round_str == NULL) {
1466-
round_str = PyUnicode_FromString("__round__");
1466+
round_str = PyUnicode_InternFromString("__round__");
14671467
if (round_str == NULL)
14681468
return NULL;
14691469
}
@@ -1582,7 +1582,7 @@ builtin_trunc(PyObject *self, PyObject *number)
15821582
}
15831583

15841584
if (trunc_str == NULL) {
1585-
trunc_str = PyUnicode_FromString("__trunc__");
1585+
trunc_str = PyUnicode_InternFromString("__trunc__");
15861586
if (trunc_str == NULL)
15871587
return NULL;
15881588
}

Python/compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ compiler_mod(struct compiler *c, mod_ty mod)
11331133
int addNone = 1;
11341134
static PyObject *module;
11351135
if (!module) {
1136-
module = PyUnicode_FromString("<module>");
1136+
module = PyUnicode_InternFromString("<module>");
11371137
if (!module)
11381138
return NULL;
11391139
}
@@ -1477,7 +1477,7 @@ compiler_class(struct compiler *c, stmt_ty s)
14771477

14781478
/* initialize statics */
14791479
if (locals == NULL) {
1480-
locals = PyUnicode_FromString("__locals__");
1480+
locals = PyUnicode_InternFromString("__locals__");
14811481
if (locals == NULL)
14821482
return 0;
14831483
}
@@ -2177,7 +2177,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
21772177
if (Py_OptimizeFlag)
21782178
return 1;
21792179
if (assertion_error == NULL) {
2180-
assertion_error = PyUnicode_FromString("AssertionError");
2180+
assertion_error = PyUnicode_InternFromString("AssertionError");
21812181
if (assertion_error == NULL)
21822182
return 0;
21832183
}

0 commit comments

Comments
 (0)