[Python-checkins] GH-90699: use statically allocated strings in typeobject.c (gh-93751)

corona10 webhook-mailer at python.org
Sun Jun 12 12:38:23 EDT 2022


https://github.com/python/cpython/commit/93310879665368445f95df2f3d9be7fb82435248
commit: 93310879665368445f95df2f3d9be7fb82435248
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: corona10 <donghee.na92 at gmail.com>
date: 2022-06-13T01:38:18+09:00
summary:

GH-90699: use statically allocated strings in typeobject.c (gh-93751)

files:
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init.h
M Objects/typeobject.c

diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h
index ca970627cb2e1..af6c5ebaaf9de 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -90,6 +90,7 @@ struct _Py_global_strings {
         STRUCT_FOR_ID(__delete__)
         STRUCT_FOR_ID(__delitem__)
         STRUCT_FOR_ID(__dict__)
+        STRUCT_FOR_ID(__dictoffset__)
         STRUCT_FOR_ID(__dir__)
         STRUCT_FOR_ID(__divmod__)
         STRUCT_FOR_ID(__doc__)
@@ -206,6 +207,7 @@ struct _Py_global_strings {
         STRUCT_FOR_ID(__typing_subst__)
         STRUCT_FOR_ID(__typing_unpacked_tuple_args__)
         STRUCT_FOR_ID(__warningregistry__)
+        STRUCT_FOR_ID(__weaklistoffset__)
         STRUCT_FOR_ID(__weakref__)
         STRUCT_FOR_ID(__xor__)
         STRUCT_FOR_ID(_abc_impl)
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 5e57ac68776c8..2420d81a8a238 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -712,6 +712,7 @@ extern "C" {
                 INIT_ID(__delete__), \
                 INIT_ID(__delitem__), \
                 INIT_ID(__dict__), \
+                INIT_ID(__dictoffset__), \
                 INIT_ID(__dir__), \
                 INIT_ID(__divmod__), \
                 INIT_ID(__doc__), \
@@ -828,6 +829,7 @@ extern "C" {
                 INIT_ID(__typing_subst__), \
                 INIT_ID(__typing_unpacked_tuple_args__), \
                 INIT_ID(__warningregistry__), \
+                INIT_ID(__weaklistoffset__), \
                 INIT_ID(__weakref__), \
                 INIT_ID(__xor__), \
                 INIT_ID(_abc_impl), \
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 18094bd43dd3a..c6df50da9736b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3637,13 +3637,13 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
 
     if (weaklistoffset) {
         type->tp_weaklistoffset = weaklistoffset;
-        if (PyDict_DelItemString((PyObject *)type->tp_dict, "__weaklistoffset__") < 0) {
+        if (PyDict_DelItem((PyObject *)type->tp_dict, &_Py_ID(__weaklistoffset__)) < 0) {
             goto finally;
         }
     }
     if (dictoffset) {
         type->tp_dictoffset = dictoffset;
-        if (PyDict_DelItemString((PyObject *)type->tp_dict, "__dictoffset__") < 0) {
+        if (PyDict_DelItem((PyObject *)type->tp_dict, &_Py_ID(__dictoffset__)) < 0) {
             goto finally;
         }
     }



More information about the Python-checkins mailing list