[Expat-discuss] New API: XML_FreeContentModel

Karl Waclawek karl at waclawek.net
Wed Jan 15 10:38:52 EST 2003


When using the element declaration handler,

typedef void
(*XML_ElementDeclHandler)(void *userData,
                          const XML_Char *name,
                          XML_Content *model);

it is the application's responsibility to free the content model argument.

The only way to do this from languages other than C/C++ is to create
a parser instance passing it application supplied memory management
function pointers (with XML_ParserCreate_MM).
 
This makes it hard or impossible to use Expat from languages that cannot
supply such C-compatible (signature *and* semantics) memory handlers,
but can access a Dll or shared library otherwise (like VB).

For that purpose I suggest adding a new API to Expat:

XMLPARSEAPI(void)
XML_FreeContentModel(XML_Parser parser, XML_Content *model);

This not only solves the problem above, but is also better from
a design perspective, since currently the application using Expat
has to know that Expat allocated the content model in one contiguous
chunk of memory. The API above hides that implementation detail.

As an alternative solution we have also had a request to add an API
that returns the memory handling suite of function pointers, like

XMLPARSEAPI(const XML_Memory_Handling_Suite *)
XML_GetMemSuite(XML_Parser parser);

allowing the application to free the content model natively.
However, this would not hide the implementation details of
how the content model is allocated.

Feedback welcome,

Karl




More information about the Expat-discuss mailing list