GH-90699: Remove `_Py_IDENTIFIER` usage from `_ctypes` (GH-99054)

This commit is contained in:
Kumar Aditya 2022-11-04 01:50:10 +05:30 committed by GitHub
parent 0faa0ba240
commit 0ee59a9ca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 163 additions and 64 deletions

View File

@ -91,6 +91,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(__complex__)
STRUCT_FOR_ID(__contains__)
STRUCT_FOR_ID(__copy__)
STRUCT_FOR_ID(__ctypes_from_outparam__)
STRUCT_FOR_ID(__del__)
STRUCT_FOR_ID(__delattr__)
STRUCT_FOR_ID(__delete__)
@ -217,25 +218,39 @@ struct _Py_global_strings {
STRUCT_FOR_ID(__weakref__)
STRUCT_FOR_ID(__xor__)
STRUCT_FOR_ID(_abc_impl)
STRUCT_FOR_ID(_abstract_)
STRUCT_FOR_ID(_annotation)
STRUCT_FOR_ID(_anonymous_)
STRUCT_FOR_ID(_argtypes_)
STRUCT_FOR_ID(_as_parameter_)
STRUCT_FOR_ID(_asyncio_future_blocking)
STRUCT_FOR_ID(_blksize)
STRUCT_FOR_ID(_bootstrap)
STRUCT_FOR_ID(_check_retval_)
STRUCT_FOR_ID(_dealloc_warn)
STRUCT_FOR_ID(_feature_version)
STRUCT_FOR_ID(_fields_)
STRUCT_FOR_ID(_finalizing)
STRUCT_FOR_ID(_find_and_load)
STRUCT_FOR_ID(_fix_up_module)
STRUCT_FOR_ID(_flags_)
STRUCT_FOR_ID(_get_sourcefile)
STRUCT_FOR_ID(_handle_fromlist)
STRUCT_FOR_ID(_initializing)
STRUCT_FOR_ID(_is_text_encoding)
STRUCT_FOR_ID(_length_)
STRUCT_FOR_ID(_lock_unlock_module)
STRUCT_FOR_ID(_loop)
STRUCT_FOR_ID(_needs_com_addref_)
STRUCT_FOR_ID(_pack_)
STRUCT_FOR_ID(_restype_)
STRUCT_FOR_ID(_showwarnmsg)
STRUCT_FOR_ID(_shutdown)
STRUCT_FOR_ID(_slotnames)
STRUCT_FOR_ID(_swappedbytes_)
STRUCT_FOR_ID(_type_)
STRUCT_FOR_ID(_uninitialized_submodules)
STRUCT_FOR_ID(_use_broken_old_ctypes_structure_semantics_)
STRUCT_FOR_ID(_warn_unawaited_coroutine)
STRUCT_FOR_ID(_xoptions)
STRUCT_FOR_ID(a)
@ -387,6 +402,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(follow_symlinks)
STRUCT_FOR_ID(format)
STRUCT_FOR_ID(frequency)
STRUCT_FOR_ID(from_param)
STRUCT_FOR_ID(fromlist)
STRUCT_FOR_ID(fset)
STRUCT_FOR_ID(func)

View File

@ -600,6 +600,7 @@ extern "C" {
INIT_ID(__complex__), \
INIT_ID(__contains__), \
INIT_ID(__copy__), \
INIT_ID(__ctypes_from_outparam__), \
INIT_ID(__del__), \
INIT_ID(__delattr__), \
INIT_ID(__delete__), \
@ -726,25 +727,39 @@ extern "C" {
INIT_ID(__weakref__), \
INIT_ID(__xor__), \
INIT_ID(_abc_impl), \
INIT_ID(_abstract_), \
INIT_ID(_annotation), \
INIT_ID(_anonymous_), \
INIT_ID(_argtypes_), \
INIT_ID(_as_parameter_), \
INIT_ID(_asyncio_future_blocking), \
INIT_ID(_blksize), \
INIT_ID(_bootstrap), \
INIT_ID(_check_retval_), \
INIT_ID(_dealloc_warn), \
INIT_ID(_feature_version), \
INIT_ID(_fields_), \
INIT_ID(_finalizing), \
INIT_ID(_find_and_load), \
INIT_ID(_fix_up_module), \
INIT_ID(_flags_), \
INIT_ID(_get_sourcefile), \
INIT_ID(_handle_fromlist), \
INIT_ID(_initializing), \
INIT_ID(_is_text_encoding), \
INIT_ID(_length_), \
INIT_ID(_lock_unlock_module), \
INIT_ID(_loop), \
INIT_ID(_needs_com_addref_), \
INIT_ID(_pack_), \
INIT_ID(_restype_), \
INIT_ID(_showwarnmsg), \
INIT_ID(_shutdown), \
INIT_ID(_slotnames), \
INIT_ID(_swappedbytes_), \
INIT_ID(_type_), \
INIT_ID(_uninitialized_submodules), \
INIT_ID(_use_broken_old_ctypes_structure_semantics_), \
INIT_ID(_warn_unawaited_coroutine), \
INIT_ID(_xoptions), \
INIT_ID(a), \
@ -896,6 +911,7 @@ extern "C" {
INIT_ID(follow_symlinks), \
INIT_ID(format), \
INIT_ID(frequency), \
INIT_ID(from_param), \
INIT_ID(fromlist), \
INIT_ID(fset), \
INIT_ID(func), \
@ -1532,6 +1548,8 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(__copy__);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(__ctypes_from_outparam__);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(__del__);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(__delattr__);
@ -1784,24 +1802,38 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_abc_impl);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_abstract_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_annotation);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_anonymous_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_argtypes_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_as_parameter_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_asyncio_future_blocking);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_blksize);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_bootstrap);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_check_retval_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_dealloc_warn);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_feature_version);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_fields_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_finalizing);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_find_and_load);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_fix_up_module);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_flags_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_get_sourcefile);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_handle_fromlist);
@ -1810,18 +1842,32 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_is_text_encoding);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_length_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_lock_unlock_module);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_loop);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_needs_com_addref_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_pack_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_restype_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_showwarnmsg);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_shutdown);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_slotnames);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_swappedbytes_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_type_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_uninitialized_submodules);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_use_broken_old_ctypes_structure_semantics_);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_warn_unawaited_coroutine);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(_xoptions);
@ -2124,6 +2170,8 @@ _PyUnicode_InitStaticStrings(void) {
PyUnicode_InternInPlace(&string);
string = &_Py_ID(frequency);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(from_param);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(fromlist);
PyUnicode_InternInPlace(&string);
string = &_Py_ID(fset);
@ -5021,6 +5069,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(__copy__));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(__ctypes_from_outparam__)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(__ctypes_from_outparam__));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(__del__)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(__del__));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5525,10 +5577,26 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_abc_impl));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_abstract_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_abstract_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_annotation)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_annotation));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_anonymous_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_anonymous_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_argtypes_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_argtypes_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_as_parameter_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_as_parameter_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_asyncio_future_blocking)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_asyncio_future_blocking));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5541,6 +5609,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_bootstrap));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_check_retval_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_check_retval_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_dealloc_warn)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_dealloc_warn));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5549,6 +5621,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_feature_version));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_fields_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_fields_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_finalizing)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_finalizing));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5561,6 +5637,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_fix_up_module));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_flags_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_flags_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_get_sourcefile)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_get_sourcefile));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5577,6 +5657,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_is_text_encoding));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_length_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_length_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_lock_unlock_module)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_lock_unlock_module));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5585,6 +5669,18 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_loop));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_needs_com_addref_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_needs_com_addref_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_pack_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_pack_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_restype_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_restype_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_showwarnmsg)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_showwarnmsg));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -5597,10 +5693,22 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(_slotnames));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_swappedbytes_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_swappedbytes_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_type_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_type_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_uninitialized_submodules)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_uninitialized_submodules));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_use_broken_old_ctypes_structure_semantics_)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_use_broken_old_ctypes_structure_semantics_));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(_warn_unawaited_coroutine)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(_warn_unawaited_coroutine));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
@ -6205,6 +6313,10 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyObject_Dump((PyObject *)&_Py_ID(frequency));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(from_param)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(from_param));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");
};
if (Py_REFCNT((PyObject *)&_Py_ID(fromlist)) < _PyObject_IMMORTAL_REFCNT) {
_PyObject_Dump((PyObject *)&_Py_ID(fromlist));
Py_FatalError("immortal object has less refcnt than expected _PyObject_IMMORTAL_REFCNT");

View File

@ -101,8 +101,6 @@ bytes(cdata)
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#include "Python.h"
@ -498,8 +496,6 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
PyTypeObject *result;
PyObject *fields;
StgDictObject *dict;
_Py_IDENTIFIER(_abstract_);
_Py_IDENTIFIER(_fields_);
/* create the new instance (which is a class,
since we are a metatype!) */
@ -508,7 +504,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
return NULL;
/* keep this for bw compatibility */
int r = _PyDict_ContainsId(result->tp_dict, &PyId__abstract_);
int r = PyDict_Contains(result->tp_dict, &_Py_ID(_abstract_));
if (r > 0)
return (PyObject *)result;
if (r < 0) {
@ -540,9 +536,9 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
dict->paramfunc = StructUnionType_paramfunc;
fields = _PyDict_GetItemIdWithError((PyObject *)dict, &PyId__fields_);
fields = PyDict_GetItemWithError((PyObject *)dict, &_Py_ID(_fields_));
if (fields) {
if (_PyObject_SetAttrId((PyObject *)result, &PyId__fields_, fields) < 0) {
if (PyObject_SetAttr((PyObject *)result, &_Py_ID(_fields_), fields) < 0) {
Py_DECREF(result);
return NULL;
}
@ -797,7 +793,6 @@ PyDoc_STRVAR(from_param_doc,
static PyObject *
CDataType_from_param(PyObject *type, PyObject *value)
{
_Py_IDENTIFIER(_as_parameter_);
PyObject *as_parameter;
int res = PyObject_IsInstance(value, type);
if (res == -1)
@ -831,7 +826,7 @@ CDataType_from_param(PyObject *type, PyObject *value)
return NULL;
}
if (_PyObject_LookupAttrId(value, &PyId__as_parameter_, &as_parameter) < 0) {
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
@ -1068,7 +1063,7 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
StgDictObject *stgdict;
PyObject *proto;
PyObject *typedict;
_Py_IDENTIFIER(_type_);
typedict = PyTuple_GetItem(args, 2);
if (!typedict)
@ -1088,7 +1083,7 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
stgdict->paramfunc = PyCPointerType_paramfunc;
stgdict->flags |= TYPEFLAG_ISPOINTER;
proto = _PyDict_GetItemIdWithError(typedict, &PyId__type_); /* Borrowed ref */
proto = PyDict_GetItemWithError(typedict, &_Py_ID(_type_)); /* Borrowed ref */
if (proto) {
StgDictObject *itemdict;
const char *current_format;
@ -1146,7 +1141,7 @@ static PyObject *
PyCPointerType_set_type(PyTypeObject *self, PyObject *type)
{
StgDictObject *dict;
_Py_IDENTIFIER(_type_);
dict = PyType_stgdict((PyObject *)self);
if (!dict) {
@ -1158,7 +1153,7 @@ PyCPointerType_set_type(PyTypeObject *self, PyObject *type)
if (-1 == PyCPointerType_SetProto(dict, type))
return NULL;
if (-1 == _PyDict_SetItemId((PyObject *)dict, &PyId__type_, type))
if (-1 == PyDict_SetItem((PyObject *)dict, &_Py_ID(_type_), type))
return NULL;
Py_RETURN_NONE;
@ -1461,8 +1456,6 @@ PyCArrayType_paramfunc(CDataObject *self)
static PyObject *
PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
_Py_IDENTIFIER(_length_);
_Py_IDENTIFIER(_type_);
PyTypeObject *result;
StgDictObject *stgdict;
StgDictObject *itemdict;
@ -1481,7 +1474,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
stgdict = NULL;
type_attr = NULL;
if (_PyObject_LookupAttrId((PyObject *)result, &PyId__length_, &length_attr) < 0) {
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_length_), &length_attr) < 0) {
goto error;
}
if (!length_attr) {
@ -1514,7 +1507,7 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
if (_PyObject_LookupAttrId((PyObject *)result, &PyId__type_, &type_attr) < 0) {
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_type_), &type_attr) < 0) {
goto error;
}
if (!type_attr) {
@ -1659,7 +1652,6 @@ static const char SIMPLE_TYPE_CHARS[] = "cbBhHiIlLdfuzZqQPXOv?g";
static PyObject *
c_wchar_p_from_param(PyObject *type, PyObject *value)
{
_Py_IDENTIFIER(_as_parameter_);
PyObject *as_parameter;
int res;
if (value == Py_None) {
@ -1709,7 +1701,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
}
}
if (_PyObject_LookupAttrId(value, &PyId__as_parameter_, &as_parameter) < 0) {
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
@ -1726,7 +1718,6 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
static PyObject *
c_char_p_from_param(PyObject *type, PyObject *value)
{
_Py_IDENTIFIER(_as_parameter_);
PyObject *as_parameter;
int res;
if (value == Py_None) {
@ -1776,7 +1767,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
}
}
if (_PyObject_LookupAttrId(value, &PyId__as_parameter_, &as_parameter) < 0) {
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
@ -1793,7 +1784,6 @@ c_char_p_from_param(PyObject *type, PyObject *value)
static PyObject *
c_void_p_from_param(PyObject *type, PyObject *value)
{
_Py_IDENTIFIER(_as_parameter_);
StgDictObject *stgd;
PyObject *as_parameter;
int res;
@ -1915,7 +1905,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
}
}
if (_PyObject_LookupAttrId(value, &PyId__as_parameter_, &as_parameter) < 0) {
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
@ -2038,7 +2028,6 @@ PyCSimpleType_paramfunc(CDataObject *self)
static PyObject *
PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
_Py_IDENTIFIER(_type_);
PyTypeObject *result;
StgDictObject *stgdict;
PyObject *proto;
@ -2053,7 +2042,7 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (result == NULL)
return NULL;
if (_PyObject_LookupAttrId((PyObject *)result, &PyId__type_, &proto) < 0) {
if (_PyObject_LookupAttr((PyObject *)result, &_Py_ID(_type_), &proto) < 0) {
return NULL;
}
if (!proto) {
@ -2223,7 +2212,6 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject *
PyCSimpleType_from_param(PyObject *type, PyObject *value)
{
_Py_IDENTIFIER(_as_parameter_);
StgDictObject *dict;
const char *fmt;
PyCArgObject *parg;
@ -2267,7 +2255,7 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
PyErr_Clear();
Py_DECREF(parg);
if (_PyObject_LookupAttrId(value, &PyId__as_parameter_, &as_parameter) < 0) {
if (_PyObject_LookupAttr(value, &_Py_ID(_as_parameter_), &as_parameter) < 0) {
return NULL;
}
if (as_parameter) {
@ -2344,7 +2332,6 @@ PyTypeObject PyCSimpleType_Type = {
static PyObject *
converters_from_argtypes(PyObject *ob)
{
_Py_IDENTIFIER(from_param);
PyObject *converters;
Py_ssize_t i;
@ -2424,7 +2411,7 @@ converters_from_argtypes(PyObject *ob)
}
*/
if (_PyObject_LookupAttrId(tp, &PyId_from_param, &cnv) <= 0) {
if (_PyObject_LookupAttr(tp, &_Py_ID(from_param), &cnv) <= 0) {
Py_DECREF(converters);
Py_DECREF(ob);
if (!PyErr_Occurred()) {
@ -2445,10 +2432,6 @@ make_funcptrtype_dict(StgDictObject *stgdict)
{
PyObject *ob;
PyObject *converters = NULL;
_Py_IDENTIFIER(_flags_);
_Py_IDENTIFIER(_argtypes_);
_Py_IDENTIFIER(_restype_);
_Py_IDENTIFIER(_check_retval_);
stgdict->align = _ctypes_get_fielddesc("P")->pffi_type->alignment;
stgdict->length = 1;
@ -2457,7 +2440,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
stgdict->getfunc = NULL;
stgdict->ffi_type_pointer = ffi_type_pointer;
ob = _PyDict_GetItemIdWithError((PyObject *)stgdict, &PyId__flags_);
ob = PyDict_GetItemWithError((PyObject *)stgdict, &_Py_ID(_flags_));
if (!ob || !PyLong_Check(ob)) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError,
@ -2468,7 +2451,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
stgdict->flags = PyLong_AsUnsignedLongMask(ob) | TYPEFLAG_ISPOINTER;
/* _argtypes_ is optional... */
ob = _PyDict_GetItemIdWithError((PyObject *)stgdict, &PyId__argtypes_);
ob = PyDict_GetItemWithError((PyObject *)stgdict, &_Py_ID(_argtypes_));
if (ob) {
converters = converters_from_argtypes(ob);
if (!converters)
@ -2481,7 +2464,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
return -1;
}
ob = _PyDict_GetItemIdWithError((PyObject *)stgdict, &PyId__restype_);
ob = PyDict_GetItemWithError((PyObject *)stgdict, &_Py_ID(_restype_));
if (ob) {
if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) {
PyErr_SetString(PyExc_TypeError,
@ -2490,7 +2473,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
}
Py_INCREF(ob);
stgdict->restype = ob;
if (_PyObject_LookupAttrId(ob, &PyId__check_retval_,
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_),
&stgdict->checker) < 0)
{
return -1;
@ -3254,7 +3237,6 @@ PyCFuncPtr_get_errcheck(PyCFuncPtrObject *self, void *Py_UNUSED(ignored))
static int
PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(_check_retval_);
PyObject *checker, *oldchecker;
if (ob == NULL) {
oldchecker = self->checker;
@ -3268,7 +3250,7 @@ PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob, void *Py_UNUSED(ign
"restype must be a type, a callable, or None");
return -1;
}
if (_PyObject_LookupAttrId(ob, &PyId__check_retval_, &checker) < 0) {
if (_PyObject_LookupAttr(ob, &_Py_ID(_check_retval_), &checker) < 0) {
return -1;
}
oldchecker = self->checker;
@ -4062,10 +4044,9 @@ _build_result(PyObject *result, PyObject *callargs,
PyTuple_SET_ITEM(tup, index, v);
index++;
} else if (bit & outmask) {
_Py_IDENTIFIER(__ctypes_from_outparam__);
v = PyTuple_GET_ITEM(callargs, i);
v = _PyObject_CallMethodIdNoArgs(v, &PyId___ctypes_from_outparam__);
v = PyObject_CallMethodNoArgs(v, &_Py_ID(__ctypes_from_outparam__));
if (v == NULL || numretvals == 1) {
Py_DECREF(callargs);
return v;
@ -4348,7 +4329,6 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
StgDictObject *dict;
PyObject *fields;
Py_ssize_t i;
_Py_IDENTIFIER(_fields_);
if (PyType_stgdict((PyObject *)type->tp_base)) {
index = _init_pos_args(self, type->tp_base,
@ -4359,7 +4339,7 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
}
dict = PyType_stgdict((PyObject *)type);
fields = _PyDict_GetItemIdWithError((PyObject *)dict, &PyId__fields_);
fields = PyDict_GetItemWithError((PyObject *)dict, &_Py_ID(_fields_));
if (fields == NULL) {
if (PyErr_Occurred()) {
return -1;

View File

@ -1,7 +1,6 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
// windows.h must be included before pycore internal headers
@ -10,6 +9,7 @@
#endif
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_runtime_init.h" // _Py_ID()
#include <stdbool.h>
@ -125,9 +125,7 @@ static void
TryAddRef(StgDictObject *dict, CDataObject *obj)
{
IUnknown *punk;
_Py_IDENTIFIER(_needs_com_addref_);
int r = _PyDict_ContainsId((PyObject *)dict, &PyId__needs_com_addref_);
int r = PyDict_Contains((PyObject *)dict, &_Py_ID(_needs_com_addref_));
if (r <= 0) {
if (r < 0) {
PrintError("getting _needs_com_addref_");

View File

@ -57,7 +57,6 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
@ -97,6 +96,8 @@
#define DONT_USE_SEH
#endif
#include "pycore_runtime_init.h"
#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
static void pymem_destructor(PyObject *ptr)
@ -719,9 +720,8 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
}
{
_Py_IDENTIFIER(_as_parameter_);
PyObject *arg;
if (_PyObject_LookupAttrId(obj, &PyId__as_parameter_, &arg) < 0) {
if (_PyObject_LookupAttr(obj, &_Py_ID(_as_parameter_), &arg) < 0) {
return -1;
}
/* Which types should we exactly allow here?
@ -1848,16 +1848,14 @@ static PyObject *
unpickle(PyObject *self, PyObject *args)
{
PyObject *typ, *state, *meth, *obj, *result;
_Py_IDENTIFIER(__new__);
_Py_IDENTIFIER(__setstate__);
if (!PyArg_ParseTuple(args, "OO!", &typ, &PyTuple_Type, &state))
return NULL;
obj = _PyObject_CallMethodIdOneArg(typ, &PyId___new__, typ);
obj = PyObject_CallMethodOneArg(typ, &_Py_ID(__new__), typ);
if (obj == NULL)
return NULL;
meth = _PyObject_GetAttrId(obj, &PyId___setstate__);
meth = PyObject_GetAttr(obj, &_Py_ID(__setstate__));
if (meth == NULL) {
goto error;
}

View File

@ -1,7 +1,6 @@
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
// windows.h must be included before pycore internal headers
@ -291,12 +290,11 @@ MakeFields(PyObject *type, CFieldObject *descr,
static int
MakeAnonFields(PyObject *type)
{
_Py_IDENTIFIER(_anonymous_);
PyObject *anon;
PyObject *anon_names;
Py_ssize_t i;
if (_PyObject_LookupAttrId(type, &PyId__anonymous_, &anon) < 0) {
if (_PyObject_LookupAttr(type, &_Py_ID(_anonymous_), &anon) < 0) {
return -1;
}
if (anon == NULL) {
@ -347,9 +345,6 @@ MakeAnonFields(PyObject *type)
int
PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
{
_Py_IDENTIFIER(_swappedbytes_);
_Py_IDENTIFIER(_use_broken_old_ctypes_structure_semantics_);
_Py_IDENTIFIER(_pack_);
StgDictObject *stgdict, *basedict;
Py_ssize_t len, offset, size, align, i;
Py_ssize_t union_size, total_align;
@ -373,7 +368,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
if (fields == NULL)
return 0;
if (_PyObject_LookupAttrId(type, &PyId__swappedbytes_, &tmp) < 0) {
if (_PyObject_LookupAttr(type, &_Py_ID(_swappedbytes_), &tmp) < 0) {
return -1;
}
if (tmp) {
@ -384,8 +379,8 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
big_endian = PY_BIG_ENDIAN;
}
if (_PyObject_LookupAttrId(type,
&PyId__use_broken_old_ctypes_structure_semantics_, &tmp) < 0)
if (_PyObject_LookupAttr(type,
&_Py_ID(_use_broken_old_ctypes_structure_semantics_), &tmp) < 0)
{
return -1;
}
@ -397,7 +392,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
use_broken_old_ctypes_semantics = 0;
}
if (_PyObject_LookupAttrId(type, &PyId__pack_, &tmp) < 0) {
if (_PyObject_LookupAttr(type, &_Py_ID(_pack_), &tmp) < 0) {
return -1;
}
if (tmp) {