From ada6b4cf8d41bb519a6a0cb2f6a36bdd5e377777 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 22 Mar 2022 19:15:30 -0600 Subject: [PATCH] Add a comment about when to use _Py_DECLARE_STR(). --- Include/internal/pycore_global_strings.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 35bffa7aff9493..46a6f7dd358ead 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -371,6 +371,16 @@ struct _Py_global_strings { #define _Py_STR(NAME) \ (_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base)) +/* _Py_DECLARE_STR() should precede all uses of _Py_STR() in a function. + + This is true even if the same string has already been declared + elsewhere, even in the same file. Mismatched duplicates are detected + by Tools/scripts/generate-global-objects.py. + + Pairing _Py_DECLARE_STR() with every use of _Py_STR() makes sure the + string keeps working even if the declaration is removed somewhere + else. It also makes it clear what the actual string is at every + place it is being used. */ #define _Py_DECLARE_STR(name, str) #ifdef __cplusplus