From 00c9fa8f2d69d15a2e4183e127b543a92fb5f4b8 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 30 Jan 2013 15:35:40 +0100 Subject: GlueGen: NativeLibrary Fix, JNILibLoaderBase Enhancement - NativeLibrary Fix - enumerateLibraryPaths(..): - Properly iterate through all prefix _and_ suffix. - Make public for JNILibLoaderBase.loadLibraryInternal(..) - isValidNativeLibraryName(..): - Stop iterating through prefix, if previously found but suffix doesn't match. - JNILibLoaderBase.loadLibraryInternal(..) Enhancement - Mark customLibLoader FIXME: remove (we will get rid of jnlp.launcher.class) - If System.load(TempJarCache) and System.loadLibrary(plainLibName) fails, use NativeLibrary.enumerateLibraryPaths() w/ System.load(..) as last resort. Tested on Linux x86_64 Java6 and OSX Java7 manually, no regressions expected. --- src/java/com/jogamp/common/os/NativeLibrary.java | 112 +++++++++++++---------- 1 file changed, 64 insertions(+), 48 deletions(-) (limited to 'src/java/com/jogamp/common/os/NativeLibrary.java') diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java index f5265af..49ec860 100755 --- a/src/java/com/jogamp/common/os/NativeLibrary.java +++ b/src/java/com/jogamp/common/os/NativeLibrary.java @@ -174,13 +174,13 @@ public class NativeLibrary implements DynamicLookupHelper { macOSXLibName, searchSystemPathFirst, loader); + Platform.initSingleton(); // loads native gluegen-rt library // Iterate down these and see which one if any we can actually find. for (Iterator iter = possiblePaths.iterator(); iter.hasNext(); ) { String path = iter.next(); if (DEBUG) { System.err.println("NativeLibrary.open(): Trying to load " + path); } - Platform.initSingleton(); // loads native gluegen-rt library long res; if(global) { res = dynLink.openLibraryGlobal(path, DEBUG); @@ -254,18 +254,22 @@ public class NativeLibrary implements DynamicLookupHelper { * @return basename of libName w/o path, ie. /usr/lib/libDrinkBeer.so -> DrinkBeer on Unix systems, but null on Windows. */ public static String isValidNativeLibraryName(String libName, boolean isLowerCaseAlready) { - libName = IOUtil.getBasename(libName); - final String libNameLC = isLowerCaseAlready ? libName : libName.toLowerCase(); - for(int i=0; i prefixIdx; i++) { + if (libBaseNameLC.startsWith(prefixes[i])) { + prefixIdx = i; + } + } + if( 0 <= prefixIdx ) { + for(int i=0; i enumerateLibraryPaths(String windowsLibName, + public static List enumerateLibraryPaths(String windowsLibName, String unixLibName, String macOSXLibName, boolean searchSystemPathFirst, @@ -372,46 +376,58 @@ public class NativeLibrary implements DynamicLookupHelper { } private static String[] buildNames(String libName) { - // If the library name already has the prefix / suffix added - // (principally because we want to force a version number on Unix - // operating systems) then just return the library name. - if (libName.startsWith(prefixes[0])) { - if (libName.endsWith(suffixes[0])) { - return new String[] { libName }; + // If the library name already has the prefix / suffix added + // (principally because we want to force a version number on Unix + // operating systems) then just return the library name. + final String libBaseNameLC = IOUtil.getBasename(libName).toLowerCase(); + + int prefixIdx = -1; + for(int i=0; i prefixIdx; i++) { + if (libBaseNameLC.startsWith(prefixes[i])) { + prefixIdx = i; + } } - - int idx = libName.indexOf(suffixes[0]); - boolean ok = true; - if (idx >= 0) { - // Check to see if everything after it is a Unix version number - for (int i = idx + suffixes[0].length(); - i < libName.length(); - i++) { - char c = libName.charAt(i); - if (!(c == '.' || (c >= '0' && c <= '9'))) { - ok = false; - break; + if( 0 <= prefixIdx ) { + for(int i=0; i suffixIdx; i++) { + suffixIdx = libBaseNameLC.indexOf(suffixes[i]); + } + boolean ok = true; + if (suffixIdx >= 0) { + // Check to see if everything after it is a Unix version number + for (int i = suffixIdx + suffixes[0].length(); + i < libName.length(); + i++) { + char c = libName.charAt(i); + if (!(c == '.' || (c >= '0' && c <= '9'))) { + ok = false; + break; + } + } + if (ok) { + return new String[] { libName }; + } } - } - if (ok) { - return new String[] { libName }; - } } - } - String[] res = new String[prefixes.length * suffixes.length + - ( PlatformPropsImpl.OS_TYPE == Platform.OSType.MACOS ? 1 : 0 )]; - int idx = 0; - for (int i = 0; i < prefixes.length; i++) { - for (int j = 0; j < suffixes.length; j++) { - res[idx++] = prefixes[i] + libName + suffixes[j]; + String[] res = new String[prefixes.length * suffixes.length + + ( PlatformPropsImpl.OS_TYPE == Platform.OSType.MACOS ? 1 : 0 )]; + int idx = 0; + for (int i = 0; i < prefixes.length; i++) { + for (int j = 0; j < suffixes.length; j++) { + res[idx++] = prefixes[i] + libName + suffixes[j]; + } } - } - if (PlatformPropsImpl.OS_TYPE == Platform.OSType.MACOS) { - // Plain library-base-name in Framework folder - res[idx++] = libName; - } - return res; + if (PlatformPropsImpl.OS_TYPE == Platform.OSType.MACOS) { + // Plain library-base-name in Framework folder + res[idx++] = libName; + } + return res; } private static void addPaths(String path, String[] baseNames, List paths) { -- cgit v1.2.3