Skip to content

Commit

Permalink
gh-106869: Use new PyMemberDef constant names (#106871)
Browse files Browse the repository at this point in the history
* Remove '#include "structmember.h"'.
* If needed, add <stddef.h> to get offsetof() function.
* Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
* Replace:

  * T_SHORT => Py_T_SHORT
  * T_INT => Py_T_INT
  * T_LONG => Py_T_LONG
  * T_FLOAT => Py_T_FLOAT
  * T_DOUBLE => Py_T_DOUBLE
  * T_STRING => Py_T_STRING
  * T_OBJECT => _Py_T_OBJECT
  * T_CHAR => Py_T_CHAR
  * T_BYTE => Py_T_BYTE
  * T_UBYTE => Py_T_UBYTE
  * T_USHORT => Py_T_USHORT
  * T_UINT => Py_T_UINT
  * T_ULONG => Py_T_ULONG
  * T_STRING_INPLACE => Py_T_STRING_INPLACE
  * T_BOOL => Py_T_BOOL
  * T_OBJECT_EX => Py_T_OBJECT_EX
  * T_LONGLONG => Py_T_LONGLONG
  * T_ULONGLONG => Py_T_ULONGLONG
  * T_PYSSIZET => Py_T_PYSSIZET
  * T_NONE => _Py_T_NONE
  * READONLY => Py_READONLY
  * PY_AUDIT_READ => Py_AUDIT_READ
  * READ_RESTRICTED => Py_AUDIT_READ
  * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED
  * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
  • Loading branch information
vstinner authored Jul 25, 2023
1 parent ed08238 commit 1a3faba
Show file tree
Hide file tree
Showing 78 changed files with 472 additions and 464 deletions.
4 changes: 2 additions & 2 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ extern "C" {
#endif

#include <stdbool.h>
#include <stddef.h>
#include "pycore_code.h" // STATS
#include <stddef.h> // offsetof()
#include "pycore_code.h" // STATS

/* See Objects/frame_layout.md for an explanation of the frame stack
* including explanation of the PyFrameObject and _PyInterpreterFrame
Expand Down
2 changes: 1 addition & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_runtime_init.h" // _Py_ID()
#include "structmember.h" // PyMemberDef

#include <stddef.h> // offsetof()


Expand Down
14 changes: 7 additions & 7 deletions Modules/_bz2module.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* _bz2 - Low-level Python interface to libbzip2. */

#include "Python.h"
#include "structmember.h" // PyMemberDef

#include <bzlib.h>
#include <stdio.h>
#include <stddef.h> // offsetof()

// Blocks output buffer wrappers
#include "pycore_blocks_output_buffer.h"
Expand Down Expand Up @@ -112,7 +112,7 @@ typedef struct {
typedef struct {
PyObject_HEAD
bz_stream bzs;
char eof; /* T_BOOL expects a char */
char eof; /* Py_T_BOOL expects a char */
PyObject *unused_data;
char needs_input;
char *input_buffer;
Expand Down Expand Up @@ -714,11 +714,11 @@ PyDoc_STRVAR(BZ2Decompressor_needs_input_doc,
"True if more input is needed before more decompressed data can be produced.");

static PyMemberDef BZ2Decompressor_members[] = {
{"eof", T_BOOL, offsetof(BZ2Decompressor, eof),
READONLY, BZ2Decompressor_eof__doc__},
{"unused_data", T_OBJECT_EX, offsetof(BZ2Decompressor, unused_data),
READONLY, BZ2Decompressor_unused_data__doc__},
{"needs_input", T_BOOL, offsetof(BZ2Decompressor, needs_input), READONLY,
{"eof", Py_T_BOOL, offsetof(BZ2Decompressor, eof),
Py_READONLY, BZ2Decompressor_eof__doc__},
{"unused_data", Py_T_OBJECT_EX, offsetof(BZ2Decompressor, unused_data),
Py_READONLY, BZ2Decompressor_unused_data__doc__},
{"needs_input", Py_T_BOOL, offsetof(BZ2Decompressor, needs_input), Py_READONLY,
BZ2Decompressor_needs_input_doc},
{NULL}
};
Expand Down
8 changes: 4 additions & 4 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
#include "structmember.h" // PyMemberDef

#include <stddef.h>

typedef struct {
Expand Down Expand Up @@ -1630,7 +1630,7 @@ static PyMethodDef deque_methods[] = {
};

static PyMemberDef deque_members[] = {
{"__weaklistoffset__", T_PYSSIZET, offsetof(dequeobject, weakreflist), READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(dequeobject, weakreflist), Py_READONLY},
{NULL},
};

Expand Down Expand Up @@ -2054,7 +2054,7 @@ static PyMethodDef defdict_methods[] = {
};

static PyMemberDef defdict_members[] = {
{"default_factory", T_OBJECT,
{"default_factory", _Py_T_OBJECT,
offsetof(defdictobject, default_factory), 0,
PyDoc_STR("Factory for default value called by __missing__().")},
{NULL}
Expand Down Expand Up @@ -2466,7 +2466,7 @@ tuplegetter_repr(_tuplegetterobject *self)


static PyMemberDef tuplegetter_members[] = {
{"__doc__", T_OBJECT, offsetof(_tuplegetterobject, doc), 0},
{"__doc__", _Py_T_OBJECT, offsetof(_tuplegetterobject, doc), 0},
{0}
};

Expand Down
15 changes: 8 additions & 7 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module instead.
#define MODULE_VERSION "1.0"

#include "Python.h"
#include "structmember.h" // PyMemberDef

#include <stddef.h> // offsetof()
#include <stdbool.h>

/*[clinic input]
Expand Down Expand Up @@ -336,9 +337,9 @@ dialect_check_quoting(int quoting)
#define D_OFF(x) offsetof(DialectObj, x)

static struct PyMemberDef Dialect_memberlist[] = {
{ "skipinitialspace", T_BOOL, D_OFF(skipinitialspace), READONLY },
{ "doublequote", T_BOOL, D_OFF(doublequote), READONLY },
{ "strict", T_BOOL, D_OFF(strict), READONLY },
{ "skipinitialspace", Py_T_BOOL, D_OFF(skipinitialspace), Py_READONLY },
{ "doublequote", Py_T_BOOL, D_OFF(doublequote), Py_READONLY },
{ "strict", Py_T_BOOL, D_OFF(strict), Py_READONLY },
{ NULL }
};

Expand Down Expand Up @@ -970,8 +971,8 @@ static struct PyMethodDef Reader_methods[] = {
#define R_OFF(x) offsetof(ReaderObj, x)

static struct PyMemberDef Reader_memberlist[] = {
{ "dialect", T_OBJECT, R_OFF(dialect), READONLY },
{ "line_num", T_ULONG, R_OFF(line_num), READONLY },
{ "dialect", _Py_T_OBJECT, R_OFF(dialect), Py_READONLY },
{ "line_num", Py_T_ULONG, R_OFF(line_num), Py_READONLY },
{ NULL }
};

Expand Down Expand Up @@ -1364,7 +1365,7 @@ static struct PyMethodDef Writer_methods[] = {
#define W_OFF(x) offsetof(WriterObj, x)

static struct PyMemberDef Writer_memberlist[] = {
{ "dialect", T_OBJECT, W_OFF(dialect), READONLY },
{ "dialect", _Py_T_OBJECT, W_OFF(dialect), Py_READONLY },
{ NULL }
};

Expand Down
14 changes: 7 additions & 7 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bytes(cdata)

#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
#include "structmember.h" // PyMemberDef


#include <ffi.h>
#ifdef MS_WIN32
Expand Down Expand Up @@ -2759,14 +2759,14 @@ PyCData_dealloc(PyObject *self)
}

static PyMemberDef PyCData_members[] = {
{ "_b_base_", T_OBJECT,
offsetof(CDataObject, b_base), READONLY,
{ "_b_base_", _Py_T_OBJECT,
offsetof(CDataObject, b_base), Py_READONLY,
"the base object" },
{ "_b_needsfree_", T_INT,
offsetof(CDataObject, b_needsfree), READONLY,
{ "_b_needsfree_", Py_T_INT,
offsetof(CDataObject, b_needsfree), Py_READONLY,
"whether the object owns the memory or not" },
{ "_objects", T_OBJECT,
offsetof(CDataObject, b_objects), READONLY,
{ "_objects", _Py_T_OBJECT,
offsetof(CDataObject, b_objects), Py_READONLY,
"internal objects tree (NEVER CHANGE THIS OBJECT!)"},
{ NULL },
};
Expand Down
6 changes: 3 additions & 3 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#endif

#include "Python.h"
#include "structmember.h" // PyMemberDef


#include <stdbool.h>

Expand Down Expand Up @@ -581,8 +581,8 @@ PyCArg_repr(PyCArgObject *self)
}

static PyMemberDef PyCArgType_members[] = {
{ "_obj", T_OBJECT,
offsetof(PyCArgObject, obj), READONLY,
{ "_obj", _Py_T_OBJECT,
offsetof(PyCArgObject, obj), Py_READONLY,
"the wrapped object" },
{ NULL },
};
Expand Down
8 changes: 4 additions & 4 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_Init()
#include "datetime.h"
#include "structmember.h" // PyMemberDef


#include <time.h>

Expand Down Expand Up @@ -2727,13 +2727,13 @@ delta_reduce(PyDateTime_Delta* self, PyObject *Py_UNUSED(ignored))

static PyMemberDef delta_members[] = {

{"days", T_INT, OFFSET(days), READONLY,
{"days", Py_T_INT, OFFSET(days), Py_READONLY,
PyDoc_STR("Number of days.")},

{"seconds", T_INT, OFFSET(seconds), READONLY,
{"seconds", Py_T_INT, OFFSET(seconds), Py_READONLY,
PyDoc_STR("Number of seconds (>= 0 and less than 1 day).")},

{"microseconds", T_INT, OFFSET(microseconds), READONLY,
{"microseconds", Py_T_INT, OFFSET(microseconds), Py_READONLY,
PyDoc_STR("Number of microseconds (>= 0 and less than 1 second).")},
{NULL}
};
Expand Down
9 changes: 5 additions & 4 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "Python.h"
#include "pycore_import.h" // _PyImport_GetModuleAttrString()
#include "pycore_pyhash.h" // _Py_HashSecret
#include "structmember.h" // PyMemberDef

#include <stddef.h> // offsetof()
#include "expat.h"
#include "pyexpat.h"

Expand Down Expand Up @@ -4134,8 +4135,8 @@ _elementtree_XMLParser__setevents_impl(XMLParserObject *self,
}

static PyMemberDef xmlparser_members[] = {
{"entity", T_OBJECT, offsetof(XMLParserObject, entity), READONLY, NULL},
{"target", T_OBJECT, offsetof(XMLParserObject, target), READONLY, NULL},
{"entity", _Py_T_OBJECT, offsetof(XMLParserObject, entity), Py_READONLY, NULL},
{"target", _Py_T_OBJECT, offsetof(XMLParserObject, target), Py_READONLY, NULL},
{NULL}
};

Expand Down Expand Up @@ -4191,7 +4192,7 @@ static PyMethodDef element_methods[] = {
};

static struct PyMemberDef element_members[] = {
{"__weaklistoffset__", T_PYSSIZET, offsetof(ElementObject, weakreflist), READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(ElementObject, weakreflist), Py_READONLY},
{NULL},
};

Expand Down
30 changes: 15 additions & 15 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "pycore_object.h" // _PyObject_GC_TRACK
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "structmember.h" // PyMemberDef


#include "clinic/_functoolsmodule.c.h"
/*[clinic input]
Expand Down Expand Up @@ -340,18 +340,18 @@ PyDoc_STRVAR(partial_doc,

#define OFF(x) offsetof(partialobject, x)
static PyMemberDef partial_memberlist[] = {
{"func", T_OBJECT, OFF(fn), READONLY,
{"func", _Py_T_OBJECT, OFF(fn), Py_READONLY,
"function object to use in future partial calls"},
{"args", T_OBJECT, OFF(args), READONLY,
{"args", _Py_T_OBJECT, OFF(args), Py_READONLY,
"tuple of arguments to future partial calls"},
{"keywords", T_OBJECT, OFF(kw), READONLY,
{"keywords", _Py_T_OBJECT, OFF(kw), Py_READONLY,
"dictionary of keyword arguments to future partial calls"},
{"__weaklistoffset__", T_PYSSIZET,
offsetof(partialobject, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET,
offsetof(partialobject, dict), READONLY},
{"__vectorcalloffset__", T_PYSSIZET,
offsetof(partialobject, vectorcall), READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET,
offsetof(partialobject, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET,
offsetof(partialobject, dict), Py_READONLY},
{"__vectorcalloffset__", Py_T_PYSSIZET,
offsetof(partialobject, vectorcall), Py_READONLY},
{NULL} /* Sentinel */
};

Expand Down Expand Up @@ -540,7 +540,7 @@ keyobject_traverse(keyobject *ko, visitproc visit, void *arg)
}

static PyMemberDef keyobject_members[] = {
{"obj", T_OBJECT,
{"obj", _Py_T_OBJECT,
offsetof(keyobject, object), 0,
PyDoc_STR("Value wrapped by a key function.")},
{NULL}
Expand Down Expand Up @@ -1394,10 +1394,10 @@ static PyGetSetDef lru_cache_getsetlist[] = {
};

static PyMemberDef lru_cache_memberlist[] = {
{"__dictoffset__", T_PYSSIZET,
offsetof(lru_cache_object, dict), READONLY},
{"__weaklistoffset__", T_PYSSIZET,
offsetof(lru_cache_object, weakreflist), READONLY},
{"__dictoffset__", Py_T_PYSSIZET,
offsetof(lru_cache_object, dict), Py_READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET,
offsetof(lru_cache_object, weakreflist), Py_READONLY},
{NULL} /* Sentinel */
};

Expand Down
30 changes: 15 additions & 15 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat()
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
#include "structmember.h" // PyMemberDef

#include "_iomodule.h"

/*[clinic input]
Expand Down Expand Up @@ -2478,10 +2478,10 @@ static PyMethodDef bufferedreader_methods[] = {
};

static PyMemberDef bufferedreader_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{"_finalizing", T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", T_PYSSIZET, offsetof(buffered, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(buffered, dict), READONLY},
{"raw", _Py_T_OBJECT, offsetof(buffered, raw), Py_READONLY},
{"_finalizing", Py_T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(buffered, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET, offsetof(buffered, dict), Py_READONLY},
{NULL}
};

Expand Down Expand Up @@ -2538,10 +2538,10 @@ static PyMethodDef bufferedwriter_methods[] = {
};

static PyMemberDef bufferedwriter_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{"_finalizing", T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", T_PYSSIZET, offsetof(buffered, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(buffered, dict), READONLY},
{"raw", _Py_T_OBJECT, offsetof(buffered, raw), Py_READONLY},
{"_finalizing", Py_T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(buffered, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET, offsetof(buffered, dict), Py_READONLY},
{NULL}
};

Expand Down Expand Up @@ -2594,8 +2594,8 @@ static PyMethodDef bufferedrwpair_methods[] = {
};

static PyMemberDef bufferedrwpair_members[] = {
{"__weaklistoffset__", T_PYSSIZET, offsetof(rwpair, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(rwpair, dict), READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(rwpair, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET, offsetof(rwpair, dict), Py_READONLY},
{NULL}
};

Expand Down Expand Up @@ -2656,10 +2656,10 @@ static PyMethodDef bufferedrandom_methods[] = {
};

static PyMemberDef bufferedrandom_members[] = {
{"raw", T_OBJECT, offsetof(buffered, raw), READONLY},
{"_finalizing", T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", T_PYSSIZET, offsetof(buffered, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(buffered, dict), READONLY},
{"raw", _Py_T_OBJECT, offsetof(buffered, raw), Py_READONLY},
{"_finalizing", Py_T_BOOL, offsetof(buffered, finalizing), 0},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(buffered, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET, offsetof(buffered, dict), Py_READONLY},
{NULL}
};

Expand Down
4 changes: 2 additions & 2 deletions Modules/_io/bytesio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ static struct PyMethodDef bytesio_methods[] = {
};

static PyMemberDef bytesio_members[] = {
{"__weaklistoffset__", T_PYSSIZET, offsetof(bytesio, weakreflist), READONLY},
{"__dictoffset__", T_PYSSIZET, offsetof(bytesio, dict), READONLY},
{"__weaklistoffset__", Py_T_PYSSIZET, offsetof(bytesio, weakreflist), Py_READONLY},
{"__dictoffset__", Py_T_PYSSIZET, offsetof(bytesio, dict), Py_READONLY},
{NULL}
};

Expand Down
Loading

0 comments on commit 1a3faba

Please sign in to comment.