summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2010-06-13 15:27:29 +0200
committerAndreas Baumann <abaumann@yahoo.com>2010-06-13 15:27:29 +0200
commit00c6e3575d56e982e3528c43d73eb588ff3ff7ac (patch)
treed206ba1bdf75a009d07d8d4f29a806559d6d7b1d
parent5c8df05a029bd9616d517945153a95c6eefc8025 (diff)
downloadwolfbones-00c6e3575d56e982e3528c43d73eb588ff3ff7ac.tar.gz
wolfbones-00c6e3575d56e982e3528c43d73eb588ff3ff7ac.tar.bz2
renamed wolf_library_get_func to wolf_library_get as we can load
variables in DLLs added tests for variables and structs in DLLs (Windows)
-rw-r--r--include/wolf/library/loader.h7
-rw-r--r--makefiles/nmake/config.mk4
-rw-r--r--src/library/loader.c2
-rw-r--r--tests/library/Makefile.W322
-rw-r--r--tests/library/test_loader.c41
-rw-r--r--tests/library/testlib.c14
6 files changed, 62 insertions, 8 deletions
diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h
index 2f37da2..585851d 100644
--- a/include/wolf/library/loader.h
+++ b/include/wolf/library/loader.h
@@ -108,8 +108,9 @@ wolf_error_t wolf_library_unload( wolf_library_p library );
char *wolf_library_error_msg( const wolf_library_p library, char *buf, size_t buflen );
/**
- * Gets a symbol (a function) from the library object. It has to be
- * casted properly to the function you are expecting to call using
+ * Gets a symbol from the library object. It has either to be properly
+ * cast to the variable to use or has to be cast to the function you are
+ * expecting to call by using
* WOLF_LIBRARY_FUNC_CAST( symbol, func_t, func ).
*
* @param library the library object
@@ -118,7 +119,7 @@ char *wolf_library_error_msg( const wolf_library_p library, char *buf, size_t bu
*
* @return a pointer to the retrieved symbol
*/
-WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p library, const char *name, wolf_error_t *error );
+WOLF_LIBRARY_FUNCPTR wolf_library_get( const wolf_library_p library, const char *name, wolf_error_t *error );
/** @} */ /* @addtogroup wolf_library */
diff --git a/makefiles/nmake/config.mk b/makefiles/nmake/config.mk
index 51a5aef..60349ce 100644
--- a/makefiles/nmake/config.mk
+++ b/makefiles/nmake/config.mk
@@ -13,9 +13,9 @@
# newer versions of Visual Studio integrate the header files of the SDK
# some versions of Visual Studio miss the mc.exe binary
-PLATFORM_SDK_DIR = C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2
+#PLATFORM_SDK_DIR = C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2
#PLATFORM_SDK_DIR = C:\Programme\Microsoft Platform SDK for Windows Server 2003 R2
-#PLATFORM_SDK_DIR = D:\Programme\Microsoft Platform SDK
+PLATFORM_SDK_DIR = D:\Programme\Microsoft Platform SDK
# OpenSSL (http://www.slproweb.com/products/Win32OpenSSL.html)
##############################################################
diff --git a/src/library/loader.c b/src/library/loader.c
index ec4c53b..dbf0fe5 100644
--- a/src/library/loader.c
+++ b/src/library/loader.c
@@ -138,7 +138,7 @@ char *wolf_library_error_msg( const wolf_library_p library, char *buf, size_t b
return buf;
}
-WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p l, const char *name, wolf_error_t *error ) {
+WOLF_LIBRARY_FUNCPTR wolf_library_get( const wolf_library_p l, const char *name, wolf_error_t *error ) {
WOLF_LIBRARY_FUNCPTR ret;
#if !defined _WIN32
WOLF_LIBRARY_DLERROR_CONST char *err = NULL;
diff --git a/tests/library/Makefile.W32 b/tests/library/Makefile.W32
index 168705d..0ef5a2f 100644
--- a/tests/library/Makefile.W32
+++ b/tests/library/Makefile.W32
@@ -35,4 +35,4 @@ local_distclean:
local_test: $(LIBRARIES)
@echo Testing loading of a library and executing a function therein..
- @test_loader 2>NUL
+ @test_loader 1>NUL 2>NUL
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c
index 37b549b..60f2514 100644
--- a/tests/library/test_loader.c
+++ b/tests/library/test_loader.c
@@ -27,6 +27,16 @@
#define LIBRARY_NAME "./testlib.so.0.0.0"
#endif
#define LIBRARY_FUNC "multiply_by_two"
+#define LIBRARY_VAR "seven"
+#define LIBRARY_STRUCT "mod_descr"
+
+typedef int (*multiply_by_two_func)( int );
+
+typedef struct {
+ int major;
+ int minor;
+ multiply_by_two_func func;
+} module_descriptor_t;
int main( void ) {
wolf_library_p library;
@@ -36,6 +46,8 @@ int main( void ) {
WOLF_LIBRARY_FUNCPTR symbol;
multiply_by_two_func func;
int res = 0;
+ int *var;
+ module_descriptor_t *mod_descr;
/* open the libray */
library = wolf_library_load( LIBRARY_NAME, &error );
@@ -49,7 +61,7 @@ int main( void ) {
}
/* fetch a known function symbol (multiply_by_two) */
- symbol = wolf_library_get_func( library, LIBRARY_FUNC, &error );
+ symbol = wolf_library_get( library, LIBRARY_FUNC, &error );
if( error != WOLF_OK ) {
fprintf( stderr, "Error %d (%s) fetching function '%s' from the library\n",
error, wolf_error_msg( error, errbuf, 512 ), LIBRARY_FUNC );
@@ -62,8 +74,35 @@ int main( void ) {
/* call it */
res = func( 7 );
+ printf( "func(7) = %d\n", res );
assert( res == 14 );
+ /* fetch address as address to a variable (seven) */
+ var = (int *)wolf_library_get( library, LIBRARY_VAR, &error );
+ if( error != WOLF_OK ) {
+ fprintf( stderr, "Error %d (%s) fetching variable '%s' from the library\n",
+ error, wolf_error_msg( error, errbuf, 512 ), LIBRARY_VAR );
+ fprintf( stderr, "Internal loader error: %s\n",
+ wolf_library_error_msg( library, errbuf, 512 ) );
+ (void)wolf_library_unload( library );
+ return EXIT_FAILURE;
+ }
+ printf( "var = %d\n", *var );
+ assert( *var == 7 );
+
+ /* fetch something complex (in this case something like a module descriptor) */
+ mod_descr = (module_descriptor_t *)wolf_library_get( library, LIBRARY_STRUCT, &error );
+ if( error != WOLF_OK ) {
+ fprintf( stderr, "Error %d (%s) fetching structure '%s' from the library\n",
+ error, wolf_error_msg( error, errbuf, 512 ), LIBRARY_STRUCT );
+ fprintf( stderr, "Internal loader error: %s\n",
+ wolf_library_error_msg( library, errbuf, 512 ) );
+ (void)wolf_library_unload( library );
+ return EXIT_FAILURE;
+ }
+ printf( "module version: %d.%d\n", mod_descr->major, mod_descr->minor );
+ assert( mod_descr->major == 1 && mod_descr->minor == 0 );
+
/* close library */
error = wolf_library_unload( library );
if( error != WOLF_OK ) {
diff --git a/tests/library/testlib.c b/tests/library/testlib.c
index b240819..cd42d1a 100644
--- a/tests/library/testlib.c
+++ b/tests/library/testlib.c
@@ -4,8 +4,22 @@
#define DLLEXPORT
#endif
+typedef int (*multiply_by_two_func)( int );
+
DLLEXPORT int multiply_by_two( int a );
int multiply_by_two( int a ) {
return a * 2;
}
+
+extern int DLLEXPORT seven = 7;
+
+typedef struct {
+ int major;
+ int minor;
+ multiply_by_two_func func;
+} module_descriptor_t;
+
+extern DLLEXPORT module_descriptor_t mod_descr = {
+ 1, 0, &multiply_by_two
+};