[Python-checkins] bpo-39465: Cleanup _PyUnicode_FromId() code (GH-20595)

Victor Stinner webhook-mailer at python.org
Tue Jun 2 08:40:01 EDT 2020


https://github.com/python/cpython/commit/297257f7bc198e2dc8e0866b539c73ff1a5cc588
commit: 297257f7bc198e2dc8e0866b539c73ff1a5cc588
branch: master
author: Victor Stinner <vstinner at python.org>
committer: GitHub <noreply at github.com>
date: 2020-06-02T14:39:45+02:00
summary:

bpo-39465: Cleanup _PyUnicode_FromId() code (GH-20595)

Work on a local variable before filling _Py_Identifier members.

files:
M Objects/unicodeobject.c

diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 511640438d015..e69bf01251ced 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
 }
 



More information about the Python-checkins mailing list