[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:11:19 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 581195f9e386be29c79e505e9fbe05a34cb70cc9
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Nov 13 01:56:13 2003 +0000

    	Added utility functions for calling JNI methods.
    
            Reviewed by Chris.
    
            * JavaScriptCore.pbproj/project.pbxproj:
            * Makefile.am:
            * bindings/Makefile.am: Added.
            * bindings/jni/Makefile.am: Added.
            * bindings/jni/jni_utility.cpp: Added.
            (attachToJavaVM):
            (callJNIMethod):
            (callJNIVoidMethod):
            (callJNIObjectMethod):
            (callJNIByteMethod):
            (callJNICharMethod):
            (callJNIShortMethod):
            (callJNIIntMethod):
            (callJNILongMethod):
            (callJNIFloatMethod):
            (callJNIDoubleMethod):
            * bindings/jni/jni_utility.h: Added.
            * bindings/objc/Makefile.am: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5473 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index d001139..f9dfcd2 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,28 @@
+2003-11-12  Richard Williamson   <rjw at apple.com>
+
+	Added utility functions for calling JNI methods.
+
+        Reviewed by Chris.
+
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * Makefile.am:
+        * bindings/Makefile.am: Added.
+        * bindings/jni/Makefile.am: Added.
+        * bindings/jni/jni_utility.cpp: Added.
+        (attachToJavaVM):
+        (callJNIMethod):
+        (callJNIVoidMethod):
+        (callJNIObjectMethod):
+        (callJNIByteMethod):
+        (callJNICharMethod):
+        (callJNIShortMethod):
+        (callJNIIntMethod):
+        (callJNILongMethod):
+        (callJNIFloatMethod):
+        (callJNIDoubleMethod):
+        * bindings/jni/jni_utility.h: Added.
+        * bindings/objc/Makefile.am: Added.
+
 2003-11-08  Darin Adler  <darin at apple.com>
 
         Reviewed by John.
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index c8e7844..a9c1e9a 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -95,6 +95,7 @@
 		};
 		0867D691FE84028FC02AAC07 = {
 			children = (
+				51856D950562EE9C008B9D83,
 				65417203039E01F90058BFEB,
 				65417200039E01BA0058BFEB,
 				089C1665FE841158C02AAC07,
@@ -110,6 +111,7 @@
 			children = (
 				6560A4CF04B3B3E7008AE952,
 				6560A63D04B3B69F008AE952,
+				51856D980562F158008B9D83,
 			);
 			isa = PBXGroup;
 			name = Frameworks;
@@ -232,6 +234,7 @@
 				65417211039E08B90058BFEB,
 				65417219039E0B390058BFEB,
 				937F4F25048E5B9900CA2AC4,
+				51856D920562EE95008B9D83,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -284,6 +287,7 @@
 				6541720C039E02E70058BFEB,
 				6541720D039E02E70058BFEB,
 				9364B274045B7D6C00A9CAC1,
+				51856D910562EE95008B9D83,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -293,6 +297,7 @@
 			files = (
 				6560A4D004B3B3E7008AE952,
 				6560A63E04B3B69F008AE952,
+				51856D990562F158008B9D83,
 			);
 			isa = PBXFrameworksBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -412,6 +417,70 @@
 //082
 //083
 //084
+//510
+//511
+//512
+//513
+//514
+		51856D8F0562EE95008B9D83 = {
+			expectedFileType = sourcecode.cpp.cpp;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_utility.cpp;
+			path = bindings/jni/jni_utility.cpp;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		51856D900562EE95008B9D83 = {
+			expectedFileType = sourcecode.c.h;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = jni_utility.h;
+			path = bindings/jni/jni_utility.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		51856D910562EE95008B9D83 = {
+			fileRef = 51856D8F0562EE95008B9D83;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		51856D920562EE95008B9D83 = {
+			fileRef = 51856D900562EE95008B9D83;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		51856D950562EE9C008B9D83 = {
+			children = (
+				51856D8F0562EE95008B9D83,
+				51856D900562EE95008B9D83,
+			);
+			isa = PBXGroup;
+			name = bindings;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		51856D980562F158008B9D83 = {
+			expectedFileType = wrapper.framework;
+			isa = PBXFileReference;
+			name = JavaVM.framework;
+			path = /System/Library/Frameworks/JavaVM.framework;
+			refType = 0;
+			sourceTree = "<absolute>";
+		};
+		51856D990562F158008B9D83 = {
+			fileRef = 51856D980562F158008B9D83;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+//510
+//511
+//512
+//513
+//514
 //650
 //651
 //652
diff --git a/JavaScriptCore/Makefile.am b/JavaScriptCore/Makefile.am
index 4007efa..a1ebb22 100644
--- a/JavaScriptCore/Makefile.am
+++ b/JavaScriptCore/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = pcre kjs
+SUBDIRS = pcre kjs bindings
 
 # FIXME: need to build the other kjs test program too
 
@@ -9,7 +9,7 @@ kjs_testkjs_DEPENDENCIES = JavaScriptCore-stamp
 kjs_testkjs_LDFLAGS = -F$(SYMROOTS) -framework JavaScriptCore
 
 all-am: JavaScriptCore-stamp
-JavaScriptCore-stamp: kjs/*.cpp kjs/*.h pcre/*.c pcre/*.h
+JavaScriptCore-stamp: kjs/*.cpp kjs/*.h pcre/*.c pcre/*.h bindings/jni/*.cpp bindings/jni/*.h
 	pbxbuild -buildstyle $(BUILDSTYLE) OBJROOT=$(SYMROOTS) SYMROOT=$(SYMROOTS) DSTROOT=$(SYMROOTS) && touch $@
 clean-am:
 	pbxbuild clean OBJROOT=$(SYMROOTS) SYMROOT=$(SYMROOTS) DSTROOT=$(SYMROOTS)
diff --git a/JavaScriptCore/bindings/Makefile.am b/JavaScriptCore/bindings/Makefile.am
new file mode 100644
index 0000000..fbf356b
--- /dev/null
+++ b/JavaScriptCore/bindings/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = jni objc
+
+INCLUDES = -I $(top_srcdir)/JavaScriptCore/kjs
diff --git a/JavaScriptCore/bindings/jni/Makefile.am b/JavaScriptCore/bindings/jni/Makefile.am
new file mode 100644
index 0000000..29ffbef
--- /dev/null
+++ b/JavaScriptCore/bindings/jni/Makefile.am
@@ -0,0 +1 @@
+INCLUDES = -I $(top_srcdir)/JavaScriptCore/kjs
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
new file mode 100644
index 0000000..3ef3f9c
--- /dev/null
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -0,0 +1,196 @@
+#include "jni_utility.h"
+
+
+static bool attachToJavaVM(JavaVM **jvm, JNIEnv **env)
+{
+    JavaVM *jvmArray[1];
+    jsize bufLen = 1;
+    jsize nJVMs = 0;
+    jint jniError = 0;
+    bool attached = false;
+
+    // if a JVM is already running ...
+    jniError = JNI_GetCreatedJavaVMs(jvmArray, bufLen, &nJVMs);
+    if ( jniError == JNI_OK )
+    {
+        // how many JVMs?
+        if ( nJVMs > 0 )
+        {
+            // connect to the Java VM
+            // there can be only one per process  -- mhay  2002.09.30
+            *jvm = jvmArray[0];
+            jniError = (*jvm)->AttachCurrentThread((void**)env, (void *)NULL);
+            if ( jniError == JNI_OK )
+                attached = true;
+            else
+                fprintf(stderr, "%s: AttachCurrentThread failed, returned %d", __PRETTY_FUNCTION__, jniError);
+        }
+    }
+    else 
+        fprintf(stderr, "%s: JNI_GetCreatedJavaVMs failed, returned %d", __PRETTY_FUNCTION__, jniError);
+
+    return attached;
+}
+
+typedef union {
+    jobject _object;
+    jboolean _boolean;
+    jbyte _byte;
+    jchar _char;
+    jshort _short;
+    jint _int;
+    jlong _long;
+    jfloat _float;
+    jdouble _double;
+    bool _error;
+} jresult;
+
+typedef enum {
+    void_function,
+    object_function,
+    boolean_function,
+    byte_function,
+    char_function,
+    short_function,
+    int_function,
+    long_function,
+    float_function,
+    double_function
+} JNIFunctionType;
+
+
+jresult callJNIMethod( JNIFunctionType type, jobject obj, const char *name, const char *sig, va_list argList)
+{
+    JavaVM *jvm = NULL;
+    JNIEnv *env = NULL;
+    jresult result;
+
+    result._error = false;
+    
+    if ( obj != NULL ) {
+        if ( attachToJavaVM(&jvm, &env) ) {
+            jclass cls = env->GetObjectClass(obj);
+            if ( cls != NULL ) {
+                jmethodID mid = env->GetMethodID(cls, name, sig);
+                if ( mid != NULL )
+                {
+                    switch (type) {
+                    case void_function:
+                        env->functions->CallVoidMethodV(env, obj, mid, argList);
+                        break;
+                    case object_function:
+                        result._object = env->functions->CallObjectMethodV(env, obj, mid, argList);
+                        break;
+                    case boolean_function:
+                        result._boolean = env->functions->CallBooleanMethodV(env, obj, mid, argList);
+                        break;
+                    case byte_function:
+                        result._byte = env->functions->CallByteMethodV(env, obj, mid, argList);
+                        break;
+                    case char_function:
+                        result._char = env->functions->CallCharMethodV(env, obj, mid, argList);
+                        break;
+                    case short_function:
+                        result._short = env->functions->CallShortMethodV(env, obj, mid, argList);
+                        break;
+                    case int_function:
+                        result._int = env->functions->CallIntMethodV(env, obj, mid, argList);
+                        break;
+                    case long_function:
+                        result._long = env->functions->CallLongMethodV(env, obj, mid, argList);
+                        break;
+                    case float_function:
+                        result._float = env->functions->CallFloatMethodV(env, obj, mid, argList);
+                        break;
+                    case double_function:
+                        result._double = env->functions->CallDoubleMethodV(env, obj, mid, argList);
+                        break;
+                    default:
+                        result._error = true;
+                    }
+                }
+                else
+                {
+                    fprintf(stderr, "%s: Could not find method: %s!", __PRETTY_FUNCTION__, name);
+                    env->ExceptionDescribe();
+                    env->ExceptionClear();
+                    result._error = true;
+                }
+
+                env->DeleteLocalRef(cls);
+            }
+            else {
+                fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
+                result._error = true;
+            }
+        }
+        else {
+            fprintf(stderr, "%s: Could not attach to the VM!", __PRETTY_FUNCTION__);
+            result._error = true;
+        }
+    }
+
+    return result;
+}
+
+#define CALL_JNI_METHOD(function_type,obj,name,sig) \
+    va_list args;\
+    va_start (args, sig);\
+    \
+    jresult result = callJNIMethod(function_type, obj, name, sig, args);\
+    \
+    va_end (args);
+
+void callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (void_function, obj, name, sig);
+}
+
+jobject callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (object_function, obj, name, sig);
+    return result._object;
+}
+
+jbyte callJNIByteMethod( jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (byte_function, obj, name, sig);
+    return result._byte;
+}
+
+jchar callJNICharMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (char_function, obj, name, sig);
+    return result._char;
+}
+
+jshort callJNIShortMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (short_function, obj, name, sig);
+    return result._short;
+}
+
+jint callJNIIntMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (int_function, obj, name, sig);
+    return result._int;
+}
+
+jlong callJNILongMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (long_function, obj, name, sig);
+    return result._long;
+}
+
+jfloat callJNIFloatMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (float_function, obj, name, sig);
+    return result._float;
+}
+
+jdouble callJNIDoubleMethod (jobject obj, const char *name, const char *sig, ... )
+{
+    CALL_JNI_METHOD (double_function, obj, name, sig);
+    return result._double;
+}
+
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
new file mode 100644
index 0000000..80b3546
--- /dev/null
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -0,0 +1,12 @@
+#include <JavaVM/jni.h>
+
+jobject callJNIObjectMethod( jobject obj, const char *name, const char *sig, ... );
+void callJNIVoidMethod( jobject obj, const char *name, const char *sig, ... );
+jboolean callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... );
+jbyte callJNIByteMethod( jobject obj, const char *name, const char *sig, ... );
+jchar callJNICharMethod( jobject obj, const char *name, const char *sig, ... );
+jshort callJNIShortMethod( jobject obj, const char *name, const char *sig, ... );
+jint callJNIIntMethod( jobject obj, const char *name, const char *sig, ... );
+jlong callJNILongMethod( jobject obj, const char *name, const char *sig, ... );
+jfloat callJNIFloatMethod( jobject obj, const char *name, const char *sig, ... );
+jdouble callJNIDoubleMethod( jobject obj, const char *name, const char *sig, ... );
diff --git a/JavaScriptCore/bindings/objc/Makefile.am b/JavaScriptCore/bindings/objc/Makefile.am
new file mode 100644
index 0000000..29ffbef
--- /dev/null
+++ b/JavaScriptCore/bindings/objc/Makefile.am
@@ -0,0 +1 @@
+INCLUDES = -I $(top_srcdir)/JavaScriptCore/kjs

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list