[libinline-java-perl] 136/398: *** empty log message ***
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:42:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.55
in repository libinline-java-perl.
commit 05cf3de83c4a8b028d2517193f9a24f87480a1a9
Author: Patrick LeBoutillier <patl at cpan.org>
Date: Mon Jan 14 14:33:43 2002 +0000
*** empty log message ***
---
Java/JNI.xs | 206 +++++++++++++++++++------------------------------------
Java/Makefile.PL | 12 +++-
Java/Portable.pm | 1 +
3 files changed, 83 insertions(+), 136 deletions(-)
diff --git a/Java/JNI.xs b/Java/JNI.xs
index 5a86231..cee60d3 100644
--- a/Java/JNI.xs
+++ b/Java/JNI.xs
@@ -9,21 +9,43 @@
/* JNI structure */
typedef struct {
- JNIEnv *env ;
JavaVM *jvm ;
jclass ijs_class ;
+ jclass string_class ;
jobject ijs ;
+ jmethodID jni_main_mid ;
+ jmethodID process_command_mid ;
jboolean debug ;
+ int destroyed ;
} InlineJavaJNIVM ;
-void debug_ex(InlineJavaJNIVM *this){
- (*(this->env))->ExceptionDescribe(this->env) ;
+void shutdown_JVM(InlineJavaJNIVM *this){
+ if (! this->destroyed){
+ (*(this->jvm))->DestroyJavaVM(this->jvm) ;
+ this->destroyed = 1 ;
+ }
+}
+
+
+JNIEnv *get_env(InlineJavaJNIVM *this){
+ JNIEnv *env ;
+
+ (*(this->jvm))->AttachCurrentThread(this->jvm, ((void **)&env), NULL) ;
+
+ return env ;
}
-JNIEXPORT jstring JNICALL Java_InlineJavaServer_jni_1callback(
- JNIEnv *env, jobject obj, jstring cmd){
+void check_exception(JNIEnv *env, char *msg){
+ if ((*(env))->ExceptionCheck(env)){
+ (*(env))->ExceptionDescribe(env) ;
+ croak(msg) ;
+ }
+}
+
+
+jstring JNICALL jni_callback(JNIEnv *env, jobject obj, jstring cmd){
dSP ;
jstring resp = NULL ;
@@ -39,6 +61,7 @@ JNIEXPORT jstring JNICALL Java_InlineJavaServer_jni_1callback(
XPUSHs(sv_2mortal(newSVpv(c, 0))) ;
PUTBACK ;
+ (*(env))->ReleaseStringUTFChars(env, cmd, c) ;
count = perl_call_pv("Inline::Java::Callback::InterceptCallback",
G_SCALAR) ;
@@ -56,6 +79,7 @@ JNIEXPORT jstring JNICALL Java_InlineJavaServer_jni_1callback(
FREETMPS ;
LEAVE ;
+
return resp ;
}
@@ -76,8 +100,9 @@ new(CLASS, classpath, debug)
PREINIT:
JavaVMInitArgs vm_args ;
JavaVMOption options[2] ;
+ JNIEnv *env ;
jint res ;
- char * cp ;
+ char *cp ;
CODE:
RETVAL = (InlineJavaJNIVM *)safemalloc(sizeof(InlineJavaJNIVM)) ;
@@ -86,6 +111,7 @@ new(CLASS, classpath, debug)
}
RETVAL->ijs = NULL ;
RETVAL->debug = debug ;
+ RETVAL->destroyed = 0 ;
options[0].optionString = (RETVAL->debug ? "-verbose" : "-verbose:") ;
cp = (char *)malloc((strlen(classpath) + 128) * sizeof(char)) ;
@@ -98,23 +124,47 @@ new(CLASS, classpath, debug)
vm_args.ignoreUnrecognized = JNI_FALSE ;
/* Create the Java VM */
- res = JNI_CreateJavaVM(&(RETVAL->jvm), (void **)&(RETVAL->env), &vm_args) ;
+ res = JNI_CreateJavaVM(&(RETVAL->jvm), (void **)&(env), &vm_args) ;
if (res < 0) {
croak("Can't create Java interpreter using JNI") ;
}
-
free(cp) ;
+
+ /* Load the classes that we will use */
+ RETVAL->ijs_class = (*(env))->FindClass(env, "InlineJavaServer") ;
+ check_exception(env, "Can't find class InlineJavaServer") ;
+ RETVAL->string_class = (*(env))->FindClass(env, "java/lang/String") ;
+ check_exception(env, "Can't find class java.lang.String") ;
+
+ /* Get the method ids that are needed later */
+ RETVAL->jni_main_mid = (*(env))->GetStaticMethodID(env, RETVAL->ijs_class, "jni_main", "(Z)LInlineJavaServer;") ;
+ check_exception(env, "Can't find method jni_main in class InlineJavaServer") ;
+ RETVAL->process_command_mid = (*(env))->GetMethodID(env, RETVAL->ijs_class, "ProcessCommand", "(Ljava/lang/String;)Ljava/lang/String;") ;
+ check_exception(env, "Can't find method ProcessCommand in class InlineJavaServer") ;
+
OUTPUT:
RETVAL
+
+void
+shutdown(this)
+ InlineJavaJNIVM * this
+
+ CODE:
+ shutdown_JVM(this) ;
+
+
+
void
DESTROY(this)
InlineJavaJNIVM * this
CODE:
- (*(this->jvm))->DestroyJavaVM(this->jvm) ;
+ shutdown_JVM(this) ;
+ free(this) ;
+
void
@@ -122,32 +172,13 @@ create_ijs(this)
InlineJavaJNIVM * this
PREINIT:
- jmethodID mid ;
+ JNIEnv *env ;
CODE:
- this->ijs_class = (*(this->env))->FindClass(this->env, "InlineJavaServer") ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- if (this->ijs_class == NULL){
- croak("Can't find class InlineJavaServer") ;
- }
+ env = get_env(this) ;
+ this->ijs = (*(env))->CallStaticObjectMethod(env, this->ijs_class, this->jni_main_mid, this->debug) ;
+ check_exception(env, "Can't call jni_main in class InlineJavaServer") ;
- mid = (*(this->env))->GetStaticMethodID(this->env, this->ijs_class, "jni_main", "(Z)LInlineJavaServer;") ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- if (mid == NULL) {
- croak("Can't find method jni_main in class InlineJavaServer") ;
- }
-
- this->ijs = (*(this->env))->CallStaticObjectMethod(this->env, this->ijs_class, mid, this->debug) ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
char *
@@ -156,116 +187,23 @@ process_command(this, data)
char * data
PREINIT:
- jmethodID mid ;
+ JNIEnv *env ;
jstring cmd ;
jstring resp ;
CODE:
- mid = (*(this->env))->GetMethodID(this->env, this->ijs_class, "ProcessCommand", "(Ljava/lang/String;)Ljava/lang/String;") ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- if (mid == NULL) {
- croak("Can't find method ProcessCommand in class InlineJavaServer") ;
- }
+ env = get_env(this) ;
+ cmd = (*(env))->NewStringUTF(env, data) ;
+ check_exception(env, "Can't create java.lang.String") ;
- cmd = (*(this->env))->NewStringUTF(this->env, data) ;
- if (cmd == NULL){
- croak("Can't create java.lang.String") ;
- }
+ resp = (*(env))->CallObjectMethod(env, this->ijs, this->process_command_mid, cmd) ;
+ check_exception(env, "Can't call ProcessCommand in InlineJavaServer") ;
- resp = (*(this->env))->CallObjectMethod(this->env, this->ijs, mid, cmd) ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- RETVAL = (char *)((*(this->env))->GetStringUTFChars(this->env, resp, NULL)) ;
+ RETVAL = (char *)((*(env))->GetStringUTFChars(env, resp, NULL)) ;
OUTPUT:
RETVAL
CLEANUP:
- (*(this->env))->ReleaseStringUTFChars(this->env, resp, RETVAL) ;
-
-
-void
-report(this, module, classes, nb_classes)
- InlineJavaJNIVM * this
- char * module
- char * classes
- int nb_classes
-
- PREINIT:
- jmethodID mid ;
- jclass class ;
- jobject args ;
- jstring arg ;
- jstring resp ;
- char * cl ;
- char * ptr ;
- int idx ;
-
- CODE:
- mid = (*(this->env))->GetMethodID(this->env, this->ijs_class, "Report", "([Ljava/lang/String;I)V") ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- if (mid == NULL) {
- croak("Can't find method Report in class InlineJavaServer") ;
- }
-
- class = (*(this->env))->FindClass(this->env, "java/lang/String") ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
- if (class == NULL){
- croak("Can't find class java.lang.String") ;
- }
-
- idx = 0 ;
- args = (*(this->env))->NewObjectArray(this->env, nb_classes + 1, class, NULL) ;
- if (args == NULL){
- croak("Can't create array of java.lang.String of length %i", nb_classes + 1) ;
- }
-
- arg = (*(this->env))->NewStringUTF(this->env, module) ;
- if (arg == NULL){
- croak("Can't create java.lang.String") ;
- }
- (*(this->env))->SetObjectArrayElement(this->env, args, idx++, arg) ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
-
- cl = strdup(classes) ;
- ptr = strtok(cl, " ") ;
-
- idx = 1 ;
- while (ptr != NULL){
- arg = (*(this->env))->NewStringUTF(this->env, ptr) ;
- if (arg == NULL){
- croak("Can't create java.lang.String") ;
- }
- (*(this->env))->SetObjectArrayElement(this->env, args, idx, arg) ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
-
- idx++ ;
- ptr = strtok(NULL, " ") ;
- }
- free(cl) ;
-
- (*(this->env))->CallVoidMethod(this->env, this->ijs, mid, args, 0) ;
- if ((*(this->env))->ExceptionOccurred(this->env)){
- (*(this->env))->ExceptionDescribe(this->env) ;
- croak("Exception occured") ;
- }
-
-
-
+ (*(env))->ReleaseStringUTFChars(env, resp, RETVAL) ;
+ (*(env))->DeleteLocalRef(env, resp) ;
diff --git a/Java/Makefile.PL b/Java/Makefile.PL
index a15a881..b58aafb 100644
--- a/Java/Makefile.PL
+++ b/Java/Makefile.PL
@@ -14,6 +14,8 @@ my $build_jni = ($jdk_dir ? 1 : 0) ;
my $jvm_lib = Inline::Java::Portable::portable('JVM_LIB') ;
my $jvm_so = Inline::Java::Portable::portable('JVM_SO') ;
+my %so_dirs = () ;
+
my @files = (
'jni.h',
'jni_md.h',
@@ -31,10 +33,8 @@ my $files = {
discard => qr/include-old/,
},
$jvm_lib => {
- discard => qr/green_threads/,
},
$jvm_so => {
- discard => qr/green_threads/,
},
} ;
@@ -125,6 +125,14 @@ else{
sub search {
my $file = $_ ;
+ my $ext = Inline::Java::Portable::portable('SO_EXT') ;
+ if ($File::Find::dir =~ /jre/){
+ if ($file =~ /\.$ext$/){
+ print $File::Find::dir . "\n" ;
+ $so_dirs{$File::Find::dir} = 1 ;
+ }
+ }
+
foreach my $f (@files){
if ($file eq $f){
my $re = $files->{$f}->{discard} ;
diff --git a/Java/Portable.pm b/Java/Portable.pm
index 82fcc53..c23b098 100644
--- a/Java/Portable.pm
+++ b/Java/Portable.pm
@@ -44,6 +44,7 @@ sub portable {
GOT_ALARM => $Config{d_alarm},
GOT_FORK => $Config{d_fork},
ENV_VAR_PATH_SEP => $Config{path_sep},
+ SO_EXT => $Config{dlext},
ENV_VAR_PATH_SEP_CP => ':',
IO_REDIR => '2>&1',
COMMAND_COM => 0,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git
More information about the Pkg-perl-cvs-commits
mailing list