]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-90699: disallow `_Py_IDENTIFIER` in core code (GH-99210)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Wed, 9 Nov 2022 16:53:21 +0000 (22:23 +0530)
committerGitHub <noreply@github.com>
Wed, 9 Nov 2022 16:53:21 +0000 (08:53 -0800)
Include/cpython/object.h
Programs/_testembed.c

index d07cb3be4c66391e1975802f73782f6df1b79313..f4755a7b2fb852c8164fa27658dd0a737ffbb0f1 100644 (file)
@@ -41,7 +41,7 @@ typedef struct _Py_Identifier {
     Py_ssize_t index;
 } _Py_Identifier;
 
-#if defined(NEEDS_PY_IDENTIFIER) || !defined(Py_BUILD_CORE)
+#ifndef Py_BUILD_CORE
 // For now we are keeping _Py_IDENTIFIER for continued use
 // in non-builtin extensions (and naughty PyPI modules).
 
@@ -49,7 +49,7 @@ typedef struct _Py_Identifier {
 #define _Py_static_string(varname, value)  static _Py_Identifier varname = _Py_static_string_init(value)
 #define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
 
-#endif  /* NEEDS_PY_IDENTIFIER */
+#endif /* !Py_BUILD_CORE */
 
 typedef struct {
     /* Number implementations must check *both*
index adb4483ccbd3c0ca4daa58db53829fa9d2b47bf0..a6ce3f7b200550c00f48ea516e5460e0d1ad825b 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef Py_BUILD_CORE_MODULE
 #  define Py_BUILD_CORE_MODULE
 #endif
-#define NEEDS_PY_IDENTIFIER
 
 /* Always enable assertion (even in release mode) */
 #undef NDEBUG
@@ -1891,7 +1890,14 @@ static int test_unicode_id_init(void)
 {
     // bpo-42882: Test that _PyUnicode_FromId() works
     // when Python is initialized multiples times.
-    _Py_IDENTIFIER(test_unicode_id_init);
+
+    // This is equivalent to `_Py_IDENTIFIER(test_unicode_id_init)`
+    // but since `_Py_IDENTIFIER` is disabled when `Py_BUILD_CORE`
+    // is defined, it is manually expanded here.
+    static _Py_Identifier PyId_test_unicode_id_init = {
+        .string = "test_unicode_id_init",
+        .index = -1,
+    };
 
     // Initialize Python once without using the identifier
     _testembed_Py_InitializeFromConfig();