From bd8fe66ed3b81622707ccfa8ac790686977242b4 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 21 Feb 2022 23:10:46 +0900 Subject: [PATCH 1/2] bpo-46541: Remove usage of _Py_IDENTIFIER from pyexpat --- Modules/pyexpat.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index f224f91f38fc3c..8741834ef7b4db 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -52,6 +52,7 @@ enum HandlerTypes { typedef struct { PyTypeObject *xml_parse_type; PyObject *error; + PyObject *str_read; } pyexpat_state; static inline pyexpat_state* @@ -824,11 +825,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 +1898,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 +2038,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 +2048,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; } From b941331d8652616fc036e3ac717445bf5b579c2e Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 21 Feb 2022 23:18:26 +0900 Subject: [PATCH 2/2] bpo-46541: Address code review --- Modules/pyexpat.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 8741834ef7b4db..7a26fe24e7592d 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1,5 +1,3 @@ -#define NEEDS_PY_IDENTIFIER - #include "Python.h" #include