[Python-Dev] Sharing expat instances

Fredrik Lundh fredrik at pythonware.com
Tue Dec 13 17:22:18 CET 2005


Martin v. Löwis wrote:
> > - sort out expat bundling issues, and include cElementTree as well
> > (using the same approach as above).

...
> > (one way to do this would be to add an "function pointer table" to pyexpat
> > that contains pointers to selected portions of the expat API, and then add
> > an indirection level to cElementTree)
>> Ok, this sounds like a larger piece of work.

here's a plan:
1. add an Include/pyexpat.h header file which contains a structure
similar to the following:
#define PyExpat_DISPATCH_MAGIC "... some magic string ..."
struct PyExpat_Dispatch {
 int size; /* size of this structure */
 int MAJOR_VERSION;
 int MINOR_VERSION;
 int MICRO_VERSION;
 ... (*ErrorString)(...)
 ... (*GetErrorColumnNumber)(...)
 ... (*GetErrorLineNumber)(...)
 ... (*Parse)(...)
 ... (*ParserCreate_MM)(...)
 ... (*ParserFree)(...)
 ... (*SetCharacterDataHandler)(...)
 ... (*SetCommentHandler)(...)
 ... (*SetDefaultHandlerExpand)(...)
 ... (*SetElementHandler)(...)
 ... (*SetNamespaceDeclHandler)(...)
 ... (*SetProcessingInstructionHandler)(...)
 ... (*SetUserData)(...)
 /* add new stuff to the end */
}
(this is the minimal stuff used by today's cElementTree; it can of course
be extended to cover a larger part of the current expat API)
2. during pyexpat initialization, initialize all members of this structure, and
make it available as a PyCObject:
 static PyExpat_Dispatch dispatch;
 dispatch.size = sizeof(dispatch):
 dispatch.MAJOR_VERSION = XML_MAJOR_VERSION;
 ...
 obj = PyCObject_FromVoidPtrAndDesc(
 &dispatch, PyExpat_DISPATCH_MAGIC, NULL
 );
 ... stuff object into module dictionary ...
3. in cElementTree (or _elementtree, or whatever the python version will
be named), import pyexpat, fetch the object, and verify
 - that the PyExpat_DISPATCH_MAGIC matches
 - that the size field is at least as large as sizeof(struct PyExpat_Dispatch)
 - that the version number matches (at least MAJOR and MINOR; I'm not
 sure under what circumstances they change the MICRO number)
4. in cElementTree (...), do all expat calls via the dispatch table.
comments ?
</F>


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /