]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39465: Cleanup _PyUnicode_FromId() code (GH-20595)
authorVictor Stinner <vstinner@python.org>
Tue, 2 Jun 2020 12:39:45 +0000 (14:39 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 12:39:45 +0000 (14:39 +0200)
Work on a local variable before filling _Py_Identifier members.

Objects/unicodeobject.c

index 511640438d0150470896b62814685d69c277bee7..e69bf01251ceddfe2deff9f37b57c690677613b1 100644 (file)
@@ -2275,17 +2275,23 @@ PyUnicode_FromString(const char *u)
 PyObject *
 _PyUnicode_FromId(_Py_Identifier *id)
 {
-    if (!id->object) {
-        id->object = PyUnicode_DecodeUTF8Stateful(id->string,
-                                                  strlen(id->string),
-                                                  NULL, NULL);
-        if (!id->object)
-            return NULL;
-        PyUnicode_InternInPlace(&id->object);
-        assert(!id->next);
-        id->next = static_strings;
-        static_strings = id;
+    if (id->object) {
+        return id->object;
+    }
+
+    PyObject *obj;
+    obj = PyUnicode_DecodeUTF8Stateful(id->string,
+                                       strlen(id->string),
+                                       NULL, NULL);
+    if (!obj) {
+        return NULL;
     }
+    PyUnicode_InternInPlace(&obj);
+
+    assert(!id->next);
+    id->object = obj;
+    id->next = static_strings;
+    static_strings = id;
     return id->object;
 }