Skip to content

Commit

Permalink
improve win32 dependent library loading
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.java.net/svn/jna~svn/trunk@723 2f8a963e-d2e4-e7d0-97bf-ccb7fcea9d80
  • Loading branch information
twall committed Sep 22, 2008
1 parent 1a17ea5 commit 93ebb9f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
6 changes: 5 additions & 1 deletion jnalib/native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ FFI_CONFIG=--enable-static --disable-shared --with-pic=yes
endif
LIBRARY=$(BUILD)/$(LIBPFX)jnidispatch$(JNISFX)
TESTLIB=$(BUILD)/$(LIBPFX)testlib$(LIBSFX)
TESTLIB2=$(BUILD)/$(LIBPFX)testlib2$(LIBSFX)

# Reasonable defaults based on GCC
LIBPFX=lib
Expand Down Expand Up @@ -213,7 +214,7 @@ else
$(CC) $(CFLAGS) -c $< $(COUT)
endif

all: $(LIBRARY) $(TESTLIB)
all: $(LIBRARY) $(TESTLIB) $(TESTLIB2)

install:
mkdir $(INSTALLDIR)
Expand All @@ -229,6 +230,9 @@ $(LIBRARY): $(JNIDISPATCH_OBJS) $(FFI_LIB)
$(TESTLIB): $(BUILD)/testlib.o
$(LD) $(LDFLAGS) $< $(TESTDEF)

$(TESTLIB2): $(BUILD)/testlib2.o
$(LD) $(LDFLAGS) $< $(TESTDEF) $(TESTLIB)

ifneq ($(DYNAMIC_LIBFFI),true)
$(FFI_LIB):
@mkdir -p $(FFI_BUILD)
Expand Down
9 changes: 8 additions & 1 deletion jnalib/native/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
#endif
#define LIBNAMETYPE wchar_t*
#define LIBNAME2CSTR(ENV,JSTR) newWideCString(ENV,JSTR)
#define LOAD_LIBRARY(NAME) LoadLibraryW(NAME)
/* See http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx:
* "Note that the standard search strategy and the alternate search strategy
* specified by LoadLibraryEx with LOAD_WITH_ALTERED_SEARCH_PATH differ in
* just one way: The standard search begins in the calling application's
* directory, and the alternate search begins in the directory of the
* executable module that LoadLibraryEx is loading."
*/
#define LOAD_LIBRARY(NAME) LoadLibraryExW(NAME, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
#define LOAD_ERROR(BUF,LEN) w32_format_error(BUF, LEN)
#define FREE_LIBRARY(HANDLE) FreeLibrary(HANDLE)
#define FIND_ENTRY(HANDLE, NAME) GetProcAddress(HANDLE, NAME)
Expand Down
35 changes: 35 additions & 0 deletions jnalib/native/testlib2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p/>
* This library 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
* Lesser General Public License for more details.
*/

/* Simple library with a dependency. */
#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif

extern int returnFalse();

EXPORT int
dependentReturnFalse() {
return returnFalse();
}


#ifdef __cplusplus
}
#endif
7 changes: 7 additions & 0 deletions jnalib/release-notes.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<a name="top"></a>
<h2>Release 3.x.x</h2>
<b>Features</b><br>
<ul>
<li>Improve win32 loading of libraries with dependencies.
</ul>
<b>Bug Fixes</b><br>
<ul></ul>
<h2>Release 3.0.6</h2>
<b>Features</b><br>
<ul>
Expand Down
13 changes: 13 additions & 0 deletions jnalib/test/com/sun/jna/LibraryLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ public void testHandleObjectMethods() {
}
}

public interface TestLib2 extends Library {
int dependentReturnFalse();
}
public void testLoadDependentLibrary() {
try {
TestLib2 lib = (TestLib2)Native.loadLibrary("testlib2", TestLib2.class);
lib.dependentReturnFalse();
}
catch(UnsatisfiedLinkError e) {
fail("Failed to load dependent libraries: " + e);
}
}

public static void main(String[] args) {
junit.textui.TestRunner.run(LibraryLoadTest.class);
}
Expand Down

0 comments on commit 93ebb9f

Please sign in to comment.