@@ -1843,13 +1843,6 @@ add_features(PyObject *mod)
1843
1843
}
1844
1844
#endif
1845
1845
1846
- static void
1847
- pyexpat_destructor (PyObject * op )
1848
- {
1849
- void * p = PyCapsule_GetPointer (op , PyExpat_CAPSULE_NAME );
1850
- PyMem_Free (p );
1851
- }
1852
-
1853
1846
static int
1854
1847
pyexpat_exec (PyObject * mod )
1855
1848
{
@@ -1933,46 +1926,40 @@ pyexpat_exec(PyObject *mod)
1933
1926
MYCONST (XML_PARAM_ENTITY_PARSING_ALWAYS );
1934
1927
#undef MYCONST
1935
1928
1936
- struct PyExpat_CAPI * capi = PyMem_Calloc (1 , sizeof (struct PyExpat_CAPI ));
1937
- if (capi == NULL ) {
1938
- PyErr_NoMemory ();
1939
- return -1 ;
1940
- }
1929
+ static struct PyExpat_CAPI capi ;
1941
1930
/* initialize pyexpat dispatch table */
1942
- capi -> size = sizeof (* capi );
1943
- capi -> magic = PyExpat_CAPI_MAGIC ;
1944
- capi -> MAJOR_VERSION = XML_MAJOR_VERSION ;
1945
- capi -> MINOR_VERSION = XML_MINOR_VERSION ;
1946
- capi -> MICRO_VERSION = XML_MICRO_VERSION ;
1947
- capi -> ErrorString = XML_ErrorString ;
1948
- capi -> GetErrorCode = XML_GetErrorCode ;
1949
- capi -> GetErrorColumnNumber = XML_GetErrorColumnNumber ;
1950
- capi -> GetErrorLineNumber = XML_GetErrorLineNumber ;
1951
- capi -> Parse = XML_Parse ;
1952
- capi -> ParserCreate_MM = XML_ParserCreate_MM ;
1953
- capi -> ParserFree = XML_ParserFree ;
1954
- capi -> SetCharacterDataHandler = XML_SetCharacterDataHandler ;
1955
- capi -> SetCommentHandler = XML_SetCommentHandler ;
1956
- capi -> SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand ;
1957
- capi -> SetElementHandler = XML_SetElementHandler ;
1958
- capi -> SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler ;
1959
- capi -> SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler ;
1960
- capi -> SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler ;
1961
- capi -> SetUserData = XML_SetUserData ;
1962
- capi -> SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler ;
1963
- capi -> SetEncoding = XML_SetEncoding ;
1964
- capi -> DefaultUnknownEncodingHandler = PyUnknownEncodingHandler ;
1931
+ capi . size = sizeof (capi );
1932
+ capi . magic = PyExpat_CAPI_MAGIC ;
1933
+ capi . MAJOR_VERSION = XML_MAJOR_VERSION ;
1934
+ capi . MINOR_VERSION = XML_MINOR_VERSION ;
1935
+ capi . MICRO_VERSION = XML_MICRO_VERSION ;
1936
+ capi . ErrorString = XML_ErrorString ;
1937
+ capi . GetErrorCode = XML_GetErrorCode ;
1938
+ capi . GetErrorColumnNumber = XML_GetErrorColumnNumber ;
1939
+ capi . GetErrorLineNumber = XML_GetErrorLineNumber ;
1940
+ capi . Parse = XML_Parse ;
1941
+ capi . ParserCreate_MM = XML_ParserCreate_MM ;
1942
+ capi . ParserFree = XML_ParserFree ;
1943
+ capi . SetCharacterDataHandler = XML_SetCharacterDataHandler ;
1944
+ capi . SetCommentHandler = XML_SetCommentHandler ;
1945
+ capi . SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand ;
1946
+ capi . SetElementHandler = XML_SetElementHandler ;
1947
+ capi . SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler ;
1948
+ capi . SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler ;
1949
+ capi . SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler ;
1950
+ capi . SetUserData = XML_SetUserData ;
1951
+ capi . SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler ;
1952
+ capi . SetEncoding = XML_SetEncoding ;
1953
+ capi . DefaultUnknownEncodingHandler = PyUnknownEncodingHandler ;
1965
1954
#if XML_COMBINED_VERSION >= 20100
1966
- capi -> SetHashSalt = XML_SetHashSalt ;
1955
+ capi . SetHashSalt = XML_SetHashSalt ;
1967
1956
#else
1968
- capi -> SetHashSalt = NULL ;
1957
+ capi . SetHashSalt = NULL ;
1969
1958
#endif
1970
1959
1971
1960
/* export using capsule */
1972
- PyObject * capi_object = PyCapsule_New (capi , PyExpat_CAPSULE_NAME ,
1973
- pyexpat_destructor );
1961
+ PyObject * capi_object = PyCapsule_New (& capi , PyExpat_CAPSULE_NAME , NULL );
1974
1962
if (capi_object == NULL ) {
1975
- PyMem_Free (capi );
1976
1963
return -1 ;
1977
1964
}
1978
1965
0 commit comments