Skip to content

Commit 297257f

Browse files
authored
bpo-39465: Cleanup _PyUnicode_FromId() code (GH-20595)
Work on a local variable before filling _Py_Identifier members.
1 parent 59d3dce commit 297257f

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

‎Objects/unicodeobject.c‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,17 +2275,23 @@ PyUnicode_FromString(const char *u)
22752275
PyObject *
22762276
_PyUnicode_FromId(_Py_Identifier *id)
22772277
{
2278-
if (!id->object) {
2279-
id->object = PyUnicode_DecodeUTF8Stateful(id->string,
2280-
strlen(id->string),
2281-
NULL, NULL);
2282-
if (!id->object)
2283-
return NULL;
2284-
PyUnicode_InternInPlace(&id->object);
2285-
assert(!id->next);
2286-
id->next = static_strings;
2287-
static_strings = id;
2278+
if (id->object) {
2279+
return id->object;
2280+
}
2281+
2282+
PyObject *obj;
2283+
obj = PyUnicode_DecodeUTF8Stateful(id->string,
2284+
strlen(id->string),
2285+
NULL, NULL);
2286+
if (!obj) {
2287+
return NULL;
22882288
}
2289+
PyUnicode_InternInPlace(&obj);
2290+
2291+
assert(!id->next);
2292+
id->object = obj;
2293+
id->next = static_strings;
2294+
static_strings = id;
22892295
return id->object;
22902296
}
22912297

0 commit comments

Comments
 (0)