- Add patch to allow opening current process
This commit is contained in:
parent
365bfa6d3d
commit
0143857e96
98
jna-3.0.9-processopen.patch
Normal file
98
jna-3.0.9-processopen.patch
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
diff -ur jna-3.0.9/native/dispatch.c jna-3.0.9.process/native/dispatch.c
|
||||||
|
--- jna-3.0.9/native/dispatch.c 2008-09-22 11:55:59.000000000 -0400
|
||||||
|
+++ jna-3.0.9.process/native/dispatch.c 2008-12-30 17:03:22.000000000 -0500
|
||||||
|
@@ -641,14 +641,20 @@
|
||||||
|
void *handle = NULL;
|
||||||
|
LIBNAMETYPE libname = NULL;
|
||||||
|
|
||||||
|
- if ((libname = LIBNAME2CSTR(env, lib)) != NULL) {
|
||||||
|
- handle = (void *)LOAD_LIBRARY(libname);
|
||||||
|
- if (!handle) {
|
||||||
|
- char buf[1024];
|
||||||
|
- throwByName(env, EUnsatisfiedLink, LOAD_ERROR(buf, sizeof(buf)));
|
||||||
|
+ /* dlopen on Unix allows NULL to mean "current process" */
|
||||||
|
+ if (lib != NULL) {
|
||||||
|
+ if ((libname = LIBNAME2CSTR(env, lib)) == NULL) {
|
||||||
|
+ return (jlong)A2L(NULL);
|
||||||
|
}
|
||||||
|
- free(libname);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ handle = (void *)LOAD_LIBRARY(libname);
|
||||||
|
+ if (!handle) {
|
||||||
|
+ char buf[1024];
|
||||||
|
+ throwByName(env, EUnsatisfiedLink, LOAD_ERROR(buf, sizeof(buf)));
|
||||||
|
+ }
|
||||||
|
+ if (libname != NULL)
|
||||||
|
+ free(libname);
|
||||||
|
return (jlong)A2L(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
diff -ur jna-3.0.9/src/com/sun/jna/NativeLibrary.java jna-3.0.9.process/src/com/sun/jna/NativeLibrary.java
|
||||||
|
--- jna-3.0.9/src/com/sun/jna/NativeLibrary.java 2008-12-30 17:19:15.000000000 -0500
|
||||||
|
+++ jna-3.0.9.process/src/com/sun/jna/NativeLibrary.java 2008-12-30 17:17:45.000000000 -0500
|
||||||
|
@@ -45,6 +45,7 @@
|
||||||
|
private final String libraryPath;
|
||||||
|
private final Map functions = new HashMap();
|
||||||
|
|
||||||
|
+ private static WeakReference currentProcess;
|
||||||
|
private static final Map libraries = new HashMap();
|
||||||
|
private static final Map searchPaths = Collections.synchronizedMap(new HashMap());
|
||||||
|
private static final List librarySearchPath = new LinkedList();
|
||||||
|
@@ -196,6 +197,27 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
+ * Returns an instance of NativeLibrary which refers to the current process.
|
||||||
|
+ * This is useful for accessing functions which were already mapped by some
|
||||||
|
+ * other mechanism, without having to reference or even know the exact
|
||||||
|
+ * name of the native library.
|
||||||
|
+ */
|
||||||
|
+ public static synchronized final NativeLibrary getProcess() {
|
||||||
|
+ NativeLibrary library = null;
|
||||||
|
+ if (currentProcess != null) {
|
||||||
|
+ library = (NativeLibrary) currentProcess.get();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (library == null) {
|
||||||
|
+ long handle = open(null);
|
||||||
|
+ library = new NativeLibrary("<process>", null, handle);
|
||||||
|
+ currentProcess = new WeakReference(library);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return library;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
* Add a path to search for the specified library, ahead of any system paths
|
||||||
|
*
|
||||||
|
* @param libraryName The name of the library to use the path for
|
||||||
|
@@ -287,9 +309,13 @@
|
||||||
|
public String getName() {
|
||||||
|
return libraryName;
|
||||||
|
}
|
||||||
|
- /** Returns the file on disk corresponding to this NativeLibrary instacne.
|
||||||
|
+ /**
|
||||||
|
+ * Returns the file on disk corresponding to this NativeLibrary instance.
|
||||||
|
+ * If this NativeLibrary represents the current process, this function will return null.
|
||||||
|
*/
|
||||||
|
public File getFile() {
|
||||||
|
+ if (libraryPath == null)
|
||||||
|
+ return null;
|
||||||
|
return new File(libraryPath);
|
||||||
|
}
|
||||||
|
/** Close the library when it is no longer referenced. */
|
||||||
|
@@ -300,8 +326,11 @@
|
||||||
|
public void dispose() {
|
||||||
|
synchronized(libraries) {
|
||||||
|
libraries.remove(getName());
|
||||||
|
- libraries.remove(getFile().getAbsolutePath());
|
||||||
|
- libraries.remove(getFile().getName());
|
||||||
|
+ File path = getFile();
|
||||||
|
+ if (path != null) {
|
||||||
|
+ libraries.remove(path.getAbsolutePath());
|
||||||
|
+ libraries.remove(path.getName());
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
synchronized(this) {
|
||||||
|
if (handle != 0) {
|
8
jna.spec
8
jna.spec
@ -1,6 +1,6 @@
|
|||||||
Name: jna
|
Name: jna
|
||||||
Version: 3.0.9
|
Version: 3.0.9
|
||||||
Release: 2%{?dist}
|
Release: 3%{?dist}
|
||||||
Summary: Pure Java access to native libraries
|
Summary: Pure Java access to native libraries
|
||||||
|
|
||||||
Group: Development/Libraries
|
Group: Development/Libraries
|
||||||
@ -27,6 +27,8 @@ Patch3: jna-3.0.4-nativemapped-array.patch
|
|||||||
Patch5: jna-callback-exception.patch
|
Patch5: jna-callback-exception.patch
|
||||||
# https://jna.dev.java.net/issues/show_bug.cgi?id=95
|
# https://jna.dev.java.net/issues/show_bug.cgi?id=95
|
||||||
Patch6: jna-3.0.9-linux-nomaplibrary.patch
|
Patch6: jna-3.0.9-linux-nomaplibrary.patch
|
||||||
|
# https://jna.dev.java.net/issues/show_bug.cgi?id=98
|
||||||
|
Patch7: jna-3.0.9-processopen.patch
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
|
||||||
|
|
||||||
BuildRequires: java-devel >= 1.6 ant jpackage-utils ant-nodeps
|
BuildRequires: java-devel >= 1.6 ant jpackage-utils ant-nodeps
|
||||||
@ -61,6 +63,7 @@ sed -e 's|@JNIPATH@|%{_libdir}/%{name}|' %{PATCH1} | patch -p1
|
|||||||
%patch3 -p1 -b .nativemapped-array
|
%patch3 -p1 -b .nativemapped-array
|
||||||
#%patch5 -p1 -b .callback-exception
|
#%patch5 -p1 -b .callback-exception
|
||||||
%patch6 -p1 -b .linux-nomaplibrary
|
%patch6 -p1 -b .linux-nomaplibrary
|
||||||
|
%patch7 -p1 -b .processopen
|
||||||
|
|
||||||
# all java binaries must be removed from the sources
|
# all java binaries must be removed from the sources
|
||||||
find . -name '*.jar' -exec rm -f '{}' \;
|
find . -name '*.jar' -exec rm -f '{}' \;
|
||||||
@ -114,6 +117,9 @@ rm -rf %{buildroot}
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Dec 30 2008 Colin Walters <walters@redhat.com> - 3.0.9-3
|
||||||
|
- Add patch to allow opening current process
|
||||||
|
|
||||||
* Sun Nov 30 2008 Colin Walters <walters@redhat.com> - 3.0.9-2
|
* Sun Nov 30 2008 Colin Walters <walters@redhat.com> - 3.0.9-2
|
||||||
- Fix library mapping, remove upstreamed patches
|
- Fix library mapping, remove upstreamed patches
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user