Skip to content
Closed
Prev Previous commit
Next Next commit
Move local _Py_IDENTIFER to global for modules.
  • Loading branch information
ericsnowcurrently committed May 17, 2019
commit b1afab175476f34e36d8a6e11059694246394584
38 changes: 15 additions & 23 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ _Py_IDENTIFIER(current_task);
_Py_IDENTIFIER(get_event_loop);
_Py_IDENTIFIER(send);
_Py_IDENTIFIER(throw);
_Py_IDENTIFIER(get_loop);
_Py_IDENTIFIER(_loop);
_Py_IDENTIFIER(get_debug);
_Py_IDENTIFIER(PENDING);
_Py_IDENTIFIER(CANCELLED);
_Py_IDENTIFIER(FINISHED);
_Py_IDENTIFIER(_repr_info);
_Py_IDENTIFIER(call_exception_handler);
_Py_IDENTIFIER(message);
_Py_IDENTIFIER(exception);
_Py_IDENTIFIER(future);
_Py_IDENTIFIER(source_traceback);
_Py_IDENTIFIER(add);
_Py_IDENTIFIER(discard);
_Py_IDENTIFIER(task);


/* State of the _asyncio module */
Expand Down Expand Up @@ -202,8 +217,6 @@ get_future_loop(PyObject *fut)
{
/* Implementation of `asyncio.futures._get_loop` */

_Py_IDENTIFIER(get_loop);
_Py_IDENTIFIER(_loop);
PyObject *getloop;

if (Future_CheckExact(fut) || Task_CheckExact(fut)) {
Expand Down Expand Up @@ -469,7 +482,6 @@ future_init(FutureObj *fut, PyObject *loop)
{
PyObject *res;
int is_true;
_Py_IDENTIFIER(get_debug);

// Same to FutureObj_clear() but not clearing fut->dict
Py_CLEAR(fut->fut_loop);
Expand Down Expand Up @@ -1255,9 +1267,6 @@ FutureObj_get_source_traceback(FutureObj *fut, void *Py_UNUSED(ignored))
static PyObject *
FutureObj_get_state(FutureObj *fut, void *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(PENDING);
_Py_IDENTIFIER(CANCELLED);
_Py_IDENTIFIER(FINISHED);
PyObject *ret = NULL;

ENSURE_FUTURE_ALIVE(fut)
Expand Down Expand Up @@ -1294,8 +1303,6 @@ _asyncio_Future__repr_info_impl(FutureObj *self)
static PyObject *
FutureObj_repr(FutureObj *fut)
{
_Py_IDENTIFIER(_repr_info);

ENSURE_FUTURE_ALIVE(fut)

PyObject *rinfo = _PyObject_CallMethodIdObjArgs((PyObject*)fut,
Expand All @@ -1320,12 +1327,6 @@ FutureObj_repr(FutureObj *fut)
static void
FutureObj_finalize(FutureObj *fut)
{
_Py_IDENTIFIER(call_exception_handler);
_Py_IDENTIFIER(message);
_Py_IDENTIFIER(exception);
_Py_IDENTIFIER(future);
_Py_IDENTIFIER(source_traceback);

PyObject *error_type, *error_value, *error_traceback;
PyObject *context;
PyObject *message = NULL;
Expand Down Expand Up @@ -1845,8 +1846,6 @@ TaskWakeupMethWrapper_new(TaskObj *task)
static int
register_task(PyObject *task)
{
_Py_IDENTIFIER(add);

PyObject *res = _PyObject_CallMethodIdObjArgs(
all_tasks, &PyId_add, task, NULL);
if (res == NULL) {
Expand All @@ -1860,8 +1859,6 @@ register_task(PyObject *task)
static int
unregister_task(PyObject *task)
{
_Py_IDENTIFIER(discard);

PyObject *res = _PyObject_CallMethodIdObjArgs(
all_tasks, &PyId_discard, task, NULL);
if (res == NULL) {
Expand Down Expand Up @@ -2358,11 +2355,6 @@ _asyncio_Task_set_name(TaskObj *self, PyObject *value)
static void
TaskObj_finalize(TaskObj *task)
{
_Py_IDENTIFIER(call_exception_handler);
_Py_IDENTIFIER(task);
_Py_IDENTIFIER(message);
_Py_IDENTIFIER(source_traceback);

PyObject *context;
PyObject *message = NULL;
PyObject *func;
Expand Down
10 changes: 6 additions & 4 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#include <sys/types.h> /* For size_t */
#endif


_Py_IDENTIFIER(__dict__);
_Py_IDENTIFIER(items);
_Py_IDENTIFIER(get);
_Py_IDENTIFIER(__setitem__);

/*[clinic input]
class _tuplegetter "_tuplegetterobject *" "&tuplegetter_type"
[clinic start generated code]*/
Expand Down Expand Up @@ -1321,7 +1327,6 @@ static PyObject *
deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *dict, *it;
_Py_IDENTIFIER(__dict__);

if (_PyObject_LookupAttrId((PyObject *)deque, &PyId___dict__, &dict) < 0) {
return NULL;
Expand Down Expand Up @@ -2031,7 +2036,6 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored))
PyObject *items;
PyObject *iter;
PyObject *result;
_Py_IDENTIFIER(items);

if (dd->default_factory == NULL || dd->default_factory == Py_None)
args = PyTuple_New(0);
Expand Down Expand Up @@ -2236,8 +2240,6 @@ Count elements in the iterable, updating the mapping");
static PyObject *
_count_elements(PyObject *self, PyObject *args)
{
_Py_IDENTIFIER(get);
_Py_IDENTIFIER(__setitem__);
PyObject *it, *iterable, *mapping, *oldval;
PyObject *newval = NULL;
PyObject *key = NULL;
Expand Down
3 changes: 2 additions & 1 deletion Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module instead.
#include <stdbool.h>


_Py_IDENTIFIER(write);

typedef struct {
PyObject *error_obj; /* CSV exception */
PyObject *dialects; /* Dialect registry */
Expand Down Expand Up @@ -1365,7 +1367,6 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
{
PyObject * output_file, * dialect = NULL;
WriterObj * self = PyObject_GC_New(WriterObj, &Writer_Type);
_Py_IDENTIFIER(write);

if (!self)
return NULL;
Expand Down
33 changes: 13 additions & 20 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ bytes(cdata)
#endif
#include "ctypes.h"


_Py_IDENTIFIER(_abstract_);
_Py_IDENTIFIER(_fields_);
_Py_IDENTIFIER(_as_parameter_);
_Py_IDENTIFIER(_type_);
_Py_IDENTIFIER(_length_);
_Py_IDENTIFIER(from_param);
_Py_IDENTIFIER(_flags_);
_Py_IDENTIFIER(_argtypes_);
_Py_IDENTIFIER(_restype_);
_Py_IDENTIFIER(_check_retval_);
_Py_IDENTIFIER(__ctypes_from_outparam__);

PyObject *PyExc_ArgError = NULL;

/* This dict maps ctypes types to POINTER types */
Expand Down Expand Up @@ -441,8 +454,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!) */
Expand Down Expand Up @@ -721,7 +732,6 @@ static const char 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)
Expand Down Expand Up @@ -992,7 +1002,6 @@ PyCPointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
StgDictObject *stgdict;
PyObject *proto;
PyObject *typedict;
_Py_IDENTIFIER(_type_);

typedict = PyTuple_GetItem(args, 2);
if (!typedict)
Expand Down Expand Up @@ -1070,7 +1079,6 @@ static PyObject *
PyCPointerType_set_type(PyTypeObject *self, PyObject *type)
{
StgDictObject *dict;
_Py_IDENTIFIER(_type_);

dict = PyType_stgdict((PyObject *)self);
if (!dict) {
Expand Down Expand Up @@ -1427,8 +1435,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;
Expand Down Expand Up @@ -1626,7 +1632,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) {
Expand Down Expand Up @@ -1693,7 +1698,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) {
Expand Down Expand Up @@ -1760,7 +1764,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;
Expand Down Expand Up @@ -2007,7 +2010,6 @@ PyCSimpleType_paramfunc(CDataObject *self)
static PyObject *
PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
_Py_IDENTIFIER(_type_);
PyTypeObject *result;
StgDictObject *stgdict;
PyObject *proto;
Expand Down Expand Up @@ -2192,7 +2194,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;
Expand Down Expand Up @@ -2313,7 +2314,6 @@ PyTypeObject PyCSimpleType_Type = {
static PyObject *
converters_from_argtypes(PyObject *ob)
{
_Py_IDENTIFIER(from_param);
PyObject *converters;
Py_ssize_t i;
Py_ssize_t nArgs;
Expand Down Expand Up @@ -2361,10 +2361,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;
Expand Down Expand Up @@ -3166,7 +3162,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;
Expand Down Expand Up @@ -3957,7 +3952,6 @@ _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_CallMethodId(v, &PyId___ctypes_from_outparam__, NULL);
Expand Down Expand Up @@ -4243,7 +4237,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,
Expand Down
6 changes: 5 additions & 1 deletion Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
#endif
#include "ctypes.h"


#ifdef MS_WIN32
_Py_IDENTIFIER(_needs_com_addref_);
#endif

/**************************************************************/

static void
Expand Down Expand Up @@ -107,7 +112,6 @@ static void
TryAddRef(StgDictObject *dict, CDataObject *obj)
{
IUnknown *punk;
_Py_IDENTIFIER(_needs_com_addref_);

if (!_PyDict_GetItemIdWithError((PyObject *)dict, &PyId__needs_com_addref_)) {
if (PyErr_Occurred()) {
Expand Down
8 changes: 5 additions & 3 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
#include <sanitizer/msan_interface.h>
#endif


_Py_IDENTIFIER(_as_parameter_);
_Py_IDENTIFIER(__new__);
_Py_IDENTIFIER(__setstate__);

#if defined(_DEBUG) || defined(__MINGW32__)
/* Don't use structured exception handling on Windows if this is defined.
MingW, AFAIK, doesn't support it.
Expand Down Expand Up @@ -707,7 +712,6 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
#endif

{
_Py_IDENTIFIER(_as_parameter_);
PyObject *arg;
if (_PyObject_LookupAttrId(obj, &PyId__as_parameter_, &arg) < 0) {
return -1;
Expand Down Expand Up @@ -1688,8 +1692,6 @@ 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;
Expand Down
10 changes: 6 additions & 4 deletions Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#endif
#include "ctypes.h"


_Py_IDENTIFIER(_anonymous_);
_Py_IDENTIFIER(_swappedbytes_);
_Py_IDENTIFIER(_use_broken_old_ctypes_structure_semantics_);
_Py_IDENTIFIER(_pack_);

/******************************************************************/
/*
StdDict - a dictionary subclass, containing additional C accessible fields
Expand Down Expand Up @@ -281,7 +287,6 @@ MakeFields(PyObject *type, CFieldObject *descr,
static int
MakeAnonFields(PyObject *type)
{
_Py_IDENTIFIER(_anonymous_);
PyObject *anon;
PyObject *anon_names;
Py_ssize_t i;
Expand Down Expand Up @@ -337,9 +342,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;
Expand Down
Loading