From bd44a7ead9f7336d7bb45f186b2b6ca0300154f7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 16 Nov 2019 18:55:29 +0200 Subject: bpo-38650: Constify PyStructSequence_UnnamedField. (GH-17005) Make it a constant and referring to a constant string. --- Doc/c-api/tuple.rst | 5 ++++- Doc/whatsnew/3.9.rst | 3 +++ Include/structseq.h | 2 +- Misc/NEWS.d/next/C API/2019-10-30-22-03-03.bpo-38650.0pi8zt.rst | 2 ++ Objects/structseq.c | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2019-10-30-22-03-03.bpo-38650.0pi8zt.rst diff --git a/Doc/c-api/tuple.rst b/Doc/c-api/tuple.rst index 25df397..62bc9a5 100644 --- a/Doc/c-api/tuple.rst +++ b/Doc/c-api/tuple.rst @@ -182,10 +182,13 @@ type. +-----------+------------------+-----------------------------------------+ -.. c:var:: char* PyStructSequence_UnnamedField +.. c:var:: const char * const PyStructSequence_UnnamedField Special value for a field name to leave it unnamed. + .. versionchanged:: 3.9 + The type was changed from ``char *``. + .. c:function:: PyObject* PyStructSequence_New(PyTypeObject *type) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index b1beb0b..6e9ddc5 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -215,6 +215,9 @@ Build and C API Changes way to call a callable Python object without any argument. (Contributed by Victor Stinner in :issue:`37194`.) +* The global variable :c:data:`PyStructSequence_UnnamedField` is now a constant + and refers to a constant string. + (Contributed by Serhiy Storchaka in :issue:`38650`.) Deprecated diff --git a/Include/structseq.h b/Include/structseq.h index e5e5d5c..8f51c89 100644 --- a/Include/structseq.h +++ b/Include/structseq.h @@ -19,7 +19,7 @@ typedef struct PyStructSequence_Desc { int n_in_sequence; } PyStructSequence_Desc; -extern char* PyStructSequence_UnnamedField; +extern const char * const PyStructSequence_UnnamedField; #ifndef Py_LIMITED_API PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type, diff --git a/Misc/NEWS.d/next/C API/2019-10-30-22-03-03.bpo-38650.0pi8zt.rst b/Misc/NEWS.d/next/C API/2019-10-30-22-03-03.bpo-38650.0pi8zt.rst new file mode 100644 index 0000000..55b9c13 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-10-30-22-03-03.bpo-38650.0pi8zt.rst @@ -0,0 +1,2 @@ +The global variable :c:data:`PyStructSequence_UnnamedField` is now a +constant and refers to a constant string. diff --git a/Objects/structseq.c b/Objects/structseq.c index c158afc..c86fbe5 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -18,7 +18,7 @@ static const char unnamed_fields_key[] = "n_unnamed_fields"; /* Fields with this name have only a field index, not a field name. They are only allowed for indices < n_visible_fields. */ -char *PyStructSequence_UnnamedField = "unnamed field"; +const char * const PyStructSequence_UnnamedField = "unnamed field"; _Py_IDENTIFIER(n_sequence_fields); _Py_IDENTIFIER(n_fields); _Py_IDENTIFIER(n_unnamed_fields); -- cgit v0.12