diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2005-12-13 19:49:55 +0000 |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2005-12-13 19:49:55 +0000 |
commit | c3345040df1adb502f5b62e9b3efc6f4232a952f (patch) | |
tree | 7b5a4b66d37dc7d931c2859e84ac30cd41bb7390 | |
parent | e2f8e3c14f6f17fe6541c926e69a5f01f1a91b9b (diff) | |
download | cpython-git-c3345040df1adb502f5b62e9b3efc6f4232a952f.tar.gz |
added cobject-based expat dispatch mechanism to pyexpat
-rw-r--r-- | Include/pyexpat.h | 45 | ||||
-rw-r--r-- | Modules/pyexpat.c | 31 |
2 files changed, 76 insertions, 0 deletions
diff --git a/Include/pyexpat.h b/Include/pyexpat.h new file mode 100644 index 0000000000..e54b16fbac --- /dev/null +++ b/Include/pyexpat.h @@ -0,0 +1,45 @@ +/* Stuff to export relevant 'expat' entry points from pyexpat to other + * parser modules, such as cElementTree. */ + +/* note: you must import expat.h before importing this module! */ + +#define PyExpat_DISPATCH_MAGIC "pyexpat.dispatch 1.0" + +struct PyExpat_Dispatch +{ + int size; /* set to sizeof(struct PyExpat_Dispatch) */ + int MAJOR_VERSION; /* XXX: use the ExpatVersionInfo instead? */ + int MINOR_VERSION; + int MICRO_VERSION; + /* pointers to selected expat functions. add new functions at + the end, if needed */ + const XML_LChar * (*ErrorString)(enum XML_Error code); + int (*GetCurrentColumnNumber)(XML_Parser parser); + int (*GetCurrentLineNumber)(XML_Parser parser); + enum XML_Status (*Parse)( + XML_Parser parser, const char *s, int len, int isFinal); + XML_Parser (*ParserCreate_MM)( + const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); + void (*ParserFree)(XML_Parser parser); + void (*SetCharacterDataHandler)( + XML_Parser parser, XML_CharacterDataHandler handler); + void (*SetCommentHandler)( + XML_Parser parser, XML_CommentHandler handler); + void (*SetDefaultHandlerExpand)( + XML_Parser parser, XML_DefaultHandler handler); + void (*SetElementHandler)( + XML_Parser parser, XML_StartElementHandler start, + XML_EndElementHandler end); + void (*SetNamespaceDeclHandler)( + XML_Parser parser, XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); + void (*SetProcessingInstructionHandler)( + XML_Parser parser, XML_ProcessingInstructionHandler handler); + void (*SetUnknownEncodingHandler)( + XML_Parser parser, XML_UnknownEncodingHandler handler, + void *encodingHandlerData); + void (*SetUserData)(XML_Parser parser, void *userData); + /* always add new stuff to the end! */ +}; + diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index d1def2408e..b59a51d0e5 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -4,6 +4,8 @@ #include "frameobject.h" #include "expat.h" +#include "pyexpat.h" + #define XML_COMBINED_VERSION (10000*XML_MAJOR_VERSION+100*XML_MINOR_VERSION+XML_MICRO_VERSION) #ifndef PyDoc_STRVAR @@ -1838,6 +1840,8 @@ MODULE_INITFUNC(void) PyObject *modelmod_name; PyObject *model_module; PyObject *sys_modules; + static struct PyExpat_Dispatch dispatch; + PyObject* dispatch_object; if (errmod_name == NULL) return; @@ -2011,6 +2015,33 @@ MODULE_INITFUNC(void) MYCONST(XML_CQUANT_REP); MYCONST(XML_CQUANT_PLUS); #undef MYCONST + + /* initialize pyexpat dispatch table */ + dispatch.size = sizeof(dispatch); + dispatch.MAJOR_VERSION = XML_MAJOR_VERSION; + dispatch.MINOR_VERSION = XML_MINOR_VERSION; + dispatch.MICRO_VERSION = XML_MICRO_VERSION; + dispatch.ErrorString = XML_ErrorString; + dispatch.GetCurrentColumnNumber = XML_GetCurrentColumnNumber; + dispatch.GetCurrentLineNumber = XML_GetCurrentLineNumber; + dispatch.Parse = XML_Parse; + dispatch.ParserCreate_MM = XML_ParserCreate_MM; + dispatch.ParserFree = XML_ParserFree; + dispatch.SetCharacterDataHandler = XML_SetCharacterDataHandler; + dispatch.SetCommentHandler = XML_SetCommentHandler; + dispatch.SetDefaultHandlerExpand = XML_SetDefaultHandlerExpand; + dispatch.SetElementHandler = XML_SetElementHandler; + dispatch.SetNamespaceDeclHandler = XML_SetNamespaceDeclHandler; + dispatch.SetProcessingInstructionHandler = XML_SetProcessingInstructionHandler; + dispatch.SetUnknownEncodingHandler = XML_SetUnknownEncodingHandler; + dispatch.SetUserData = XML_SetUserData; + + /* export as cobject */ + dispatch_object = PyCObject_FromVoidPtrAndDesc( + &dispatch, PyExpat_DISPATCH_MAGIC, NULL + ); + if (dispatch_object) + PyModule_AddObject(m, "dispatch", dispatch_object); } static void |