Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/twall/jna
Browse files Browse the repository at this point in the history
Pulling master back to get compilation fixes.
  • Loading branch information
hakanai committed May 7, 2013
2 parents 136653a + b1aa24d commit 6a06656
Show file tree
Hide file tree
Showing 36 changed files with 636 additions and 483 deletions.
Empty file modified .classpath
100755 → 100644
Empty file.
Empty file modified .project
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions CHANGES.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Features
* [#209](https://github.com/twall/jna/issues/209): Improve default performance saving last error results - [@twall](https://github.com/twall).
* Use predictable names for CPU arch prefix (namely x86, x86-64); names correspond to OSGI processor values - [@twall](https://github.com/twall).
* Avoid superfluous Structure memory allocation from native - [@twall](https://github.com/twall).
* Added `Library.OPTION_CLASSLOADER`, which enables loading native libraries from any class loader (including JNA's native library). This enables parallel dependencies on JNA (e.g. within a tomcat deployment without having to include JNA in the app server environment) - [@twall](https://github.com/twall).

Bug Fixes
---------
Expand All @@ -17,6 +18,7 @@ Bug Fixes
* [#215](https://github.com/twall/jna/issues/215): Force use of XSI `strerror_r` on linux - [LionelCons](https://github.com/LionelCons).
* [#214](https://github.com/twall/jna/issues/214): Don't map library names when an absolute path is provided - [@twall](https://github.com/twall).
* [#218](https://github.com/twall/jna/issues/218): Explicitly handle broken Android SecurityManager implementation - [@twall](https://github.com/twall).
* [#223](https://github.com/twall/jna/issues/223): Fix layout/size derivation for unions - [@twall](https://github.com/twall).

Release 3.5.2
=============
Expand Down
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified OTHERS
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Java Native Access (JNA)
========================

The definitive JNA reference (including an overview and usage details) is in the [JavaDoc](http://twall.github.com/jna/3.5.2/javadoc/). Please read the [overview](http://twall.github.com/jna/3.5.2/javadoc/overview-summary.html#overview_description).
The definitive JNA reference (including an overview and usage details) is in the [JavaDoc](http://twall.github.com/jna/3.5.2/javadoc/). Please read the [overview](http://twall.github.com/jna/3.5.2/javadoc/overview-summary.html#overview_description). Questions, comments, or exploratory conversations should begin on the [mailing list](http://groups.google.com/group/jna-users), although you may find it easier to find answers to already-solved problems on [StackOverflow](http://stackoverflow.com/questions/tagged/jna).

JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code—no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation.

Expand Down
70 changes: 39 additions & 31 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,51 @@
o arrays are treated as pointers, except within a struct
- in structure (inline; otherwise pointer-to-X should be used)
- as function argument (auto-convert to pointer via Memory)
o pointer to type in struct should use Pointer or ByReference
o pointer to type in struct should use PointerType or Structure.ByReference
o "free" should be invisible wherever possible

# FUTURE DEMOS:
* test keyboard keys' state (needs OSX)
* test keyboard keys' state (needs OSX impl)
* get system process information, basic process control
* additional file utilities (meta info, free space, etc)
* enforce window minimum/maximum size (workaround java bug)

# TODO

# DOCS: how to properly use W32API_DEFAULT_OPTIONS (A/W, String/WString)
* annotations/generics:
o GetPrimitiveArrayCritical: use this if flagged (by annotation? method name?)
o per-arg/return type marshalling
o avoid casts in loadLibrary
o wrap global variables w/type (set/get)
o support annotations of parameters and return values w/o breaking
1.4 compatibility (retroweaver?), e.g.
-- retroweaver (requires retroweaver runtime classes to provide annotation
features) not yet worth doing

* make native dll extraction from jar public, to use with user dlls packaged
in a jar
void my_function(@MarshalAs(off_t)long arg);

trading off cruft in the interface def to avoid cruft in the usage:

my_function(0) versus my_function(new off_t(0))

this only really applies to NativeLong/IntegerType types that want to use a
primitive value instead of creating an object instance.
o flag string(/wstring)-returning methods which need to free their result
to avoid leaking memory whan auto-creating strings from the result
(since normally we don't take explicit ownership of any returned pointers)
this is a special case for returned strings only, since other returned
pointers are available to the user for later "freeing"
Use a map on library creation, an iface for the library, or annotation
NOTE: how many methods actually do this? strdup...
Maybe make function return "Memory", which can then be converted to a
Structure or some other type. Then memory will free itself when no longer
referenced. (not really common)



* auto-generate direct mappings/bindings on a per-method basis (perform a
method register on first call to an interface-mapped function) with
sufficient pre-processing to convert to primitives.

* dispose memory/callbacks in Native finalizer to ensure they run first
(use referencequeue to run them when they become unreachable)
Expand All @@ -34,39 +64,13 @@
and forth multiple times). This also makes it easer to perform conversions
(no native changes required).

* GetPrimitiveArrayCritical: use this if flagged (by annotation? method name?)
* direct/raw non-primitive array arguments (String[], Pointer[], NativeMapped[])
* ppc64 direct/raw failures (multiple)
* direct calls on ppc to varargs (callbacks) with FP args fail; avoid them for
now
* combine direct and interface mapping calling code where possible
* Callback.PostCallWrite.write() cf PostCallRead
* eliminate type conversion contexts; these are almost entirely unused

* support annotations of parameters and return values w/o breaking
1.4 compatibility (retroweaver?), e.g.
-- retroweaver (requires retroweaver runtime classes to provide annotation
features) not yet worth doing

void my_function(@MarshalAs(off_t)long arg);

trading off cruft in the interface def to avoid cruft in the usage:

my_function(0) versus my_function(new off_t(0))

this only really applies to NativeLong/IntegerType types that want to use a
primitive value instead of creating an object instance.

* flag string(/wstring)-returning methods which need to free their result
to avoid leaking memory whan auto-creating strings from the result
(since normally we don't take explicit ownership of any returned pointers)
this is a special case for returned strings only, since other returned
pointers are available to the user for later "freeing"
Use a map on library creation, an iface for the library, or annotation
NOTE: how many methods actually do this? strdup...
Maybe make function return "Memory", which can then be converted to a
Structure or some other type. Then memory will free itself when no longer
referenced.
* universal GCC build w/cross-compile (needs cross compilers...)
* return Pointer.SIZE/LONG_SIZE/WCHAR_SIZE in bits (for consistency with 1.5)
Long.SIZE, Integer.SIZE, et al.
Expand All @@ -76,6 +80,10 @@


# DONE
* combine direct and interface mapping calling code where possible
* DOCS: how to properly use W32API_DEFAULT_OPTIONS (A/W, String/WString)
* make native dll extraction from jar public, to use with user dlls packaged
in a jar
* use consistent cpu references (x86->i386, x86_64->amd64)
* osgi for osx
* NO: make Pointer free-able (system allocates memory, client frees it); actually,
Expand Down
12 changes: 5 additions & 7 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,9 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
<src path="${test.src}"/>
<exclude name="${tests.exclude}"/>
</javac>
<!-- Set up versions of test library for resource path loading -->
<copy todir="${test.classes}/${os.prefix}">
<copy todir="${test.classes}">
<fileset dir="${build.native}">
<patternset>
<include name="**/*testlib-jar*"/>
<include name="**/*testlib-path*"/>
</patternset>
<include name="*testlib-jar*"/>
</fileset>
</copy>
<!-- Create a jar for easy movement of tests, and jar load test -->
Expand All @@ -741,7 +737,7 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
<include name="**/*testlib-jar*"/>
</fileset>
</jar>
<!-- Ensure jar-based library unavailable on FS-based class path -->
<!-- Ensure jar-based library is unavailable on FS-based class path -->
<delete>
<fileset dir="${test.classes}">
<include name="**/*testlib-jar*"/>
Expand Down Expand Up @@ -781,6 +777,8 @@ osname=macosx;processor=x86;processor=x86-64;processor=ppc
<copy todir="${shared}" file="${build.native}/jnidispatch.dll"/>
<copy todir="${shared}" file="${build.native}/testlib.dll"/>
<copy todir="${shared}" file="${build.native}/testlib2.dll"/>
<copy todir="${shared}" file="${build.native}/test-path.dll"/>
<copy todir="${shared}" file="${build.native}/testlib-truncated"/>
<copy todir="${shared}" file="w32ce-test.lnk"/>
<chmod file="${shared}/*.dll" perm="+x"/>
</target>
Expand Down
Empty file modified contrib/README
100755 → 100644
Empty file.
Empty file modified contrib/balloontips/README
100755 → 100644
Empty file.
19 changes: 7 additions & 12 deletions contrib/platform/test/com/sun/jna/platform/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testMoveToTrash() throws Exception {
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
File file = File.createTempFile(getName(), ".tmp", tmpdir);
try {
assertTrue("File should exist", file.exists());
assertTrue("Original source file missing: " + file, file.exists());
try {
utils.moveToTrash(new File[] { file });
}
Expand All @@ -38,9 +38,7 @@ public void testMoveToTrash() throws Exception {
assertFalse("File still exists after move to trash: " + file, file.exists());
}
finally {
if (file.exists()) {
file.delete();
}
file.delete();
}
}

Expand All @@ -55,9 +53,10 @@ public void testMoveSymlinkToTrash() throws Exception {
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
File file = File.createTempFile(getName(), ".tmp", tmpdir);
File symlink = new File(tmpdir, file.getName() + ".link");
Runtime.getRuntime().exec(new String[] { "ln", "-s", file.getAbsolutePath(), symlink.getAbsolutePath() });
try {
assertTrue("File should exist", symlink.exists());
Runtime.getRuntime().exec(new String[] { "ln", "-s", file.getAbsolutePath(), symlink.getAbsolutePath() });
assertTrue("Original source file missing: " + file, file.exists());
assertTrue("Symlink creation failed (missing): " + symlink, symlink.exists());
try {
utils.moveToTrash(new File[] { symlink });
}
Expand All @@ -68,12 +67,8 @@ public void testMoveSymlinkToTrash() throws Exception {
assertTrue("Original file should still exist after move to trash: " + file, file.exists());
}
finally {
if (symlink.exists()) {
symlink.delete();
}
if (file.exists()) {
file.delete();
}
symlink.delete();
file.delete();
}
}

Expand Down
4 changes: 4 additions & 0 deletions native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ HOST_CONFIG=--host=arm-mingw32ce
FFI_ENV+=LD=arm-mingw32ce-ld CPP=cpp CFLAGS="$(CDEFINES)"
PHONEME=../phoneme/cdc/src
JAVA_INCLUDES=-I$(PHONEME)/share/javavm/export -I$(PHONEME)/share -I$(PHONEME)/win32 -I$(PHONEME)/win32-arm
TESTLIB_TRUNC=$(BUILD)/testlib-truncated.dll
endif

ifeq ($(OS),win32)
Expand All @@ -158,6 +159,7 @@ EXTRAOBJS=$(RSRC)
STRIP=@echo
LIBPFX=
LIBSFX=.dll
TESTLIB_TRUNC=$(BUILD)/testlib-truncated.dll

ifneq ($(ARCH),amd64)
ifeq ($(CC),gcc)
Expand Down Expand Up @@ -367,6 +369,8 @@ $(LIBRARY): $(JNIDISPATCH_OBJS) $(FFI_LIB)
$(TESTLIB): $(BUILD)/testlib.o
$(LD) $(LDFLAGS) $< $(LIBS)

# These targets provide for different shared library loading methods
# without getting into native library load conflicts
$(TESTLIB_JAR) $(TESTLIB_PATH) $(TESTLIB_TRUNC): $(TESTLIB)
@cp $< $@

Expand Down
10 changes: 5 additions & 5 deletions native/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,23 +538,23 @@ static void make_thread_keys() {

/** Store the requested detach state for the current thread. */
void
jnidispatch_detach(jboolean d) {
JNA_detach(jboolean d) {
if (!TLS_SET(tls_detach_key, L2A((jlong)(d?THREAD_DETACH:THREAD_LEAVE_ATTACHED)))) {
fprintf(stderr, "JNA: unable to set thread-local detach value\n");
}
}

/** Store the value of errno/GetLastError in TLS */
void
jnidispatch_set_last_error(int err) {
JNA_set_last_error(int err) {
if (!TLS_SET(tls_errno_key, L2A((jlong)err))) {
fprintf(stderr, "JNA: unable to set thread-local errno value\n");
}
}

/** Store the value of errno/GetLastError in TLS */
int
jnidispatch_get_last_error() {
JNA_get_last_error() {
return (int)A2L(TLS_GET(tls_errno_key));
}

Expand Down Expand Up @@ -645,7 +645,7 @@ callback_dispatch(ffi_cif* cif, void* resp, void** cbargs, void* user_data) {
}

const char*
jnidispatch_callback_init(JNIEnv* env) {
JNA_callback_init(JNIEnv* env) {
#ifndef _WIN32
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
pthread_once(&key_once, make_thread_keys);
Expand All @@ -657,7 +657,7 @@ jnidispatch_callback_init(JNIEnv* env) {
}

void
jnidispatch_callback_dispose(JNIEnv* env) {
JNA_callback_dispose(JNIEnv* env) {
if (classObject) {
(*env)->DeleteWeakGlobalRef(env, classObject);
classObject = NULL;
Expand Down
Loading

0 comments on commit 6a06656

Please sign in to comment.