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

RE: [xml] initGenericErrorDefaultFunc weirdness.



Umm, well, maybe.  Take a look at the implementation of
initGenericErrorDefaultFunc():

void
initGenericErrorDefaultFunc(xmlGenericErrorFunc * handler)
{
    if (handler == NULL)
        xmlGenericError = xmlGenericErrorDefaultFunc;
    else
        (*handler) = xmlGenericErrorDefaultFunc;
}

handler is a pointer to function pointer in order to allow
initGenericErrorDefaultFunc() to stuff a value into it.  Passing a
pointer to the address of an actual function is pointless (so to speak)
at best, catastrophic at worst.  You should either pass NULL or the
address of a function pointer variable:

xmlGenericErrorFunc handler;
initGenericErrorDefaultFunc(&handler);
/* do something with handler if desired, perhaps calling the function it
points to if it's not NULL */

Caveat: this is based purely on an inspection of the code.  I'm not
quite sure what initGenericErrorDefaultFunc() does, or what you're
trying to accomplish, but I have the feeling it's not doing what you
want done.

> -----Original Message-----
> From: xml-bounces gnome org [mailto:xml-bounces gnome org] On 
> Behalf Of William M. Brack
> Sent: Wednesday, June 02, 2004 10:23 AM
> To: Jose Commins
> Cc: xml gnome org
> Subject: Re: [xml] initGenericErrorDefaultFunc weirdness.
> 
> OK, sorry about that - I must be more careful to respond accurately!
> 
> Basic C programming example follows:-
> ---------------------------------------
>   bill billsuper work $ cat bb.c
>   #include <libxml/xmlerror.h>
>   void MyXMLErrorFunction(void *ctx, const char *msg, ...)
>   {
>     return;
>   }
> 
>   int main(int argc, char **argv) {
>     initGenericErrorDefaultFunc(
>       (xmlGenericErrorFunc *)&MyXMLErrorFunction
>      );
>   return 0;
>   }
>   bill billsuper work $ gcc -Wall \
>     `../xmlinstall/bin/xml2-config --cflags --libs` \
>     -o bb bb.c
>   bill billsuper work $
> -------------------------------------------
> 
> The function initGenericErrorDefaultFunc takes a single argument
> which is the *address* of a function of type xmlGenericErrorFunc. 
> Therefore, since MyXMLErrorFunction is declared as type void, it is
> necessary to specify a type override.  The required type is the
> address (i.e. a pointer to) a xmlGenericErrorFunc, and in C that is
> written as (xmlGenericErrorFunc *).
> 
> HTH
> 
> Bill
> 
> 
> Jose Commins said:
> >
> > 	With your suggestion below, I get ' main.c:109: error: invalid
> > lvalue
> > in unary `&' '
> > 	With this:
> > 
> initGenericErrorDefaultFunc((xmlGenericErrorFunc)&MyXMLErrorFunction)
> > I
> > still get: 'main.c:109: passing arg 1 of
> > `initGenericErrorDefaultFunc'
> > from incompatible pointer type' error.
> > 	Argh!
> >
> >
> > Regards,
> > 		Jose.
> >
> > --
> >   Death, taxes and Microsoft. If you put it that way, the first two
> > don't seem so bad.
> >
> > On 2 Jun 2004, at 3:37 am, William M. Brack wrote:
> >
> >> Jose Commins said:
> >>>
> >>> 	Odd, I am trying to use:
> >>>
> >>> 	
> initGenericErrorDefaultFunc((xmlGenericErrorFunc)MyXMLErrorFunction);
> >>>
> >>> 	But I get this error on compilation:
> >>>
> >>> 	main.c:109: passing arg 1 of `initGenericErrorDefaultFunc' from
> >>> incompatible pointer type
> >>>
> >>> 	And here's my function:
> >>>
> >>> void MyXMLErrorFunction(void *ctx, const char *msg, ...)
> >>> {
> >>> 	printf("Aiee!  And error has occured!\n");
> >>> }
> >>>
> >>>
> >>> 	I've tried everything: using the direct address, different
> >>> assignments
> >>> and so on, but I either get the same error or bus errors.  I *do*
> >>> have
> >>> this working:
> >>>
> >>> 	xmlSetGenericErrorFunc(NULL,
> >>> (xmlGenericErrorFunc)MyXMLErrorFunction);
> >>>
> >>> 	And that works fine.
> >>>
> >>> 	But, am I doing something wrong with the declaration/assignment
> >>> of
> >>> 'initGenericErrorDefaultFunc' or is it b0rked?
> >>>
> >>>
> >>> Regards,
> >>> 		Jose.
> >>
> >> From xmlerror.h:
> >> XMLPUBFUN void XMLCALL
> >>     xmlSetGenericErrorFunc      (void *ctx,
> >>                                  xmlGenericErrorFunc handler);
> >> XMLPUBFUN void XMLCALL
> >>     initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);
> >>
> >> so perhaps you could try
> >>
> >> 
> initGenericErrorDefaultFunc(&(xmlGenericErrorFunc)MyXMLErrorFunction);
> >>
> >> (i.e. use the '&' address-of operator)?
> >>
> >> Regards,
> >>
> >> Bill



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