Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-46541: Remove usage of _Py_IDENTIFIER from pyexpat #31468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Modules/pyexpat.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define NEEDS_PY_IDENTIFIER

#include "Python.h"
#include <ctype.h>

Expand Down Expand Up @@ -52,6 +50,7 @@ enum HandlerTypes {
typedef struct {
PyTypeObject *xml_parse_type;
PyObject *error;
PyObject *str_read;
} pyexpat_state;

static inline pyexpat_state*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down