From 886ea7b793eadd6abe46aa4e2b83f1f8795ec38f Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:43:24 +0000 Subject: [PATCH 1/2] disallow _Py_IDENTIFIER --- Include/cpython/object.h | 4 ++-- Programs/_testembed.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index fa0cfb24484952..3abfcb7d44f0fb 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -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* diff --git a/Programs/_testembed.c b/Programs/_testembed.c index adb4483ccbd3c0..52515881123ea7 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -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,11 @@ 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); + + 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(); From aa158d1a04e6a91d1a763a3b73382091c6ed9ea2 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:27:33 +0000 Subject: [PATCH 2/2] add comment --- Programs/_testembed.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 52515881123ea7..a6ce3f7b200550 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1891,6 +1891,9 @@ static int test_unicode_id_init(void) // bpo-42882: Test that _PyUnicode_FromId() works // when Python is initialized multiples times. + // 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,