Skip to content

Commit bd44a7e

Browse files
bpo-38650: Constify PyStructSequence_UnnamedField. (pythonGH-17005)
Make it a constant and referring to a constant string.
1 parent 5fd5cb8 commit bd44a7e

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

Doc/c-api/tuple.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,13 @@ type.
182182
+-----------+------------------+-----------------------------------------+
183183
184184
185-
.. c:var:: char* PyStructSequence_UnnamedField
185+
.. c:var:: const char * const PyStructSequence_UnnamedField
186186
187187
Special value for a field name to leave it unnamed.
188188
189+
.. versionchanged:: 3.9
190+
The type was changed from ``char *``.
191+
189192
190193
.. c:function:: PyObject* PyStructSequence_New(PyTypeObject *type)
191194

Doc/whatsnew/3.9.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ Build and C API Changes
215215
way to call a callable Python object without any argument.
216216
(Contributed by Victor Stinner in :issue:`37194`.)
217217

218+
* The global variable :c:data:`PyStructSequence_UnnamedField` is now a constant
219+
and refers to a constant string.
220+
(Contributed by Serhiy Storchaka in :issue:`38650`.)
218221

219222

220223
Deprecated

Include/structseq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct PyStructSequence_Desc {
1919
int n_in_sequence;
2020
} PyStructSequence_Desc;
2121

22-
extern char* PyStructSequence_UnnamedField;
22+
extern const char * const PyStructSequence_UnnamedField;
2323

2424
#ifndef Py_LIMITED_API
2525
PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The global variable :c:data:`PyStructSequence_UnnamedField` is now a
2+
constant and refers to a constant string.

Objects/structseq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char unnamed_fields_key[] = "n_unnamed_fields";
1818

1919
/* Fields with this name have only a field index, not a field name.
2020
They are only allowed for indices < n_visible_fields. */
21-
char *PyStructSequence_UnnamedField = "unnamed field";
21+
const char * const PyStructSequence_UnnamedField = "unnamed field";
2222
_Py_IDENTIFIER(n_sequence_fields);
2323
_Py_IDENTIFIER(n_fields);
2424
_Py_IDENTIFIER(n_unnamed_fields);

0 commit comments

Comments
 (0)