Found a work-around for gcc warning about type-punning.

git-svn-id: https://shellinabox.googlecode.com/svn/trunk@29 0da03de8-d603-11dd-86c2-0f8696b7b6f9
This commit is contained in:
zodiac 2009-01-05 20:42:07 +00:00
parent 632460dbbe
commit 48a3768baa
2 changed files with 52 additions and 46 deletions

View file

@ -163,48 +163,51 @@ static void *loadSymbol(const char *lib, const char *fn) {
static void loadSSL(void) { static void loadSSL(void) {
check(!SSL_library_init); check(!SSL_library_init);
struct { struct {
void **var; union {
void *avoid_gcc_warning_about_type_punning;
void **var;
};
const char *fn; const char *fn;
} symbols[] = { } symbols[] = {
{ (void **)&x_BIO_ctrl, "BIO_ctrl" }, { { &x_BIO_ctrl }, "BIO_ctrl" },
{ (void **)&x_BIO_f_buffer, "BIO_f_buffer" }, { { &x_BIO_f_buffer }, "BIO_f_buffer" },
{ (void **)&x_BIO_free_all, "BIO_free_all" }, { { &x_BIO_free_all }, "BIO_free_all" },
{ (void **)&x_BIO_new, "BIO_new" }, { { &x_BIO_new }, "BIO_new" },
{ (void **)&x_BIO_new_socket, "BIO_new_socket" }, { { &x_BIO_new_socket }, "BIO_new_socket" },
{ (void **)&x_BIO_pop, "BIO_pop" }, { { &x_BIO_pop }, "BIO_pop" },
{ (void **)&x_BIO_push, "BIO_push" }, { { &x_BIO_push }, "BIO_push" },
{ (void **)&x_ERR_clear_error, "ERR_clear_error" }, { { &x_ERR_clear_error }, "ERR_clear_error" },
{ (void **)&x_ERR_clear_error, "ERR_clear_error" }, { { &x_ERR_clear_error }, "ERR_clear_error" },
{ (void **)&x_ERR_peek_error, "ERR_peek_error" }, { { &x_ERR_peek_error }, "ERR_peek_error" },
{ (void **)&x_ERR_peek_error, "ERR_peek_error" }, { { &x_ERR_peek_error }, "ERR_peek_error" },
{ (void **)&x_SSL_CTX_callback_ctrl, "SSL_CTX_callback_ctrl" }, { { &x_SSL_CTX_callback_ctrl }, "SSL_CTX_callback_ctrl" },
{ (void **)&x_SSL_CTX_check_private_key, "SSL_CTX_check_private_key" }, { { &x_SSL_CTX_check_private_key }, "SSL_CTX_check_private_key" },
{ (void **)&x_SSL_CTX_ctrl, "SSL_CTX_ctrl" }, { { &x_SSL_CTX_ctrl }, "SSL_CTX_ctrl" },
{ (void **)&x_SSL_CTX_free, "SSL_CTX_free" }, { { &x_SSL_CTX_free }, "SSL_CTX_free" },
{ (void **)&x_SSL_CTX_new, "SSL_CTX_new" }, { { &x_SSL_CTX_new }, "SSL_CTX_new" },
{ (void **)&x_SSL_CTX_use_PrivateKey_file, "SSL_CTX_use_PrivateKey_file" }, { { &x_SSL_CTX_use_PrivateKey_file }, "SSL_CTX_use_PrivateKey_file" },
{ (void **)&x_SSL_CTX_use_certificate_file,"SSL_CTX_use_certificate_file"}, { { &x_SSL_CTX_use_certificate_file },"SSL_CTX_use_certificate_file"},
{ (void **)&x_SSL_ctrl, "SSL_ctrl" }, { { &x_SSL_ctrl }, "SSL_ctrl" },
{ (void **)&x_SSL_free, "SSL_free" }, { { &x_SSL_free }, "SSL_free" },
{ (void **)&x_SSL_get_error, "SSL_get_error" }, { { &x_SSL_get_error }, "SSL_get_error" },
{ (void **)&x_SSL_get_ex_data, "SSL_get_ex_data" }, { { &x_SSL_get_ex_data }, "SSL_get_ex_data" },
{ (void **)&x_SSL_get_rbio, "SSL_get_rbio" }, { { &x_SSL_get_rbio }, "SSL_get_rbio" },
#ifdef TLSEXT_NAMETYPE_host_name #ifdef TLSEXT_NAMETYPE_host_name
{ (void **)&x_SSL_get_servername, "SSL_get_servername" }, { { &x_SSL_get_servername }, "SSL_get_servername" },
#endif #endif
{ (void **)&x_SSL_get_wbio, "SSL_get_wbio" }, { { &x_SSL_get_wbio }, "SSL_get_wbio" },
{ (void **)&x_SSL_library_init, "SSL_library_init" }, { { &x_SSL_library_init }, "SSL_library_init" },
{ (void **)&x_SSL_new, "SSL_new" }, { { &x_SSL_new }, "SSL_new" },
{ (void **)&x_SSL_read, "SSL_read" }, { { &x_SSL_read }, "SSL_read" },
#ifdef TLSEXT_NAMETYPE_host_name #ifdef TLSEXT_NAMETYPE_host_name
{ (void **)&x_SSL_set_SSL_CTX, "SSL_set_SSL_CTX" }, { { &x_SSL_set_SSL_CTX }, "SSL_set_SSL_CTX" },
#endif #endif
{ (void **)&x_SSL_set_accept_state, "SSL_set_accept_state" }, { { &x_SSL_set_accept_state }, "SSL_set_accept_state" },
{ (void **)&x_SSL_set_bio, "SSL_set_bio" }, { { &x_SSL_set_bio }, "SSL_set_bio" },
{ (void **)&x_SSL_set_ex_data, "SSL_set_ex_data" }, { { &x_SSL_set_ex_data }, "SSL_set_ex_data" },
{ (void **)&x_SSL_shutdown, "SSL_shutdown" }, { { &x_SSL_shutdown }, "SSL_shutdown" },
{ (void **)&x_SSL_write, "SSL_write" }, { { &x_SSL_write }, "SSL_write" },
{ (void **)&x_SSLv23_server_method, "SSLv23_server_method" } { { &x_SSLv23_server_method }, "SSLv23_server_method" }
}; };
for (int i = 0; i < sizeof(symbols)/sizeof(symbols[0]); i++) { for (int i = 0; i < sizeof(symbols)/sizeof(symbols[0]); i++) {
if (!(*symbols[i].var = loadSymbol("libssl.so", symbols[i].fn))) { if (!(*symbols[i].var = loadSymbol("libssl.so", symbols[i].fn))) {

View file

@ -125,19 +125,22 @@ static void loadPAM(void) {
check(!x_pam_start); check(!x_pam_start);
check(!x_misc_conv); check(!x_misc_conv);
struct { struct {
void **var; union {
void *avoid_gcc_warning_about_type_punning;
void **var;
};
const char *lib; const char *lib;
const char *fn; const char *fn;
} symbols[] = { } symbols[] = {
{ (void **)&x_pam_acct_mgmt, "libpam.so", "pam_acct_mgmt" }, { { &x_pam_acct_mgmt }, "libpam.so", "pam_acct_mgmt" },
{ (void **)&x_pam_authenticate, "libpam.so", "pam_authenticate" }, { { &x_pam_authenticate }, "libpam.so", "pam_authenticate" },
{ (void **)&x_pam_close_session, "libpam.so", "pam_close_session" }, { { &x_pam_close_session }, "libpam.so", "pam_close_session" },
{ (void **)&x_pam_end, "libpam.so", "pam_end" }, { { &x_pam_end }, "libpam.so", "pam_end" },
{ (void **)&x_pam_get_item, "libpam.so", "pam_get_item" }, { { &x_pam_get_item }, "libpam.so", "pam_get_item" },
{ (void **)&x_pam_open_session, "libpam.so", "pam_open_session" }, { { &x_pam_open_session }, "libpam.so", "pam_open_session" },
{ (void **)&x_pam_set_item, "libpam.so", "pam_set_item" }, { { &x_pam_set_item }, "libpam.so", "pam_set_item" },
{ (void **)&x_pam_start, "libpam.so", "pam_start" }, { { &x_pam_start }, "libpam.so", "pam_start" },
{ (void **)&x_misc_conv, "libpam_misc.so", "misc_conv" } { { &x_misc_conv }, "libpam_misc.so", "misc_conv" }
}; };
for (int i = 0; i < sizeof(symbols)/sizeof(symbols[0]); i++) { for (int i = 0; i < sizeof(symbols)/sizeof(symbols[0]); i++) {
if (!(*symbols[i].var = loadSymbol(symbols[i].lib, symbols[i].fn))) { if (!(*symbols[i].var = loadSymbol(symbols[i].lib, symbols[i].fn))) {