packages feed

java-bridge 0.20130606.2 → 0.20130606.3

raw patch · 5 files changed

+171/−7 lines, 5 filessetup-changed

Files

+ HFunction.java view
@@ -0,0 +1,50 @@+import java.lang.reflect.*;++/**+ * An HFunction can be used as a invocation handler which actually+ * handles the invocation by calling a Haskell function.+ *+ * @author Julian Fleischer+ */+public class HFunction implements InvocationHandler {++    private final long hFunction;++    static native void release(long func);+    static native Object call(long func, Method self, Object[] args);++    /**+     * Creates an HFunction from a function pointer.+     *+     * @param func+     */+    public HFunction(long func) {+        hFunction = func;+    }++    public Object invoke(Object proxy, Method method, Object[] args) {+        return call(hFunction, method, args);+    }++    protected void finalize() {+        release(hFunction);+    }++    /**+     * Make an HFunction for a given iface from a function pointer.+     *+     * @param iface+     * @param func+     */+    @SuppressWarnings("unchecked")+    public static <T> T makeFunction(Class<T> iface, long func) {+        InvocationHandler handler = new HFunction(func);+        return (T) Proxy.newProxyInstance(+                            iface.getClassLoader(),+                            new Class<?>[] { iface },+                            handler);+    }+}+++
+ ReadClass.java view
@@ -0,0 +1,33 @@+import java.io.*;++public class ReadClass {++    public static void main(String... args) throws Exception {++        File file = new File("HFunction.class");+        int size = (int) file.length();+                +        FileInputStream stream = new FileInputStream(file);+        PrintStream out = new PrintStream("src/hfunction.h");++        byte[] bytes = new byte[size];++        stream.read(bytes);++        out.printf("\n#define FFIJNI_HFUNCTION_LENGTH %d\n\n", size);+        out.print("static jbyte hFunctionClass[FFIJNI_HFUNCTION_LENGTH] = {");+        for (int i = 0; i < size; i++) {+            if (i % 16 == 0) {+                out.println();+                out.print("  ");+            }+            out.print(bytes[i]);+            if (i+1 < size) {+                out.print(", ");+            }+        }+        out.println("\n};");+    }+}++
Setup.hs view
@@ -38,14 +38,16 @@ #endif  main = do+    let verb = verbose      args <- getArgs      args' <- case args of         "configure" : _ -> do-            notice normal ("OS and Arch are " ++ show buildOS ++ " " ++ show buildArch)-            args_ <- Exc.catch (configure verbose args buildOS) $ \exc -> do-                warn normal $+            notice verb ("OS=" ++ show buildOS)+            notice verb ("ARCH=" ++ show buildArch)+            args_ <- Exc.catch (configure verb args buildOS) $ \exc -> do+                warn verb $                     "Could not find a JDK. Continuing anyway.\n"                  ++ "The error is: "                  ++ ((show :: Exc.SomeException -> String) exc)@@ -227,7 +229,7 @@     javaArch <- rawSystemStdout normal (javaHome ++ "/bin/java") ["GetProperty", "os.arch"] 	    >>= return . head . lines -    notice verb $ "os.arch is " ++ javaArch+    notice verb $ "os.arch=" ++ javaArch      libjvmPath <- getEnvironment >>= return . lookup "FFIJNI_LIBJVM"         >>= maybe (return $ javaHome ++ "/jre/lib/" ++ javaArch ++ "/server/libjvm.so") return@@ -237,6 +239,10 @@      findFirstFile id [javaHome ++ "/include/jni.h"]         >>= maybe (fail $ "jni.h was not found in " ++ javaHome ++ "/include")+                  (return . const ())++    findFirstFile id [javaHome ++ "/include/linux/jni_md.h"]+        >>= maybe (fail $ "jni_md.h was not found in " ++ javaHome ++ "/include/linux")                   (return . const ())      return $ args ++ ["--extra-include-dirs=" ++ javaHome ++ "/include",
java-bridge.cabal view
@@ -1,5 +1,5 @@ name:           java-bridge-version:        0.20130606.2+version:        0.20130606.3  license:        MIT license-file:   LICENSE@@ -119,7 +119,10 @@ extra-source-files: include/jni.h,                     src/Foreign/Java/JNI/core.hs,                     src/ffijni.h,+                    src/hfunction.h,                     GetProperty.java,+                    HFunction.java,+                    ReadClass.java,                     examples/calculator/calculator.cabal,                     examples/system-properties/Makefile,                     HACKING.txt,@@ -155,8 +158,8 @@   Library-    cc-options:         -DFFIJNI_BRIDGE_VERSION="0.20130606.2"-    cpp-options:        -DFFIJNI_BRIDGE_VERSION="0.20130606.2"+    cc-options:         -DFFIJNI_BRIDGE_VERSION="0.20130606.3"+    cpp-options:        -DFFIJNI_BRIDGE_VERSION="0.20130606.3"      build-depends:      base >= 4.5 && < 5                         , directory >= 1.1.0.2
+ src/hfunction.h view
@@ -0,0 +1,72 @@++#define FFIJNI_HFUNCTION_LENGTH 1057++static jbyte hFunctionClass[FFIJNI_HFUNCTION_LENGTH] = {+  -54, -2, -70, -66, 0, 0, 0, 50, 0, 48, 10, 0, 10, 0, 31, 9, +  0, 5, 0, 32, 10, 0, 5, 0, 33, 10, 0, 5, 0, 34, 7, 0, +  35, 10, 0, 5, 0, 36, 10, 0, 8, 0, 37, 7, 0, 38, 10, 0, +  39, 0, 40, 7, 0, 41, 7, 0, 42, 1, 0, 9, 104, 70, 117, 110, +  99, 116, 105, 111, 110, 1, 0, 1, 74, 1, 0, 7, 114, 101, 108, 101, +  97, 115, 101, 1, 0, 4, 40, 74, 41, 86, 1, 0, 4, 99, 97, 108, +  108, 1, 0, 66, 40, 74, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, +  47, 114, 101, 102, 108, 101, 99, 116, 47, 77, 101, 116, 104, 111, 100, 59, +  91, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, +  99, 116, 59, 41, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, +  98, 106, 101, 99, 116, 59, 1, 0, 6, 60, 105, 110, 105, 116, 62, 1, +  0, 4, 67, 111, 100, 101, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, +  98, 101, 114, 84, 97, 98, 108, 101, 1, 0, 6, 105, 110, 118, 111, 107, +  101, 1, 0, 83, 40, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, +  79, 98, 106, 101, 99, 116, 59, 76, 106, 97, 118, 97, 47, 108, 97, 110, +  103, 47, 114, 101, 102, 108, 101, 99, 116, 47, 77, 101, 116, 104, 111, 100, +  59, 91, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, +  101, 99, 116, 59, 41, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, +  79, 98, 106, 101, 99, 116, 59, 1, 0, 8, 102, 105, 110, 97, 108, 105, +  122, 101, 1, 0, 3, 40, 41, 86, 1, 0, 12, 109, 97, 107, 101, 70, +  117, 110, 99, 116, 105, 111, 110, 1, 0, 38, 40, 76, 106, 97, 118, 97, +  47, 108, 97, 110, 103, 47, 67, 108, 97, 115, 115, 59, 74, 41, 76, 106, +  97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99, 116, 59, +  1, 0, 9, 83, 105, 103, 110, 97, 116, 117, 114, 101, 1, 0, 50, 60, +  84, 58, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, +  101, 99, 116, 59, 62, 40, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, +  47, 67, 108, 97, 115, 115, 60, 84, 84, 59, 62, 59, 74, 41, 84, 84, +  59, 1, 0, 10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1, 0, +  14, 72, 70, 117, 110, 99, 116, 105, 111, 110, 46, 106, 97, 118, 97, 12, +  0, 18, 0, 24, 12, 0, 12, 0, 13, 12, 0, 16, 0, 17, 12, 0, +  14, 0, 15, 1, 0, 9, 72, 70, 117, 110, 99, 116, 105, 111, 110, 12, +  0, 18, 0, 15, 12, 0, 43, 0, 44, 1, 0, 15, 106, 97, 118, 97, +  47, 108, 97, 110, 103, 47, 67, 108, 97, 115, 115, 7, 0, 45, 12, 0, +  46, 0, 47, 1, 0, 16, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, +  79, 98, 106, 101, 99, 116, 1, 0, 35, 106, 97, 118, 97, 47, 108, 97, +  110, 103, 47, 114, 101, 102, 108, 101, 99, 116, 47, 73, 110, 118, 111, 99, +  97, 116, 105, 111, 110, 72, 97, 110, 100, 108, 101, 114, 1, 0, 14, 103, +  101, 116, 67, 108, 97, 115, 115, 76, 111, 97, 100, 101, 114, 1, 0, 25, +  40, 41, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 67, 108, 97, +  115, 115, 76, 111, 97, 100, 101, 114, 59, 1, 0, 23, 106, 97, 118, 97, +  47, 108, 97, 110, 103, 47, 114, 101, 102, 108, 101, 99, 116, 47, 80, 114, +  111, 120, 121, 1, 0, 16, 110, 101, 119, 80, 114, 111, 120, 121, 73, 110, +  115, 116, 97, 110, 99, 101, 1, 0, 98, 40, 76, 106, 97, 118, 97, 47, +  108, 97, 110, 103, 47, 67, 108, 97, 115, 115, 76, 111, 97, 100, 101, 114, +  59, 91, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 67, 108, 97, +  115, 115, 59, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 114, 101, +  102, 108, 101, 99, 116, 47, 73, 110, 118, 111, 99, 97, 116, 105, 111, 110, +  72, 97, 110, 100, 108, 101, 114, 59, 41, 76, 106, 97, 118, 97, 47, 108, +  97, 110, 103, 47, 79, 98, 106, 101, 99, 116, 59, 0, 33, 0, 5, 0, +  10, 0, 1, 0, 11, 0, 1, 0, 18, 0, 12, 0, 13, 0, 0, 0, +  6, 1, 8, 0, 14, 0, 15, 0, 0, 1, 8, 0, 16, 0, 17, 0, +  0, 0, 1, 0, 18, 0, 15, 0, 1, 0, 19, 0, 0, 0, 42, 0, +  3, 0, 3, 0, 0, 0, 10, 42, -73, 0, 1, 42, 31, -75, 0, 2, +  -79, 0, 0, 0, 1, 0, 20, 0, 0, 0, 14, 0, 3, 0, 0, 0, +  21, 0, 4, 0, 22, 0, 9, 0, 23, 0, 1, 0, 21, 0, 22, 0, +  1, 0, 19, 0, 0, 0, 34, 0, 4, 0, 4, 0, 0, 0, 10, 42, +  -76, 0, 2, 44, 45, -72, 0, 3, -80, 0, 0, 0, 1, 0, 20, 0, +  0, 0, 6, 0, 1, 0, 0, 0, 26, 0, 4, 0, 23, 0, 24, 0, +  1, 0, 19, 0, 0, 0, 36, 0, 2, 0, 1, 0, 0, 0, 8, 42, +  -76, 0, 2, -72, 0, 4, -79, 0, 0, 0, 1, 0, 20, 0, 0, 0, +  10, 0, 2, 0, 0, 0, 30, 0, 7, 0, 31, 0, 9, 0, 25, 0, +  26, 0, 2, 0, 19, 0, 0, 0, 54, 0, 5, 0, 4, 0, 0, 0, +  26, -69, 0, 5, 89, 31, -73, 0, 6, 78, 42, -74, 0, 7, 4, -67, +  0, 8, 89, 3, 42, 83, 45, -72, 0, 9, -80, 0, 0, 0, 1, 0, +  20, 0, 0, 0, 10, 0, 2, 0, 0, 0, 41, 0, 9, 0, 42, 0, +  27, 0, 0, 0, 2, 0, 28, 0, 1, 0, 29, 0, 0, 0, 2, 0, +  30+};