1- #define NEEDS_PY_IDENTIFIER
2-
31#include "Python.h"
42#include <ctype.h>
53
@@ -52,6 +50,7 @@ enum HandlerTypes {
5250typedef struct {
5351 PyTypeObject * xml_parse_type ;
5452 PyObject * error ;
53+ PyObject * str_read ;
5554} pyexpat_state ;
5655
5756static inline pyexpat_state *
@@ -824,11 +823,10 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
824823{
825824 int rv = 1 ;
826825 PyObject * readmethod = NULL ;
827- _Py_IDENTIFIER (read );
828826
829827 pyexpat_state * state = PyType_GetModuleState (cls );
830828
831- if (_PyObject_LookupAttrId (file , & PyId_read , & readmethod ) < 0 ) {
829+ if (_PyObject_LookupAttr (file , state -> str_read , & readmethod ) < 0 ) {
832830 return NULL ;
833831 }
834832 if (readmethod == NULL ) {
@@ -1898,6 +1896,10 @@ static int
18981896pyexpat_exec (PyObject * mod )
18991897{
19001898 pyexpat_state * state = pyexpat_get_state (mod );
1899+ state -> str_read = PyUnicode_InternFromString ("read" );
1900+ if (state -> str_read == NULL ) {
1901+ return -1 ;
1902+ }
19011903 state -> xml_parse_type = (PyTypeObject * )PyType_FromModuleAndSpec (
19021904 mod , & _xml_parse_type_spec , NULL );
19031905
@@ -2034,6 +2036,7 @@ pyexpat_traverse(PyObject *module, visitproc visit, void *arg)
20342036 pyexpat_state * state = pyexpat_get_state (module );
20352037 Py_VISIT (state -> xml_parse_type );
20362038 Py_VISIT (state -> error );
2039+ Py_VISIT (state -> str_read );
20372040 return 0 ;
20382041}
20392042
@@ -2043,6 +2046,7 @@ pyexpat_clear(PyObject *module)
20432046 pyexpat_state * state = pyexpat_get_state (module );
20442047 Py_CLEAR (state -> xml_parse_type );
20452048 Py_CLEAR (state -> error );
2049+ Py_CLEAR (state -> str_read );
20462050 return 0 ;
20472051}
20482052
0 commit comments