Andy Polyakov <[EMAIL PROTECTED]>:

>> The function pointer *must* be inside a data object to make such constructs
>> legal,

> But that's what Richard (subconsciously?) attempted to do in first
> place:
> 
> static void (*mem_cb)()=NULL;
> 
> void CRYPTO_mem_leaks_cb(void (*cb)())
>         {
>         ...
>         mem_cb=cb;
>         lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
>         mem_cb=NULL;
>         ...
>         }

That's weird, I did not notice this and don't know why he did it this way
(and probably he doesn't either :-).

This is however not what I meant, this is just like calling

         lh_doall_arg(mh,(void (*)())cb_leak,(char *)cb);

without using the extra static variable.  We're still passing
a function pointer value.  What would work, however, is

> void CRYPTO_mem_leaks_cb(void (*cb)())
>         {
>         ...
>         void *cb_ptr=&cb;
>         lh_doall_arg(mh,(void (*)())cb_leak,cb);
>         ...
>         }

(there's no reason to introduce a struct unless one wants to do things
over-complicated, I don't know why I mentioned structs before).
The point is that C doesn't like mixing function pointers and data
object pointers; they don't necessarily have identical
representations (you could have 32 bit function pointers, but 64
bit data pointers).  To force C to convert values between these types,
you'd have to cast to some integer type inbetween:

        (void (*)()) (long) cb

But of course this is so complicated because it should never be done
and is not guaranteed to do anything useful.  &cb, on the other hand,
is the pointer to some data object; the function that gets this
pointer as an argument has to retrieve the actual function pointer
from inside this data object, i.e. use *((void (**)()) arg)
where arg is the void * argument passed to it.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to