rpms/jna/devel jna-3.0.9-processopen.patch, NONE, 1.1 jna.spec, 1.14, 1.15

Colin Walters walters at fedoraproject.org
Tue Dec 30 23:34:39 UTC 2008


Author: walters

Update of /cvs/pkgs/rpms/jna/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv31168

Modified Files:
	jna.spec 
Added Files:
	jna-3.0.9-processopen.patch 
Log Message:
* Tue Dec 30 2008 Colin Walters <walters at redhat.com> - 3.0.9-3
- Add patch to allow opening current process


jna-3.0.9-processopen.patch:

--- NEW FILE jna-3.0.9-processopen.patch ---
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) {


Index: jna.spec
===================================================================
RCS file: /cvs/pkgs/rpms/jna/devel/jna.spec,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- jna.spec	30 Nov 2008 18:43:32 -0000	1.14
+++ jna.spec	30 Dec 2008 23:34:06 -0000	1.15
@@ -1,6 +1,6 @@
 Name:           jna
 Version:        3.0.9
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        Pure Java access to native libraries
 
 Group:          Development/Libraries
@@ -27,6 +27,8 @@
 Patch5:         jna-callback-exception.patch
 # https://jna.dev.java.net/issues/show_bug.cgi?id=95
 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)
 
 BuildRequires:  java-devel >= 1.6 ant jpackage-utils ant-nodeps
@@ -61,6 +63,7 @@
 %patch3 -p1 -b .nativemapped-array
 #%patch5 -p1 -b .callback-exception
 %patch6 -p1 -b .linux-nomaplibrary
+%patch7 -p1 -b .processopen
 
 # all java binaries must be removed from the sources
 find . -name '*.jar' -exec rm -f '{}' \;
@@ -114,6 +117,9 @@
 
 
 %changelog
+* Tue Dec 30 2008 Colin Walters <walters at redhat.com> - 3.0.9-3
+- Add patch to allow opening current process
+
 * Sun Nov 30 2008 Colin Walters <walters at redhat.com> - 3.0.9-2
 - Fix library mapping, remove upstreamed patches
 




More information about the fedora-extras-commits mailing list