Issue #28761: The fields name and doc of structures PyMemberDef, PyGetSetDef,
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Nov 2016 05:58:08 +0000 (07:58 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Nov 2016 05:58:08 +0000 (07:58 +0200)
PyStructSequence_Field, PyStructSequence_Desc, and wrapperbase are now of
type "const char *" rather of "char *".

Doc/c-api/typeobj.rst
Doc/extending/newtypes.rst
Doc/whatsnew/3.7.rst
Include/descrobject.h
Include/structmember.h
Include/structseq.h
Misc/NEWS
Objects/structseq.c

index 323f017d65bb123cd1ebe1cb171a803f1a13c05a..4a27d4b843e32a160a62771244dcfc5ddb1a43a4 100644 (file)
@@ -725,11 +725,11 @@ type objects) *must* have the :attr:`ob_size` field.
       typedef int (*setter)(PyObject *, PyObject *, void *);
 
       typedef struct PyGetSetDef {
-          char *name;    /* attribute name */
-          getter get;    /* C function to get the attribute */
-          setter set;    /* C function to set or delete the attribute */
-          char *doc;     /* optional doc string */
-          void *closure; /* optional additional data for getter and setter */
+          const char *name; /* attribute name */
+          getter get;       /* C function to get the attribute */
+          setter set;       /* C function to set or delete the attribute */
+          const char *doc;  /* optional doc string */
+          void *closure;    /* optional additional data for getter and setter */
       } PyGetSetDef;
 
 
index b8ce4377877e707cf0d85f5fc4ca33a391065526..118f336ae11deb30868eff3270bae45fd253843e 100644 (file)
@@ -1138,11 +1138,11 @@ in the instance.  A variety of primitive C types are supported, and access may
 be read-only or read-write.  The structures in the table are defined as::
 
    typedef struct PyMemberDef {
-       char *name;
-       int   type;
-       int   offset;
-       int   flags;
-       char *doc;
+       const char *name;
+       int         type;
+       int         offset;
+       int         flags;
+       const char *doc;
    } PyMemberDef;
 
 For each entry in the table, a :term:`descriptor` will be constructed and added to the
index de0c3646bdb5f7477e673bc55a55747c9fc9eee8..0f6ebc4b1d548d41989806af39c5d87d840208d5 100644 (file)
@@ -99,6 +99,12 @@ Build and C API Changes
   of libffi is now required when building ``_ctypes`` on such platforms.
   Contributed by Zachary Ware in :issue:`27979`.
 
+* The fields :c:member:`name` and :c:member:`doc` of structures
+  :c:type:`PyMemberDef`, :c:type:`PyGetSetDef`,
+  :c:type:`PyStructSequence_Field`, :c:type:`PyStructSequence_Desc`,
+  and :c:type:`wrapperbase` are now of type ``const char *`` rather of
+  ``char *``.  (Contributed by Serhiy Storchaka in :issue:`28761`.)
+
 
 Deprecated
 ==========
index 8f3e84c365fce36a124bd879118161365853a299..013d64521f5edc47dafdc947d763e5025195daf2 100644 (file)
@@ -9,10 +9,10 @@ typedef PyObject *(*getter)(PyObject *, void *);
 typedef int (*setter)(PyObject *, PyObject *, void *);
 
 typedef struct PyGetSetDef {
-    char *name;
+    const char *name;
     getter get;
     setter set;
-    char *doc;
+    const char *doc;
     void *closure;
 } PyGetSetDef;
 
@@ -24,11 +24,11 @@ typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
                                       void *wrapped, PyObject *kwds);
 
 struct wrapperbase {
-    char *name;
+    const char *name;
     int offset;
     void *function;
     wrapperfunc wrapper;
-    char *doc;
+    const char *doc;
     int flags;
     PyObject *name_strobj;
 };
index 5da8a46682946cb28069d910778aecdebdc5dabb..b54f7081f458dd9c33a524874b4b3e90c3bbf954 100644 (file)
@@ -16,11 +16,11 @@ extern "C" {
    pointer is NULL. */
 
 typedef struct PyMemberDef {
-    char *name;
+    const char *name;
     int type;
     Py_ssize_t offset;
     int flags;
-    char *doc;
+    const char *doc;
 } PyMemberDef;
 
 /* Types */
index af227164c8d4587eee53c24d30524be9b851f5e5..e5e5d5c5735e9d5dc79d3417c09be5a1e7556d3f 100644 (file)
@@ -8,13 +8,13 @@ extern "C" {
 #endif
 
 typedef struct PyStructSequence_Field {
-    char *name;
-    char *doc;
+    const char *name;
+    const char *doc;
 } PyStructSequence_Field;
 
 typedef struct PyStructSequence_Desc {
-    char *name;
-    char *doc;
+    const char *name;
+    const char *doc;
     struct PyStructSequence_Field *fields;
     int n_in_sequence;
 } PyStructSequence_Desc;
index 4eb0408a89407b89b9a78d4f8779c72d522d834c..72114e842c0681698596fab94d71e4d55bd4ebb6 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -432,6 +432,10 @@ Windows
 C API
 -----
 
+- Issue #28761: The fields name and doc of structures PyMemberDef, PyGetSetDef,
+  PyStructSequence_Field, PyStructSequence_Desc, and wrapperbase are now of
+  type "const char *" rather of "char *".
+
 - Issue #28748: Private variable _Py_PackageContext is now of type "const char *"
   rather of "char *".
 
index 6f1782f29b836336f63144afaeb28e8e68c1409f..c2ece5abb1ca2d2496fcab79f6ff2fede1a26bac 100644 (file)
@@ -256,7 +256,7 @@ structseq_reduce(PyStructSequence* self)
     }
 
     for (; i < n_fields; i++) {
-        char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name;
+        const char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name;
         if (PyDict_SetItemString(dict, n, self->ob_item[i]) < 0)
             goto error;
     }