From 7cc4bb2a8bcc4c16b6a12826abbd874bf38f9dc1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 8 Apr 2010 02:22:12 +0200 Subject: http://jogamp.org/bugzilla/show_bug.cgi?id=393 Fixed junit test: test1 - Create seperate native libraries to reflect a real world example: test1 - the library to bind to (no more declaring __stdcall @nn functions) BindingTest1p1 - the dynamic fixed linkage binding test1p1, references dynamic library test1 at linktime. BindingTest1p2 - the dynamic runtime linkage binding test1p2, loads dynamic library test1 at runtime. Generic: - gluegen-cpptasks-base.xml - target 'gluegen.cpptasks.detect.os' Set new property 'system.env.library.path' DYLD_LIBRARY_PATH (macosx) LD_LIBRARY_PATH (unix) PATH (windows) - target 'gluegen.cpptasks.striplibs' Strips the symbols out of the native libraries in case c.compiler.debug is false. Maybe configured with the properties: c.strip.tool, c.strip.args - Using system.env.library.path in junit call to find the test1 library in case of runtime linkage and lookup (test1p2). - Use gluegen.cpptasks.striplibs for all native libs .. - Added macosx32 in analogy to macosx64, both defaults to true now - com.jogamp.common.os.WindowsDynamicLinkerImpl:lookupSymbol() - Added lookup for __stdcall @nn (stepping alignment 4, max-args: 12) in case no undecorated __cdecl symbol is found. Fixed Windows platform: - Use proper path.seperator on Windows. - test1.dll needs proper soname inside for fixed linkage (test1p1) hence the output name must be test1.dll, not libtest1.so +++ http://jogamp.org/bugzilla/show_bug.cgi?id=394 Fix MacOsX platform: The commit of cpptasks.jar, git hash 129e783741d91e9ee5cd7da5d5c962c32ec96b0b, broke the universal binary build on MacOSX. The above change used cpptasks-1.05b with a few patches in regards to crosscompilation, but missed one, which accepts the '-arch' argument for GccLinker undecorated. The new cpptasks.jar is vanilla 1.05b + cpptasks-1.0b5-darwin-patch.diff, the latter a more refined one. This version accepts the '-arch' argument undecorated on the darwin platform. +++ --- .../jogamp/common/os/WindowsDynamicLinkerImpl.java | 28 +++++++++++++- .../test/junit/generation/Test1p1JavaEmitter.java | 4 +- .../generation/Test1p2ProcAddressEmitter.java | 6 +-- .../jogamp/gluegen/test/junit/generation/test1.c | 44 +++++++++++----------- .../jogamp/gluegen/test/junit/generation/test1.h | 20 ++++++++-- 5 files changed, 71 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java index f5a3312..2858f74 100755 --- a/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java +++ b/src/java/com/jogamp/common/os/WindowsDynamicLinkerImpl.java @@ -2,9 +2,20 @@ package com.jogamp.common.os; +import java.security.*; public class WindowsDynamicLinkerImpl implements DynamicLinker { + private static boolean DEBUG; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + DEBUG = (System.getProperty("gluegen.debug.NativeLibrary") != null); + return null; + } + }); + } /** Interface to C language function:
BOOL FreeLibrary(HANDLE hLibModule); */ private static native int FreeLibrary(long hLibModule); @@ -36,7 +47,22 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker { } public long lookupSymbol(long libraryHandle, String symbolName) { - return GetProcAddressA(libraryHandle, symbolName); + String _symbolName = symbolName; + long addr = GetProcAddressA(libraryHandle, _symbolName); + if(0==addr) { + // __stdcall hack: try some @nn decorations, + // the leading '_' must not be added (same with cdecl) + final int argAlignment=4; // 4 byte alignment of each argument + final int maxArguments=12; // experience .. + for(int arg=0; 0==addr && arg<=maxArguments; arg++) { + _symbolName = symbolName+"@"+(arg*argAlignment); + addr = GetProcAddressA(libraryHandle, _symbolName); + } + } + if(DEBUG) { + System.err.println("WindowsDynamicLinkerImpl.lookupSymbol(0x"+Long.toHexString(libraryHandle)+", "+symbolName+") -> "+_symbolName+", 0x"+Long.toHexString(addr)); + } + return addr; } public void closeLibrary(long libraryHandle) { diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java index 6320f92..7e8ef49 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java @@ -65,8 +65,8 @@ public class Test1p1JavaEmitter extends BaseTest1 { */ @Test public void chapter01TestLoadLibrary() throws Exception { - String nativesPath = testOutput + "/build/natives"; - System.load(nativesPath + "/libtest1p1.so"); + //System.loadLibrary("test1"); + System.loadLibrary("BindingTest1p1"); } /** diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java index 83f20d1..2d2cca3 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java @@ -69,9 +69,9 @@ public class Test1p2ProcAddressEmitter extends BaseTest1 { */ @Test public void chapter01TestLoadLibrary() throws Exception { - System.loadLibrary("test1p2"); - dynamicLookupHelper = NativeLibrary.open("test1p2", getClass().getClassLoader(), true); - Assert.assertNotNull("NativeLibrary.open(test1p2) failed", dynamicLookupHelper); + System.loadLibrary("BindingTest1p2"); + dynamicLookupHelper = NativeLibrary.open("test1", getClass().getClassLoader(), true); + Assert.assertNotNull("NativeLibrary.open(test1) failed", dynamicLookupHelper); BindingTest1p2Impl.resetProcAddressTable(dynamicLookupHelper); } diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c index f654467..d74cfc6 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c @@ -1,14 +1,16 @@ +#define __MYAPI_EXPORT_ 1 #include "test1.h" + #include #include #include #include -foo nopTest() { +MYAPI foo MYAPIENTRY nopTest() { return 42; } -int32_t arrayTestInt32(int64_t context, int32_t * array) { +MYAPI int32_t MYAPIENTRY arrayTestInt32(int64_t context, int32_t * array) { int32_t r=0; int i; assert(NULL!=array); @@ -20,7 +22,7 @@ int32_t arrayTestInt32(int64_t context, int32_t * array) { return r+context; } -int64_t arrayTestInt64(int64_t context, int64_t * array) { +MYAPI int64_t MYAPIENTRY arrayTestInt64(int64_t context, int64_t * array) { int64_t r=0; int i; assert(NULL!=array); @@ -32,7 +34,7 @@ int64_t arrayTestInt64(int64_t context, int64_t * array) { return r+context; } -foo * arrayTestFoo2( foo * array ) { +MYAPI foo * MYAPIENTRY arrayTestFoo2( foo * array ) { int i; foo * result = calloc(ARRAY_SIZE, sizeof(foo)); assert(NULL!=array); @@ -43,7 +45,7 @@ foo * arrayTestFoo2( foo * array ) { return result; } -foo * * arrayTestFoo3ArrayToPtrPtr(foo * array) { +MYAPI foo * * MYAPIENTRY arrayTestFoo3ArrayToPtrPtr(foo * array) { int j; foo * * result = calloc(ARRAY_SIZE, sizeof(foo *)); for(j=0; j