Skip to content

Commit 21412d0

Browse files
bpo-46541: Add a Comment About When to Use _Py_DECLARE_STR(). (gh-32063)
In a gh-32003 comment, I realized it wasn't very clear how _Py_DECLARE_STR() should be used. This changes adds a comment to clarify. https://bugs.python.org/issue46541
1 parent 0360e9f commit 21412d0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Include/internal/pycore_global_strings.h

+10
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ struct _Py_global_strings {
372372
#define _Py_STR(NAME) \
373373
(_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base))
374374

375+
/* _Py_DECLARE_STR() should precede all uses of _Py_STR() in a function.
376+
377+
This is true even if the same string has already been declared
378+
elsewhere, even in the same file. Mismatched duplicates are detected
379+
by Tools/scripts/generate-global-objects.py.
380+
381+
Pairing _Py_DECLARE_STR() with every use of _Py_STR() makes sure the
382+
string keeps working even if the declaration is removed somewhere
383+
else. It also makes it clear what the actual string is at every
384+
place it is being used. */
375385
#define _Py_DECLARE_STR(name, str)
376386

377387
#ifdef __cplusplus

0 commit comments

Comments
 (0)