diff options
author | Dong-hee Na <donghee.na@python.org> | 2022-02-21 14:46:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 14:46:52 (GMT) |
commit | 2b86616456629e11de33629da1bb732f033c436e (patch) | |
tree | e68168e6f724803d392d9007128ee87d07368e41 | |
parent | 195a46d6ffd4cec6c5fb69c5890f8b1758ac91ca (diff) | |
download | cpython-2b86616456629e11de33629da1bb732f033c436e.zip cpython-2b86616456629e11de33629da1bb732f033c436e.tar.gz cpython-2b86616456629e11de33629da1bb732f033c436e.tar.bz2 |
bpo-46541: Remove usage of _Py_IDENTIFIER from pyexpat (GH-31468)
-rw-r--r-- | Modules/pyexpat.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index f224f91..7a26fe2 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1,5 +1,3 @@ -#define NEEDS_PY_IDENTIFIER - #include "Python.h" #include <ctype.h> @@ -52,6 +50,7 @@ enum HandlerTypes { typedef struct { PyTypeObject *xml_parse_type; PyObject *error; + PyObject *str_read; } pyexpat_state; static inline pyexpat_state* @@ -824,11 +823,10 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls, { int rv = 1; PyObject *readmethod = NULL; - _Py_IDENTIFIER(read); pyexpat_state *state = PyType_GetModuleState(cls); - if (_PyObject_LookupAttrId(file, &PyId_read, &readmethod) < 0) { + if (_PyObject_LookupAttr(file, state->str_read, &readmethod) < 0) { return NULL; } if (readmethod == NULL) { @@ -1898,6 +1896,10 @@ static int pyexpat_exec(PyObject *mod) { pyexpat_state *state = pyexpat_get_state(mod); + state->str_read = PyUnicode_InternFromString("read"); + if (state->str_read == NULL) { + return -1; + } state->xml_parse_type = (PyTypeObject *)PyType_FromModuleAndSpec( mod, &_xml_parse_type_spec, NULL); @@ -2034,6 +2036,7 @@ pyexpat_traverse(PyObject *module, visitproc visit, void *arg) pyexpat_state *state = pyexpat_get_state(module); Py_VISIT(state->xml_parse_type); Py_VISIT(state->error); + Py_VISIT(state->str_read); return 0; } @@ -2043,6 +2046,7 @@ pyexpat_clear(PyObject *module) pyexpat_state *state = pyexpat_get_state(module); Py_CLEAR(state->xml_parse_type); Py_CLEAR(state->error); + Py_CLEAR(state->str_read); return 0; } |