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