diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-05-19 08:47:44 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-05-19 08:47:44 +0200 |
commit | 88221f3b5fb7f2d824e367bf565b71640dedc8f9 (patch) | |
tree | 6dbba2a984c20c2bf02bbc399ff6235a960b1ded /tests | |
parent | 6b862d85083cec0b2b028970c420f855b6d1de4f (diff) | |
download | wolfbones-88221f3b5fb7f2d824e367bf565b71640dedc8f9.tar.gz wolfbones-88221f3b5fb7f2d824e367bf565b71640dedc8f9.tar.bz2 |
fixed the function dlsym casting problem
Diffstat (limited to 'tests')
-rw-r--r-- | tests/library/test_loader.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index b9bce9d..7e5fa28 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -26,6 +26,8 @@ int main( void ) { wolf_error_t error; char errbuf[512]; typedef int (*multiply_by_two_func)( int ); + union { multiply_by_two_func func; void *obj; } alias; + void *symbol; multiply_by_two_func func; int res = 0; @@ -37,8 +39,12 @@ int main( void ) { return EXIT_FAILURE; } - /* fetch a known symbol (multiply_by_two) */ - *(void **)(&func) = wolf_library_get( library, "multiply_by_two", &error ); + /* fetch a known function symbol (multiply_by_two), for the reasons why naive + * casting doesn't work, see: + * http://en.wikipedia.org/wiki/Dynamic_loading#cite_note-gcc-strict-aliasing-5 */ + symbol = wolf_library_get( library, "multiply_by_two", &error ); + alias.obj = symbol; + func = alias.func; /* call it */ res = func( 2 ); |