diff options
author | Victor Stinner <vstinner@python.org> | 2023-07-25 13:28:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 13:28:30 (GMT) |
commit | 1a3faba9f15e0c03c6cc0d225d377b8910b5379f (patch) | |
tree | 0aebe4139933835899fd5f618c023bceb9de0389 /Python | |
parent | ed082383272c2c238e364e9cc83229234aee23cc (diff) | |
download | cpython-1a3faba9f15e0c03c6cc0d225d377b8910b5379f.zip cpython-1a3faba9f15e0c03c6cc0d225d377b8910b5379f.tar.gz cpython-1a3faba9f15e0c03c6cc0d225d377b8910b5379f.tar.bz2 |
gh-106869: Use new PyMemberDef constant names (#106871)
* 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)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 3 | ||||
-rw-r--r-- | Python/bytecodes.c | 2 | ||||
-rw-r--r-- | Python/ceval.c | 2 | ||||
-rw-r--r-- | Python/context.c | 4 | ||||
-rw-r--r-- | Python/specialize.c | 12 | ||||
-rw-r--r-- | Python/structmember.c | 86 | ||||
-rw-r--r-- | Python/symtable.c | 18 | ||||
-rw-r--r-- | Python/traceback.c | 8 |
8 files changed, 67 insertions, 68 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 55a1370..412de79 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -6,7 +6,6 @@ #include "pycore_ceval.h" // _Py_EnterRecursiveCall #include "pycore_interp.h" // _PyInterpreterState.ast #include "pycore_pystate.h" // _PyInterpreterState_GET() -#include "structmember.h" #include <stddef.h> // Forward declaration @@ -923,7 +922,7 @@ ast_type_reduce(PyObject *self, PyObject *unused) } static PyMemberDef ast_type_members[] = { - {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY}, + {"__dictoffset__", Py_T_PYSSIZET, offsetof(AST_object, dict), Py_READONLY}, {NULL} /* Sentinel */ }; diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 0705f5b..0f1e007 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -36,7 +36,7 @@ #include "optimizer.h" #include "pydtrace.h" #include "setobject.h" -#include "structmember.h" // struct PyMemberDef, T_OFFSET_EX + #define USE_COMPUTED_GOTOS 0 #include "ceval_macros.h" diff --git a/Python/ceval.c b/Python/ceval.c index a8987ef..688c019 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -34,7 +34,7 @@ #include "opcode.h" #include "pydtrace.h" #include "setobject.h" -#include "structmember.h" // struct PyMemberDef, T_OFFSET_EX + #include <ctype.h> #include <stdbool.h> diff --git a/Python/context.c b/Python/context.c index 1ffae98..9ac5187 100644 --- a/Python/context.c +++ b/Python/context.c @@ -7,7 +7,7 @@ #include "pycore_object.h" #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() -#include "structmember.h" // PyMemberDef + #include "clinic/context.c.h" @@ -1042,7 +1042,7 @@ _contextvars_ContextVar_reset(PyContextVar *self, PyObject *token) static PyMemberDef PyContextVar_members[] = { - {"name", T_OBJECT, offsetof(PyContextVar, var_name), READONLY}, + {"name", _Py_T_OBJECT, offsetof(PyContextVar, var_name), Py_READONLY}, {NULL} }; diff --git a/Python/specialize.c b/Python/specialize.c index 5892f54..1669ce1 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -9,7 +9,7 @@ #include "pycore_object.h" #include "pycore_opcode.h" // _PyOpcode_Caches #include "pycore_pylifecycle.h" // _PyOS_URandomNonblock() -#include "structmember.h" // struct PyMemberDef, T_OFFSET_EX + #include <stdlib.h> // rand() @@ -621,7 +621,7 @@ analyze_descriptor(PyTypeObject *type, PyObject *name, PyObject **descr, int sto if (desc_cls == &PyMemberDescr_Type) { PyMemberDescrObject *member = (PyMemberDescrObject *)descriptor; struct PyMemberDef *dmem = member->d_member; - if (dmem->type == T_OBJECT_EX) { + if (dmem->type == Py_T_OBJECT_EX) { return OBJECT_SLOT; } return OTHER_SLOT; @@ -803,7 +803,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_EXPECTED_ERROR); goto fail; } - if (dmem->flags & PY_AUDIT_READ) { + if (dmem->flags & Py_AUDIT_READ) { SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_AUDITED_SLOT); goto fail; } @@ -811,7 +811,7 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_OUT_OF_RANGE); goto fail; } - assert(dmem->type == T_OBJECT_EX); + assert(dmem->type == Py_T_OBJECT_EX); assert(offset > 0); cache->index = (uint16_t)offset; write_u32(cache->version, type->tp_version_tag); @@ -939,7 +939,7 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_EXPECTED_ERROR); goto fail; } - if (dmem->flags & READONLY) { + if (dmem->flags & Py_READONLY) { SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_ATTR_READ_ONLY); goto fail; } @@ -947,7 +947,7 @@ _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name) SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_OUT_OF_RANGE); goto fail; } - assert(dmem->type == T_OBJECT_EX); + assert(dmem->type == Py_T_OBJECT_EX); assert(offset > 0); cache->index = (uint16_t)offset; write_u32(cache->version, type->tp_version_tag); diff --git a/Python/structmember.c b/Python/structmember.c index 19a7522..7a5a6a4 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -2,7 +2,7 @@ /* Map C struct members to Python object attributes */ #include "Python.h" -#include "structmember.h" // PyMemberDef + PyObject * PyMember_GetOne(const char *obj_addr, PyMemberDef *l) @@ -17,62 +17,62 @@ PyMember_GetOne(const char *obj_addr, PyMemberDef *l) const char* addr = obj_addr + l->offset; switch (l->type) { - case T_BOOL: + case Py_T_BOOL: v = PyBool_FromLong(*(char*)addr); break; - case T_BYTE: + case Py_T_BYTE: v = PyLong_FromLong(*(char*)addr); break; - case T_UBYTE: + case Py_T_UBYTE: v = PyLong_FromUnsignedLong(*(unsigned char*)addr); break; - case T_SHORT: + case Py_T_SHORT: v = PyLong_FromLong(*(short*)addr); break; - case T_USHORT: + case Py_T_USHORT: v = PyLong_FromUnsignedLong(*(unsigned short*)addr); break; - case T_INT: + case Py_T_INT: v = PyLong_FromLong(*(int*)addr); break; - case T_UINT: + case Py_T_UINT: v = PyLong_FromUnsignedLong(*(unsigned int*)addr); break; - case T_LONG: + case Py_T_LONG: v = PyLong_FromLong(*(long*)addr); break; - case T_ULONG: + case Py_T_ULONG: v = PyLong_FromUnsignedLong(*(unsigned long*)addr); break; - case T_PYSSIZET: + case Py_T_PYSSIZET: v = PyLong_FromSsize_t(*(Py_ssize_t*)addr); break; - case T_FLOAT: + case Py_T_FLOAT: v = PyFloat_FromDouble((double)*(float*)addr); break; - case T_DOUBLE: + case Py_T_DOUBLE: v = PyFloat_FromDouble(*(double*)addr); break; - case T_STRING: + case Py_T_STRING: if (*(char**)addr == NULL) { v = Py_NewRef(Py_None); } else v = PyUnicode_FromString(*(char**)addr); break; - case T_STRING_INPLACE: + case Py_T_STRING_INPLACE: v = PyUnicode_FromString((char*)addr); break; - case T_CHAR: + case Py_T_CHAR: v = PyUnicode_FromStringAndSize((char*)addr, 1); break; - case T_OBJECT: + case _Py_T_OBJECT: v = *(PyObject **)addr; if (v == NULL) v = Py_None; Py_INCREF(v); break; - case T_OBJECT_EX: + case Py_T_OBJECT_EX: v = *(PyObject **)addr; if (v == NULL) { PyObject *obj = (PyObject *)obj_addr; @@ -83,13 +83,13 @@ PyMember_GetOne(const char *obj_addr, PyMemberDef *l) } Py_XINCREF(v); break; - case T_LONGLONG: + case Py_T_LONGLONG: v = PyLong_FromLongLong(*(long long *)addr); break; - case T_ULONGLONG: + case Py_T_ULONGLONG: v = PyLong_FromUnsignedLongLong(*(unsigned long long *)addr); break; - case T_NONE: + case _Py_T_NONE: v = Py_NewRef(Py_None); break; default: @@ -118,27 +118,27 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) addr += l->offset; - if ((l->flags & READONLY)) + if ((l->flags & Py_READONLY)) { PyErr_SetString(PyExc_AttributeError, "readonly attribute"); return -1; } if (v == NULL) { - if (l->type == T_OBJECT_EX) { + if (l->type == Py_T_OBJECT_EX) { /* Check if the attribute is set. */ if (*(PyObject **)addr == NULL) { PyErr_SetString(PyExc_AttributeError, l->name); return -1; } } - else if (l->type != T_OBJECT) { + else if (l->type != _Py_T_OBJECT) { PyErr_SetString(PyExc_TypeError, "can't delete numeric/char attribute"); return -1; } } switch (l->type) { - case T_BOOL:{ + case Py_T_BOOL:{ if (!PyBool_Check(v)) { PyErr_SetString(PyExc_TypeError, "attribute value type must be bool"); @@ -150,7 +150,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) *(char*)addr = (char) 0; break; } - case T_BYTE:{ + case Py_T_BYTE:{ long long_val = PyLong_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; @@ -161,7 +161,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to char"); break; } - case T_UBYTE:{ + case Py_T_UBYTE:{ long long_val = PyLong_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; @@ -170,7 +170,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to unsigned char"); break; } - case T_SHORT:{ + case Py_T_SHORT:{ long long_val = PyLong_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; @@ -179,7 +179,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to short"); break; } - case T_USHORT:{ + case Py_T_USHORT:{ long long_val = PyLong_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; @@ -188,7 +188,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to unsigned short"); break; } - case T_INT:{ + case Py_T_INT:{ long long_val = PyLong_AsLong(v); if ((long_val == -1) && PyErr_Occurred()) return -1; @@ -197,7 +197,7 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to int"); break; } - case T_UINT:{ + case Py_T_UINT:{ unsigned long ulong_val = PyLong_AsUnsignedLong(v); if ((ulong_val == (unsigned long)-1) && PyErr_Occurred()) { /* XXX: For compatibility, accept negative int values @@ -215,13 +215,13 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) WARN("Truncation of value to unsigned int"); break; } - case T_LONG:{ + case Py_T_LONG:{ *(long*)addr = PyLong_AsLong(v); if ((*(long*)addr == -1) && PyErr_Occurred()) return -1; break; } - case T_ULONG:{ + case Py_T_ULONG:{ *(unsigned long*)addr = PyLong_AsUnsignedLong(v); if ((*(unsigned long*)addr == (unsigned long)-1) && PyErr_Occurred()) { @@ -236,32 +236,32 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) } break; } - case T_PYSSIZET:{ + case Py_T_PYSSIZET:{ *(Py_ssize_t*)addr = PyLong_AsSsize_t(v); if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1) && PyErr_Occurred()) return -1; break; } - case T_FLOAT:{ + case Py_T_FLOAT:{ double double_val = PyFloat_AsDouble(v); if ((double_val == -1) && PyErr_Occurred()) return -1; *(float*)addr = (float)double_val; break; } - case T_DOUBLE: + case Py_T_DOUBLE: *(double*)addr = PyFloat_AsDouble(v); if ((*(double*)addr == -1) && PyErr_Occurred()) return -1; break; - case T_OBJECT: - case T_OBJECT_EX: + case _Py_T_OBJECT: + case Py_T_OBJECT_EX: oldv = *(PyObject **)addr; *(PyObject **)addr = Py_XNewRef(v); Py_XDECREF(oldv); break; - case T_CHAR: { + case Py_T_CHAR: { const char *string; Py_ssize_t len; @@ -273,18 +273,18 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v) *(char*)addr = string[0]; break; } - case T_STRING: - case T_STRING_INPLACE: + case Py_T_STRING: + case Py_T_STRING_INPLACE: PyErr_SetString(PyExc_TypeError, "readonly attribute"); return -1; - case T_LONGLONG:{ + case Py_T_LONGLONG:{ long long value; *(long long*)addr = value = PyLong_AsLongLong(v); if ((value == -1) && PyErr_Occurred()) return -1; break; } - case T_ULONGLONG:{ + case Py_T_ULONGLONG:{ unsigned long long value; /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong doesn't ??? */ diff --git a/Python/symtable.c b/Python/symtable.c index 2407367..04be319 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -3,7 +3,7 @@ #include "pycore_parser.h" // _PyParser_ASTFromString() #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_symtable.h" // PySTEntryObject -#include "structmember.h" // PyMemberDef + /* error strings used for warnings */ #define GLOBAL_PARAM \ @@ -171,14 +171,14 @@ ste_dealloc(PySTEntryObject *ste) #define OFF(x) offsetof(PySTEntryObject, x) static PyMemberDef ste_memberlist[] = { - {"id", T_OBJECT, OFF(ste_id), READONLY}, - {"name", T_OBJECT, OFF(ste_name), READONLY}, - {"symbols", T_OBJECT, OFF(ste_symbols), READONLY}, - {"varnames", T_OBJECT, OFF(ste_varnames), READONLY}, - {"children", T_OBJECT, OFF(ste_children), READONLY}, - {"nested", T_INT, OFF(ste_nested), READONLY}, - {"type", T_INT, OFF(ste_type), READONLY}, - {"lineno", T_INT, OFF(ste_lineno), READONLY}, + {"id", _Py_T_OBJECT, OFF(ste_id), Py_READONLY}, + {"name", _Py_T_OBJECT, OFF(ste_name), Py_READONLY}, + {"symbols", _Py_T_OBJECT, OFF(ste_symbols), Py_READONLY}, + {"varnames", _Py_T_OBJECT, OFF(ste_varnames), Py_READONLY}, + {"children", _Py_T_OBJECT, OFF(ste_children), Py_READONLY}, + {"nested", Py_T_INT, OFF(ste_nested), Py_READONLY}, + {"type", Py_T_INT, OFF(ste_type), Py_READONLY}, + {"lineno", Py_T_INT, OFF(ste_lineno), Py_READONLY}, {NULL} }; diff --git a/Python/traceback.c b/Python/traceback.c index c5787b5..ca524b1 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -17,7 +17,7 @@ #include "../Parser/pegen.h" // _PyPegen_byte_offset_to_character_offset() #include "frameobject.h" // PyFrame_New() -#include "structmember.h" // PyMemberDef + #include "osdefs.h" // SEP #ifdef HAVE_FCNTL_H # include <fcntl.h> @@ -148,9 +148,9 @@ static PyMethodDef tb_methods[] = { }; static PyMemberDef tb_memberlist[] = { - {"tb_frame", T_OBJECT, OFF(tb_frame), READONLY|PY_AUDIT_READ}, - {"tb_lasti", T_INT, OFF(tb_lasti), READONLY}, - {"tb_lineno", T_INT, OFF(tb_lineno), READONLY}, + {"tb_frame", _Py_T_OBJECT, OFF(tb_frame), Py_READONLY|Py_AUDIT_READ}, + {"tb_lasti", Py_T_INT, OFF(tb_lasti), Py_READONLY}, + {"tb_lineno", Py_T_INT, OFF(tb_lineno), Py_READONLY}, {NULL} /* Sentinel */ }; |