mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
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)
This commit is contained in:
parent
ed08238327
commit
1a3faba9f1
78 changed files with 472 additions and 464 deletions
3
Python/Python-ast.c
generated
3
Python/Python-ast.c
generated
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 ??? */
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue