Skip to content

Commit

Permalink
Issue #28761: The fields name and doc of structures PyMemberDef, PyGe…
Browse files Browse the repository at this point in the history
…tSetDef,

PyStructSequence_Field, PyStructSequence_Desc, and wrapperbase are now of
type "const char *" rather of "char *".
  • Loading branch information
serhiy-storchaka committed Nov 22, 2016
1 parent 9af740b commit 007d7ff
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 21 deletions.
10 changes: 5 additions & 5 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
10 changes: 5 additions & 5 deletions Doc/extending/newtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
==========
Expand Down
8 changes: 4 additions & 4 deletions Include/descrobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions Include/structmember.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions Include/structseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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 *".

Expand Down
2 changes: 1 addition & 1 deletion Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 007d7ff

Please sign in to comment.