[xmlsec] fix warning about ptr->func conversion
- From: Aleksey Sanin <aleksey src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [xmlsec] fix warning about ptr->func conversion
- Date: Sun, 9 May 2010 21:07:15 +0000 (UTC)
commit ebbf6e958d8396160b0320d52f5ac8b24162a308
Author: Aleksey Sanin <aleksey aleksey com>
Date: Sun May 9 14:07:26 2010 -0700
fix warning about ptr->func conversion
include/xmlsec/mscrypto/crypto.h | 16 +++++-----
include/xmlsec/xmlsec.h | 57 ++++++++++++++++++++++++++++++++++++++
src/dl.c | 19 ++++++++++--
src/openssl/app.c | 42 +++++++++++++++++++++------
4 files changed, 112 insertions(+), 22 deletions(-)
---
diff --git a/include/xmlsec/mscrypto/crypto.h b/include/xmlsec/mscrypto/crypto.h
index dd8a994..5f3142f 100644
--- a/include/xmlsec/mscrypto/crypto.h
+++ b/include/xmlsec/mscrypto/crypto.h
@@ -194,14 +194,14 @@ XMLSEC_CRYPTO_EXPORT xmlSecTransformId xmlSecMSCryptoTransformRsaSha512GetKlass(
xmlSecMSCryptoTransformRsaPkcs1GetKlass()
XMLSEC_CRYPTO_EXPORT xmlSecTransformId xmlSecMSCryptoTransformRsaPkcs1GetKlass(void);
-/**
- * xmlSecMSCryptoTransformRsaOaepId:
- *
- * The RSA OAEP key transport transform klass.
- */
-#define xmlSecMSCryptoTransformRsaOaepId \
- xmlSecMSCryptoTransformRsaOaepGetKlass()
-XMLSEC_CRYPTO_EXPORT xmlSecTransformId xmlSecMSCryptoTransformRsaOaepGetKlass(void);
+/**
+ * xmlSecMSCryptoTransformRsaOaepId:
+ *
+ * The RSA OAEP key transport transform klass.
+ */
+#define xmlSecMSCryptoTransformRsaOaepId \
+ xmlSecMSCryptoTransformRsaOaepGetKlass()
+XMLSEC_CRYPTO_EXPORT xmlSecTransformId xmlSecMSCryptoTransformRsaOaepGetKlass(void);
/**
* xmlSecMSCryptoTransformRsaOaepId:
diff --git a/include/xmlsec/xmlsec.h b/include/xmlsec/xmlsec.h
index 9ab4cea..ad44918 100644
--- a/include/xmlsec/xmlsec.h
+++ b/include/xmlsec/xmlsec.h
@@ -150,6 +150,63 @@ XMLSEC_EXPORT int xmlSecCheckVersionExt (int major,
#define ATTRIBUTE_UNUSED
#endif
+/***********************************************************************
+ *
+ * Helpers to convert from void* to function pointer, this silence
+ * gcc warning
+ *
+ * warning: ISO C forbids conversion of object pointer to function
+ * pointer type
+ *
+ * The workaround is to declare a union that does the conversion. This is
+ * guaranteed (ISO/IEC 9899:1990 "C89"/"C90") to match exactly.
+ *
+ ***********************************************************************/
+
+/**
+ * XMLSEC_PTR_TO_FUNC_IMPL:
+ * @func_type: the function type.
+ *
+ * Macro declares helper functions to convert between "void *" pointer and
+ * function pointer.
+ */
+#define XMLSEC_PTR_TO_FUNC_IMPL(func_type) \
+ union xmlSecPtrToFuncUnion_ ##func_type { \
+ void *ptr; \
+ func_type * func; \
+ } ; \
+ static func_type * xmlSecPtrToFunc_ ##func_type(void * ptr) { \
+ union xmlSecPtrToFuncUnion_ ##func_type x; \
+ x.ptr = ptr; \
+ return (x.func); \
+ } \
+ static void * xmlSecFuncToPtr_ ##func_type(func_type * func) { \
+ union xmlSecPtrToFuncUnion_ ##func_type x; \
+ x.func = func; \
+ return (x.ptr); \
+ }
+
+/**
+ * XMLSEC_PTR_TO_FUNC:
+ * @func_type: the function type.
+ * @ptr: the "void*" pointer to be converted.
+ *
+ * Macro converts from "void*" pointer to "func_type" function pointer.
+ */
+#define XMLSEC_PTR_TO_FUNC(func_type, ptr) \
+ xmlSecPtrToFunc_ ##func_type((ptr))
+
+/**
+ * XMLSEC_FUNC_TO_PTR:
+ * @func_type: the function type.
+ * @func: the "func_type" function pointer to be converted.
+ *
+ * Macro converts from "func_type" function pointer to "void*" pointer.
+ */
+#define XMLSEC_FUNC_TO_PTR(func_type, func) \
+ xmlSecFuncToPtr_ ##func_type((func))
+
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/src/dl.c b/src/dl.c
index 3771e84..d6f37ef 100644
--- a/src/dl.c
+++ b/src/dl.c
@@ -82,10 +82,14 @@ static int xmlSecCryptoDLLibrariesListFindByName (xmlSecP
typedef xmlSecCryptoDLFunctionsPtr (*xmlSecCryptoGetFunctionsCallback)(void);
+/* conversion from ptr to func "the right way" */
+XMLSEC_PTR_TO_FUNC_IMPL(xmlSecCryptoGetFunctionsCallback)
+
+
static xmlSecCryptoDLLibraryPtr
xmlSecCryptoDLLibraryCreate(const xmlChar* name) {
xmlSecCryptoDLLibraryPtr lib;
- xmlSecCryptoGetFunctionsCallback getFunctions;
+ xmlSecCryptoGetFunctionsCallback * getFunctions;
xmlSecAssert2(name != NULL, NULL);
@@ -149,7 +153,9 @@ xmlSecCryptoDLLibraryCreate(const xmlChar* name) {
return(NULL);
}
- getFunctions = (xmlSecCryptoGetFunctionsCallback)lt_dlsym(lib->handle, (char*)lib->getFunctionsName);
+ getFunctions = XMLSEC_PTR_TO_FUNC(xmlSecCryptoGetFunctionsCallback,
+ lt_dlsym(lib->handle, (char*)lib->getFunctionsName)
+ );
if(getFunctions == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
"lt_dlsym",
@@ -175,7 +181,12 @@ xmlSecCryptoDLLibraryCreate(const xmlChar* name) {
return(NULL);
}
- getFunctions = (xmlSecCryptoGetFunctionsCallback)GetProcAddress(lib->handle, (char*)lib->getFunctionsName);
+ getFunctions = XMLSEC_PTR_TO_FUNC(xmlSecCryptoGetFunctionsCallback,
+ GetProcAddress(
+ lib->handle,
+ (const char*)lib->getFunctionsName
+ )
+ );
if(getFunctions == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
"GetProcAddressA",
@@ -198,7 +209,7 @@ xmlSecCryptoDLLibraryCreate(const xmlChar* name) {
return(NULL);
}
- lib->functions = getFunctions();
+ lib->functions = (*getFunctions)();
if(lib->functions == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
"getFunctions",
diff --git a/src/openssl/app.c b/src/openssl/app.c
index fe427ea..1319b07 100644
--- a/src/openssl/app.c
+++ b/src/openssl/app.c
@@ -32,10 +32,20 @@
#include <xmlsec/openssl/evp.h>
#include <xmlsec/openssl/x509.h>
-static int xmlSecOpenSSLAppLoadRANDFile (const char *file);
-static int xmlSecOpenSSLAppSaveRANDFile (const char *file);
-static int xmlSecOpenSSLDefaultPasswordCallback(char *buf, int bufsiz, int verify, void *userdata);
-static int xmlSecOpenSSLDummyPasswordCallback (char *buf, int bufsize, int verify, void *userdata);
+static int xmlSecOpenSSLAppLoadRANDFile (const char *file);
+static int xmlSecOpenSSLAppSaveRANDFile (const char *file);
+static int xmlSecOpenSSLDefaultPasswordCallback (char *buf,
+ int bufsiz,
+ int verify,
+ void *userdata);
+static int xmlSecOpenSSLDummyPasswordCallback (char *buf,
+ int bufsize,
+ int verify,
+ void *userdata);
+
+/* conversion from ptr to func "the right way" */
+XMLSEC_PTR_TO_FUNC_IMPL(pem_password_cb)
+
/**
* xmlSecOpenSSLAppInit:
@@ -234,13 +244,21 @@ xmlSecOpenSSLAppKeyLoadBIO(BIO* bio, xmlSecKeyDataFormat format,
switch(format) {
case xmlSecKeyDataFormatPem:
/* try to read private key first */
+ if(pwd != NULL) {
pKey = PEM_read_bio_PrivateKey(bio, NULL,
- (pwd != NULL) ? xmlSecOpenSSLDummyPasswordCallback : (pem_password_cb*)pwdCallback,
- (pwd != NULL) ? (void*)pwd : pwdCallbackCtx);
+ xmlSecOpenSSLDummyPasswordCallback,
+ (void*)pwd);
+ } else {
+ pKey = PEM_read_bio_PrivateKey(bio, NULL,
+ XMLSEC_PTR_TO_FUNC(pem_password_cb, pwdCallback),
+ pwdCallbackCtx);
+ }
if(pKey == NULL) {
/* go to start of the file and try to read public key */
BIO_reset(bio);
- pKey = PEM_read_bio_PUBKEY(bio, NULL, (pem_password_cb*)pwdCallback, pwdCallbackCtx);
+ pKey = PEM_read_bio_PUBKEY(bio, NULL,
+ XMLSEC_PTR_TO_FUNC(pem_password_cb, pwdCallback),
+ pwdCallbackCtx);
if(pKey == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
@@ -270,7 +288,9 @@ xmlSecOpenSSLAppKeyLoadBIO(BIO* bio, xmlSecKeyDataFormat format,
break;
case xmlSecKeyDataFormatPkcs8Pem:
/* try to read private key first */
- pKey = PEM_read_bio_PrivateKey(bio, NULL, (pem_password_cb*)pwdCallback, pwdCallbackCtx);
+ pKey = PEM_read_bio_PrivateKey(bio, NULL,
+ XMLSEC_PTR_TO_FUNC(pem_password_cb, pwdCallback),
+ pwdCallbackCtx);
if(pKey == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
@@ -282,7 +302,9 @@ xmlSecOpenSSLAppKeyLoadBIO(BIO* bio, xmlSecKeyDataFormat format,
break;
case xmlSecKeyDataFormatPkcs8Der:
/* try to read private key first */
- pKey = d2i_PKCS8PrivateKey_bio(bio, NULL, (pem_password_cb*)pwdCallback, pwdCallbackCtx);
+ pKey = d2i_PKCS8PrivateKey_bio(bio, NULL,
+ XMLSEC_PTR_TO_FUNC(pem_password_cb, pwdCallback),
+ pwdCallbackCtx);
if(pKey == NULL) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
@@ -1513,7 +1535,7 @@ xmlSecOpenSSLAppSaveRANDFile(const char *file) {
*/
void*
xmlSecOpenSSLAppGetDefaultPwdCallback(void) {
- return((void*)xmlSecOpenSSLDefaultPasswordCallback);
+ return XMLSEC_FUNC_TO_PTR(pem_password_cb, xmlSecOpenSSLDefaultPasswordCallback);
}
static int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]