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

appro> But that's what Richard (subconsciously?) attempted to do in
appro> first place:

Don't look at me, that part of the code was there in mem.c since
eons...

appro> static void (*mem_cb)()=NULL;
appro> 
appro> void CRYPTO_mem_leaks_cb(void (*cb)())
appro>         {
appro>         ...
appro>         mem_cb=cb;
appro>         lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
appro>         mem_cb=NULL;
appro>         ...
appro>         }
appro> 
appro> I mean someting has prevented him from just "lh_doall_arg(mh,(void
appro> (*)())cb_leak,(char *)cb)," hasn't it?

I Actually don't know why Eric needed to do that.  But just for
clarity, let me show you what DEC C says:

        void (*mem_callback)()=(void (*)())cb;
...........................................^
%CC-I-NONSTANDCAST, In the initializer for mem_callback, "cb" of type "pointer to 
char", is being converted to "pointer to function () returning void".  Such a cast is 
not permitted by the standard.
at line number 668 in file 
DISK$ALPUTILS:[LEVITTE.WRK.OPENSSL-0_9_5-DEV.CRYPTO]MEM_DBG.C;3

        lh_doall_arg(mh,(void (*)())cb_leak,(char *)mem_cb);
....................................................^
%CC-I-NONSTANDCAST, In this statement, "mem_cb" of type "pointer to function () 
returning void", is being converted to "pointer to char".  Such a cast is not 
permitted by the standard.
at line number 677 in file 
DISK$ALPUTILS:[LEVITTE.WRK.OPENSSL-0_9_5-DEV.CRYPTO]MEM_DBG.C;3


As you can see, whatever you do with the current scheme, there will
always be a conversion between function pointers and non-function
pointers.

appro> > so this is not silly at all.  An alternative would be to use
appro> > unions of a function pointer
appro> Why structures/unions? "lh_doall_arg(mh,(void (*)())cb_leak,(void
appro> *)&mem_cb)" should do...

The easiest way to avoid the conversions noted above is to have a
union like this:

        union foo {
                void *simple;
                int (*fn)();
        };

and use it internally.  You put whatever char * you want to convert to
a functino pointer into simple and pull out the function pointer from
fn, and vice versa.

appro> Of course provided that it's appropriately derefenced in
appro> cb_leak!

As you can see above, that's exactly one of the problems.

appro> And I fail to understand why mem_cb has to be declared static?

Not to be seen outside of the file?

appro> It can be perfectly declared in CRYPTO_mem_leaks_cb scope which
appro> also makes it multi-thead safe, doesn't it?

You're absolutely right about, but that is beside the point in this
case.  This is a ANSI C problem, not a MT problem.

appro> typedef void (*cb_t) ();
appro> 
appro> static void cb_leak(MEM *m, void *cb)
appro>         {
appro>         void (*mem_callback)()=*((cb_t *)cb);

You convert from void * to void (*)() (i.e. between a "simple
type" and a function pointer).  DEC C will complain.

appro>         mem_callback(m->order,m->file,m->line,m->num,m->addr);
appro>         }
appro> 
appro> void CRYPTO_mem_leaks_cb(void (*cb)())
appro>         {
appro>         void (*mem_cb)() = cb;
appro>         if (mh == NULL) return;
appro>         CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
appro>         lh_doall_arg(mh,(void (*)())cb_leak,(void *)(&mem_cb));

You convert from void (*)() to void * (i.e. between a "simple
type" and a function pointer).  DEC C will complain.

appro>         CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);
appro>         }

-- 
Richard Levitte   \ Spannv�gen 38, II \ [EMAIL PROTECTED]
Redakteur@Stacken  \ S-161 43  BROMMA  \ T: +46-8-26 52 47
                    \      SWEDEN       \ or +46-708-26 53 44
Procurator Odiosus Ex Infernis             -- [EMAIL PROTECTED]

Unsolicited commercial email is subject to an archival fee of $400.
See <http://www.stacken.kth.se/~levitte/mail/> for more info.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to