summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xinclude/wolf/port/dllexport.h34
-rw-r--r--src/library/loader.c10
-rw-r--r--tests/library/Makefile.W3211
-rw-r--r--tests/library/test_loader.c19
-rw-r--r--tests/library/testlib.c8
6 files changed, 80 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 51b4972..fc16c3e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,8 @@ makefiles/gmake/platform.mk.vars
*.a
*.lib
*.so.*
+*.dll
+*.exp
# binaries
tests/port/test_strdup
diff --git a/include/wolf/port/dllexport.h b/include/wolf/port/dllexport.h
new file mode 100755
index 0000000..06594ca
--- /dev/null
+++ b/include/wolf/port/dllexport.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2010 Andreas Baumann <abaumann@yahoo.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef WOLF_DLL_EXPORT_H
+#define WOLF_DLL_EXPORT_H
+
+#ifdef _WIN32
+#ifdef BUILD_SHARED
+#define WOLF_LIBEXPORT __declspec( dllexport )
+#define WOLF_PRIVATE __declspec( )
+#else
+#define WOLF_LIBEXPORT
+#define WOLF_PRIVATE
+#endif
+#else
+#define WOLF_LIBEXPORT
+#define WOLF_PRIVATE
+#endif
+
+#endif /* ifndef WOLF_DLL_EXPORT_H */
diff --git a/src/library/loader.c b/src/library/loader.c
index aa501e3..96141e0 100644
--- a/src/library/loader.c
+++ b/src/library/loader.c
@@ -135,9 +135,19 @@ WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p l, const char *
#if defined HAVE_DLFCN
ret = dlsym( l->handle, name );
+ if( ret == NULL ) {
+ strncpy( l->errbuf, dlerror( ), INTERNAL_ERRBUF_SIZE );
+ return WOLF_ERR_INTERNAL;
+ }
#else
#if defined _WIN32
ret = GetProcAddress( l->handle, name );
+ if( ret == NULL ) {
+ printf( "XXX: %d\n", GetLastError( ) );
+ strncpy( l->errbuf, "<TODO: GetLastError>", INTERNAL_ERRBUF_SIZE );
+ *error = WOLF_ERR_INTERNAL;
+ return ret;
+ }
#else
#error Not using DLFCN as shared loader. Port first!
#endif
diff --git a/tests/library/Makefile.W32 b/tests/library/Makefile.W32
index 4ebcab9..7c44d8d 100644
--- a/tests/library/Makefile.W32
+++ b/tests/library/Makefile.W32
@@ -13,11 +13,20 @@ INCLUDE_LIBS = \
TEST_BINS = \
test_loader.exe
+TEST_OBJS = \
+ testlib.obj
+
+TEST_LIBRARIES = \
+ testlib.dll
+
!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk
+testlib.dll: $(TEST_OBJS)
+ $(LINK) /DLL /nologo /out:$@ $(LDFLAGS) $(LIBS) $?
+
test_loader.exe: test_loader.obj $(TOPDIR)\src\wolf.lib
-local_all:
+local_all: $(TEST_LIBRARIES)
local_clean:
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c
index 0eef9f2..6fd5d2e 100644
--- a/tests/library/test_loader.c
+++ b/tests/library/test_loader.c
@@ -21,6 +21,12 @@
#include <stdio.h> /* for fprintf */
#include <assert.h> /* for assert */
+#ifdef _WIN32
+#define LIBRARY_NAME "testlib.dll"
+#else
+#define LIBRARY_NAME "./testlib.so.0.0.0"
+#endif
+
int main( void ) {
wolf_library_p library;
wolf_error_t error;
@@ -32,7 +38,7 @@ int main( void ) {
int res = 0;
/* open the libray */
- library = wolf_library_load( "./testlib.so.0.0.0", &error );
+ library = wolf_library_load( LIBRARY_NAME, &error );
if( error != WOLF_OK ) {
fprintf( stderr, "Error %d loading the library: %s\n",
error, wolf_library_errmsg( error, library, errbuf, 512 ) );
@@ -44,9 +50,18 @@ int main( void ) {
* http://en.wikipedia.org/wiki/Dynamic_loading
*/
symbol = wolf_library_get_func( library, "multiply_by_two", &error );
+ if( error != WOLF_OK ) {
+ fprintf( stderr, "Error %d fetching a function from the library: %s\n",
+ error, wolf_library_errmsg( error, library, errbuf, 512 ) );
+ return EXIT_FAILURE;
+ }
+#if !defined _WIN32
alias.obj = symbol;
func = alias.func;
-
+#else
+ func = (multiply_by_two_func)symbol;
+#endif
+
/* call it */
res = func( 7 );
assert( res == 14 );
diff --git a/tests/library/testlib.c b/tests/library/testlib.c
index f8e457a..b240819 100644
--- a/tests/library/testlib.c
+++ b/tests/library/testlib.c
@@ -1,4 +1,10 @@
-int multiply_by_two( int a );
+#ifdef _WIN32
+#define DLLEXPORT __declspec( dllexport )
+#else
+#define DLLEXPORT
+#endif
+
+DLLEXPORT int multiply_by_two( int a );
int multiply_by_two( int a ) {
return a * 2;