1
- #define NEEDS_PY_IDENTIFIER
2
-
3
1
#include "Python.h"
4
2
#include <ctype.h>
5
3
@@ -52,6 +50,7 @@ enum HandlerTypes {
52
50
typedef struct {
53
51
PyTypeObject * xml_parse_type ;
54
52
PyObject * error ;
53
+ PyObject * str_read ;
55
54
} pyexpat_state ;
56
55
57
56
static inline pyexpat_state *
@@ -824,11 +823,10 @@ pyexpat_xmlparser_ParseFile_impl(xmlparseobject *self, PyTypeObject *cls,
824
823
{
825
824
int rv = 1 ;
826
825
PyObject * readmethod = NULL ;
827
- _Py_IDENTIFIER (read );
828
826
829
827
pyexpat_state * state = PyType_GetModuleState (cls );
830
828
831
- if (_PyObject_LookupAttrId (file , & PyId_read , & readmethod ) < 0 ) {
829
+ if (_PyObject_LookupAttr (file , state -> str_read , & readmethod ) < 0 ) {
832
830
return NULL ;
833
831
}
834
832
if (readmethod == NULL ) {
@@ -1898,6 +1896,10 @@ static int
1898
1896
pyexpat_exec (PyObject * mod )
1899
1897
{
1900
1898
pyexpat_state * state = pyexpat_get_state (mod );
1899
+ state -> str_read = PyUnicode_InternFromString ("read" );
1900
+ if (state -> str_read == NULL ) {
1901
+ return -1 ;
1902
+ }
1901
1903
state -> xml_parse_type = (PyTypeObject * )PyType_FromModuleAndSpec (
1902
1904
mod , & _xml_parse_type_spec , NULL );
1903
1905
@@ -2034,6 +2036,7 @@ pyexpat_traverse(PyObject *module, visitproc visit, void *arg)
2034
2036
pyexpat_state * state = pyexpat_get_state (module );
2035
2037
Py_VISIT (state -> xml_parse_type );
2036
2038
Py_VISIT (state -> error );
2039
+ Py_VISIT (state -> str_read );
2037
2040
return 0 ;
2038
2041
}
2039
2042
@@ -2043,6 +2046,7 @@ pyexpat_clear(PyObject *module)
2043
2046
pyexpat_state * state = pyexpat_get_state (module );
2044
2047
Py_CLEAR (state -> xml_parse_type );
2045
2048
Py_CLEAR (state -> error );
2049
+ Py_CLEAR (state -> str_read );
2046
2050
return 0 ;
2047
2051
}
2048
2052
0 commit comments