@@ -1886,13 +1886,6 @@ add_features(PyObject *mod)
1886
1886
}
1887
1887
#endif
1888
1888
1889
- static void
1890
- pyexpat_destructor (PyObject * op )
1891
- {
1892
- void * p = PyCapsule_GetPointer (op , PyExpat_CAPSULE_NAME );
1893
- PyMem_Free (p );
1894
- }
1895
-
1896
1889
static int
1897
1890
pyexpat_exec (PyObject * mod )
1898
1891
{
@@ -1980,46 +1973,40 @@ pyexpat_exec(PyObject *mod)
1980
1973
MYCONST (XML_PARAM_ENTITY_PARSING_ALWAYS );
1981
1974
#undef MYCONST
1982
1975
1983
- struct PyExpat_CAPI * capi = PyMem_Calloc (1 , sizeof (struct PyExpat_CAPI ));
1984
- if (capi == NULL ) {
1985
- PyErr_NoMemory ();
1986
- return -1 ;
1987
- }
1976
+ static struct PyExpat_CAPI capi ;
1988
1977
/* initialize pyexpat dispatch table */
1989
- capi -> size = sizeof (* capi );
1990
- capi -> magic = PyExpat_CAPI_MAGIC ;
1991
- capi -> MAJOR_VERSION = XML_MAJOR_VERSION ;
1992
- capi -> MINOR_VERSION = XML_MINOR_VERSION ;
1993
- capi -> MICRO_VERSION = XML_MICRO_VERSION ;
1994
- capi -> ErrorString = XML_ErrorString ;
1995
- capi -> GetErrorCode = XML_GetErrorCode ;
1996
- capi -> GetErrorColumnNumber = XML_GetErrorColumnNumber ;
1997
- capi -> GetErrorLineNumber = XML_GetErrorLineNumber ;
1998
- capi -> Parse = XML_Parse ;
1999
- capi -> ParserCreate_MM = XML_ParserCreate_MM ;
2000
- capi -> ParserFree = XML_ParserFree ;
2001
- capi -> SetCharacterDataHandler = XML_SetCharacterDataHandler ;
2002
- capi -> SetCommentHandler = XML_SetCommentHandler ;
2003
- capi -> SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand ;
2004
- capi -> SetElementHandler = XML_SetElementHandler ;
2005
- capi -> SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler ;
2006
- capi -> SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler ;
2007
- capi -> SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler ;
2008
- capi -> SetUserData = XML_SetUserData ;
2009
- capi -> SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler ;
2010
- capi -> SetEncoding = XML_SetEncoding ;
2011
- capi -> DefaultUnknownEncodingHandler = PyUnknownEncodingHandler ;
1978
+ capi . size = sizeof (capi );
1979
+ capi . magic = PyExpat_CAPI_MAGIC ;
1980
+ capi . MAJOR_VERSION = XML_MAJOR_VERSION ;
1981
+ capi . MINOR_VERSION = XML_MINOR_VERSION ;
1982
+ capi . MICRO_VERSION = XML_MICRO_VERSION ;
1983
+ capi . ErrorString = XML_ErrorString ;
1984
+ capi . GetErrorCode = XML_GetErrorCode ;
1985
+ capi . GetErrorColumnNumber = XML_GetErrorColumnNumber ;
1986
+ capi . GetErrorLineNumber = XML_GetErrorLineNumber ;
1987
+ capi . Parse = XML_Parse ;
1988
+ capi . ParserCreate_MM = XML_ParserCreate_MM ;
1989
+ capi . ParserFree = XML_ParserFree ;
1990
+ capi . SetCharacterDataHandler = XML_SetCharacterDataHandler ;
1991
+ capi . SetCommentHandler = XML_SetCommentHandler ;
1992
+ capi . SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand ;
1993
+ capi . SetElementHandler = XML_SetElementHandler ;
1994
+ capi . SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler ;
1995
+ capi . SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler ;
1996
+ capi . SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler ;
1997
+ capi . SetUserData = XML_SetUserData ;
1998
+ capi . SetStartDoctypeDeclHandler = XML_SetStartDoctypeDeclHandler ;
1999
+ capi . SetEncoding = XML_SetEncoding ;
2000
+ capi . DefaultUnknownEncodingHandler = PyUnknownEncodingHandler ;
2012
2001
#if XML_COMBINED_VERSION >= 20100
2013
- capi -> SetHashSalt = XML_SetHashSalt ;
2002
+ capi . SetHashSalt = XML_SetHashSalt ;
2014
2003
#else
2015
- capi -> SetHashSalt = NULL ;
2004
+ capi . SetHashSalt = NULL ;
2016
2005
#endif
2017
2006
2018
2007
/* export using capsule */
2019
- PyObject * capi_object = PyCapsule_New (capi , PyExpat_CAPSULE_NAME ,
2020
- pyexpat_destructor );
2008
+ PyObject * capi_object = PyCapsule_New (& capi , PyExpat_CAPSULE_NAME , NULL );
2021
2009
if (capi_object == NULL ) {
2022
- PyMem_Free (capi );
2023
2010
return -1 ;
2024
2011
}
2025
2012
0 commit comments