On Wed, Nov 08, 2006 at 12:47:03PM -0800, David Schwartz wrote:
>
> > But it gets cast back to the correct type before it is called. These
> > casts are done the way they are to get type-safety. Removing that option
> > strikes me as a bad thing.

>
> It does not. Look closely at how these functions work:
>
> char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
> pem_password_cb *cb, void *u)


That seems to be 0.9.7 code, in 0.9.8 it looks like:
void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
pem_password_cb *cb, void *u)

And we have:
typedef void *d2i_of_void(void **,const unsigned char **,long);

The example mentioned in on the gcc list seems to be:
X509 *PEM_read_X509_AUX(FILE *fp, X509 **x, pem_password_cb *cb, void *u)
{
return(((X509 *(*)(X509 *(*)(X509 **,const unsigned char **,long),char *,FILE *,X509 **,pem_password_cb *,void *))((openssl_fptr)PEM_ASN1_read))(d2i_X509_AUX, "TRUSTED CERTIFICATE",fp,x,cb,u));
}

We have:
void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
pem_password_cb *cb, void *u);

What happens here is that PEM_ASN1_read() first gets cast to an
openssl_fptr which is:
typedef void (*openssl_fptr)(void);

And then to an:
X509 *(*)(X509 *(*)(X509 **,const unsigned char **,long),char *,FILE
*,X509 **,pem_password_cb *,void *)

And we have:
X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length);

What I think the problem is, is that you use "d2i_of_void *d2i" while
you mean "d2i_of_void d2i".

d2i_of_void *d2i would be a pointer to a pointer to a function, while
d2i_of_void d2i would be just a pointer to a function.


Kurt

__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager majordomo@openssl.org