From 686ee56fc5e4b8a3573dbad3a0e997fe89ba71a7 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 18 May 2010 18:25:41 +0200 Subject: now stuck in dlsym/dereferencing type-punned pointer will break strict-aliasing rules beautiness :-) --- tests/library/test_loader.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index 6088c92..b9bce9d 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -19,12 +19,17 @@ #include /* for EXIT_SUCCESS, EXIT_FAILURE */ #include /* for fprintf */ +#include /* for assert */ int main( void ) { wolf_library_p library; wolf_error_t error; char errbuf[512]; + typedef int (*multiply_by_two_func)( int ); + multiply_by_two_func func; + int res = 0; + /* open the libray */ library = wolf_library_load( "./testlib.so.0.0.0", &error ); if( error != WOLF_OK ) { fprintf( stderr, "Error %d loading the library: %s\n", @@ -32,7 +37,20 @@ int main( void ) { return EXIT_FAILURE; } - wolf_library_unload( library ); + /* fetch a known symbol (multiply_by_two) */ + *(void **)(&func) = wolf_library_get( library, "multiply_by_two", &error ); + + /* call it */ + res = func( 2 ); + assert( res == 4 ); + + /* close library */ + error = wolf_library_unload( library ); + if( error != WOLF_OK ) { + fprintf( stderr, "Error %d unloading the library: %s\n", + error, wolf_library_errmsg( error, library, errbuf, 512 ) ); + return EXIT_FAILURE; + } return EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf