@@ -54,6 +54,7 @@ enum HandlerTypes {
5454typedef  struct  {
5555    PyTypeObject  * xml_parse_type ;
5656    PyObject  * error ;
57+     PyObject  * str_code ;
5758} pyexpat_state ;
5859
5960static  inline  pyexpat_state * 
@@ -107,13 +108,11 @@ struct HandlerInfo {
107108static  struct  HandlerInfo  handler_info [64 ];
108109
109110static  int 
110- set_xml_error_attr_code (PyObject  * err , enum  XML_Error  code )
111+ set_xml_error_attr_code (pyexpat_state   * state ,  PyObject  * err , enum  XML_Error  code )
111112{
112-     PyObject  * py_id_code  =  PyUnicode_InternFromString ("code" );
113113    PyObject  * v  =  PyLong_FromLong ((long )code );
114-     int  ok  =  v  !=  NULL  &&  PyObject_SetAttr (err , py_id_code , v ) !=  -1 ;
114+     int  ok  =  v  !=  NULL  &&  PyObject_SetAttr (err , state -> str_code , v ) !=  -1 ;
115115    Py_XDECREF (v );
116-     Py_XDECREF (py_id_code );
117116    return  ok ;
118117}
119118
@@ -153,7 +152,7 @@ set_xml_error(pyexpat_state *state,
153152    Py_DECREF (arg );
154153    if  (
155154        res  !=  NULL 
156-         &&  set_xml_error_attr_code (res , code )
155+         &&  set_xml_error_attr_code (state ,  res , code )
157156        &&  set_xml_error_attr_location (res , "lineno" , lineno )
158157        &&  set_xml_error_attr_location (res , "offset" , column )
159158    ) {
@@ -2061,6 +2060,11 @@ pyexpat_exec(PyObject *mod)
20612060        return  -1 ;
20622061    }
20632062
2063+     state -> str_code  =  PyUnicode_InternFromString ("code" );
2064+     if  (state -> str_code  ==  NULL ) {
2065+         return  -1 ;
2066+     }
2067+ 
20642068    /* Add some symbolic constants to the module */ 
20652069
20662070    if  (PyModule_AddObjectRef (mod , "error" , state -> error ) <  0 ) {
@@ -2196,6 +2200,7 @@ pyexpat_clear(PyObject *module)
21962200    pyexpat_state  * state  =  pyexpat_get_state (module );
21972201    Py_CLEAR (state -> xml_parse_type );
21982202    Py_CLEAR (state -> error );
2203+     Py_CLEAR (state -> str_code );
21992204    return  0 ;
22002205}
22012206
0 commit comments