[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [xml] Problems with libxml2-2.6.4



On Mon, Feb 23, 2004 at 05:34:14PM +0000, Gary Pennington wrote:
> Hi,
> 
> I have a problem with libxml2 (2.6.4).
> 
> The problem lies with xmlSAXParseFile(). This function is defined as:
> 
> XMLPUBFUN xmlDocPtr XMLCALL
>                 xmlSAXParseFile         (xmlSAXHandlerPtr sax,
>                                          const char *filename,
>                                          int recovery);
> 
> (You'll note that argument 1 is xmlSAXHandlerPtr. However, if code does the
> following:
> 
> 	xmlDocPtr doc = xmlSAXParseFile(&xmlDefaultSAXHandler, filename, 0);
> 
> Then there is an issue, since xmlDefaultSAXHandler() is defined as:
> 
> XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __xmlDefaultSAXHandler(void);
> 
> (With threads enabled, XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler
> otherwise.)
> 
> This means that compiling code that uses xmlSAXParseFile with
> xmlDefaultSAXHandler will generate warnings since the function expects
> a  XMLSAXHandlerPtr for the first argument but gets xmlSAXHandlerV1*.
> 
> I can see that there is some kind of mismatch between the xmlSAXParseFile()
> function and the definition of xmlDefaultSAXHandler, but it's not clear how
> best to address it.
> 
> How should this best be corrected? Is it correct to just cast the value
> of &xmlDefaultSAXHandler to xmlSAXHandlerPtr?

  in the transition to 2.6 the following happened:
    - the parser got converted to SAX2 internally, this was discussed
      on the list.
    - the xmlSAXHandlerPtr structure grew up as a result, especially
      new startElementNs and endElementNs callbacks
    - the old public variables got transformed to use a backward compatible
      type xmlSAXHandlerV1
    - the parser interfaces check for xmlSAXHandlerPtr->initialized
      and if it's not XML_SAX2_MAGIC then it assume it's a V1 interface
      and us the backward compatible internal code path for it.

Using xmlDefaultSAXHandler is safe, the parser will detect it's V1 and
use the older parsing code, so a cast is fine. You just don't get the
benefits of SAX2 and some of the speedup. You're basically using a
compatibility mode for pre-2.6,

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]