8000 bpo-46541: Remove usage of _Py_IDENTIFIER from array module · python/cpython@8573510 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8573510

Browse files
committed
bpo-46541: Remove usage of _Py_IDENTIFIER from array module
1 parent b207711 commit 8573510

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct _Py_global_strings {
194194
STRUCT_FOR_ID(__weakref__)
195195
STRUCT_FOR_ID(__xor__)
196196
STRUCT_FOR_ID(_abc_impl)
197+
STRUCT_FOR_ID(_array_reconstructor)
197198
STRUCT_FOR_ID(_blksize)
198199
STRUCT_FOR_ID(_dealloc_warn)
199200
STRUCT_FOR_ID(_finalizing)

Include/internal/pycore_runtime_init.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ extern "C" {
809809
INIT_ID(__weakref__), \
810810
INIT_ID(__xor__), \
811811
INIT_ID(_abc_impl), \
812+
INIT_ID(_array_reconstructor), \
812813
INIT_ID(_blksize), \
813814
INIT_ID(_dealloc_warn), \
814815
INIT_ID(_finalizing), \

Modules/arraymodule.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#ifndef Py_BUILD_CORE_BUILTIN
77
# define Py_BUILD_CORE_MODULE 1
88
#endif
9-
#define NEEDS_PY_IDENTIFIER
109

1110
#define PY_SSIZE_T_CLEAN
1211
#include "Python.h"
1312
#include "pycore_floatobject.h" // _PyFloat_Unpack4()
1413
#include "pycore_moduleobject.h" // _PyModule_GetState()
14+
#include "pycore_runtime.h" // _Py_ID()
1515
#include "structmember.h" // PyMemberDef
1616
#include <stddef.h> // offsetof()
1717
#include <stddef.h>
@@ -1478,7 +1478,6 @@ array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n)
14781478
PyObject *b, *res;
14791479
Py_ssize_t itemsize = self->ob_descr->itemsize;
14801480
Py_ssize_t nbytes;
1481-
_Py_IDENTIFIER(read);
14821481
int not_enough_bytes;
14831482

14841483
if (n < 0) {
@@ -1491,7 +1490,7 @@ array_array_fromfile_impl(arrayobject *self, PyObject *f, Py_ssize_t n)
14911490
}
14921491
nbytes = n * itemsize;
14931492

1494-
b = _PyObject_CallMethodId(f, &PyId_read, "n", nbytes);
1493+
b = _PyObject_CallMethod(f, &_Py_ID(read), "n", nbytes);
14951494
if (b == NULL)
14961495
return NULL;
14971496

@@ -1546,14 +1545,13 @@ array_array_tofile(arrayobject *self, PyObject *f)
15461545
char* ptr = self->ob_item + i*BLOCKSIZE;
15471546
Py_ssize_t size = BLOCKSIZE;
15481547
PyObject *bytes, *res;
1549-
_Py_IDENTIFIER(write);
15501548

15511549
if (i*BLOCKSIZE + size > nbytes)
15521550
size = nbytes - i*BLOCKSIZE;
15531551
bytes = PyBytes_FromStringAndSize(ptr, size);
15541552
if (bytes == NULL)
15551553
return NULL;
1556-
res = _PyObject_CallMethodIdOneArg(f, &PyId_write, bytes);
1554+
res = PyObject_CallMethodOneArg(f, &_Py_ID(write), bytes);
15571555
Py_DECREF(bytes);
15581556
if (res == NULL)
15591557
return NULL;
@@ -2193,16 +2191,14 @@ array_array___reduce_ex__(arrayobject *self, PyObject *value)
21932191
int mformat_code;
21942192
static PyObject *array_reconstructor = NULL;
21952193
long protocol;
2196-
_Py_IDENTIFIER(_array_reconstructor);
2197-
_Py_IDENTIFIER(__dict__);
21982194

21992195
if (array_reconstructor == NULL) {
22002196
PyObject *array_module = PyImport_ImportModule("array");
22012197
if (array_module == NULL)
22022198
return NULL;
2203-
array_reconstructor = _PyObject_GetAttrId(
2199+
array_reconstructor = PyObject_GetAttr(
22042200
array_module,
2205-
&PyId__array_reconstructor);
2201+
&_Py_ID(_array_reconstructor));
22062202
Py_DECREF(array_module);
22072203
if (array_reconstructor == NULL)
22082204
return NULL;
@@ -2217,7 +2213,7 @@ array_array___reduce_ex__(arrayobject *self, PyObject *value)
22172213
if (protocol == -1 && PyErr_Occurred())
22182214
return NULL;
22192215

2220-
if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) {
2216+
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(__dict__), &dict) < 0) {
22212217
return NULL;
22222218
}
22232219
if (dict == NULL) {
@@ -2946,8 +2942,7 @@ static PyObject *
29462942
array_arrayiterator___reduce___impl(arrayiterobject *self)
29472943
/*[clinic end generated code: output=7898a52e8e66e016 input=a062ea1e9951417a]*/
29482944
{
2949-
_Py_IDENTIFIER(iter);
2950-
PyObject *func = _PyEval_GetBuiltinId(&PyId_iter);
2945+
PyObject *func = _PyEval_GetBuiltin(&_Py_ID(iter));
29512946
if (self->ao == NULL) {
29522947
return Py_BuildValue("N(())", func);
29532948
}

0 commit comments

Comments
 (0)
0