[libinline-java-perl] 285/398: ok

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:15 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 6c1ba2899843fea179f6ebe825aec767dc1c72d1
Author: patrick_leb <>
Date:   Sat Feb 14 14:52:26 2004 +0000

    ok
---
 Java/PerlInterpreter/Makefile.PL                   |  28 ++-
 Java/PerlInterpreter/PerlInterpreter.pm            |  29 +++
 Java/PerlInterpreter/PerlInterpreter.xs            | 199 +++++----------------
 Java/PerlInterpreter/dougm/test.pl                 |  33 +---
 Java/PerlInterpreter/dougm/test.sh                 |   2 +-
 .../perl/inline/java/InlineJavaPerlException.java  |   6 +
 .../inline/java/InlineJavaPerlInterpreter.java     |  79 ++++----
 7 files changed, 152 insertions(+), 224 deletions(-)

diff --git a/Java/PerlInterpreter/Makefile.PL b/Java/PerlInterpreter/Makefile.PL
index 3c19b73..ce1f540 100644
--- a/Java/PerlInterpreter/Makefile.PL
+++ b/Java/PerlInterpreter/Makefile.PL
@@ -1,16 +1,38 @@
 use ExtUtils::MakeMaker ;
+use ExtUtils::Embed ;
+use Config ;
 
 use strict ;
 require "../Portable.pm" ;
 
-my $libperl_dir = Inline::Java::Portable::portable('SUB_FIX_MAKE_QUOTES',
-	"??") ;
+
+my $ccopts = ccopts() ;
+chomp($ccopts) ;
+my $ldopts = ldopts() ;
+chomp($ldopts) ;
 
 WriteMakefile(
 	NAME => 'Inline::Java::PerlInterpreter',
 	VERSION_FROM => 'PerlInterpreter.pm',
+	CCFLAGS => $ccopts,
+	LDDLFLAGS => "-Wl,--whole-archive $ldopts -Wl,--no-whole-archive $Config{lddlflags}",
 	INC => join(' ', @main::I),
-	LIBS => [join(' ', @main::L) . " -ljvm -L$libperl_dir -lperl"],
 	# CCFLAGS => '-D_REENTRANT',
 ) ;
 
+__END__
+
+#!perl
+
+use 5.8.0;
+use strict;
+use Config;
+use ExtUtils::Embed;
+
+my $cmodule = 'PerlInterpreter';
+
+
+my $ar  = "-Wl,--whole-archive";
+my $nar = "-Wl,--no-whole-archive";
+
+run("$Config{cc} -Wall $ar $ccopts $ldopts $nar -o lib$cmodule.so $cmodule.c");
diff --git a/Java/PerlInterpreter/PerlInterpreter.pm b/Java/PerlInterpreter/PerlInterpreter.pm
index 3e00e4e..0ff26bd 100644
--- a/Java/PerlInterpreter/PerlInterpreter.pm
+++ b/Java/PerlInterpreter/PerlInterpreter.pm
@@ -1,7 +1,36 @@
 package Inline::Java::PerlInterpreter ;
 
 use strict ;
+use Inline::Java ;
 
 $Inline::Java::PerlInterpreter::VERSION = '0.50' ;
 
+
+use Inline (
+	Java => 'STUDY',
+	EMBEDDED_JNI => 1,
+	STUDY => [],
+	NAME => 'Inline::Java::PerlInterpreter',
+) ;
+
+
+
+sub java_eval {
+	my $code = shift ;
+
+	my $ret = eval $code ;
+	if ($@){
+		die($@) ;
+	}
+
+	return $ret ;
+}
+
+
+sub java_require {
+	my $module = shift ;
+
+	return java_eval("require $module ;") ;
+}
+
 1 ;
diff --git a/Java/PerlInterpreter/PerlInterpreter.xs b/Java/PerlInterpreter/PerlInterpreter.xs
index 249da32..4bdf61f 100644
--- a/Java/PerlInterpreter/PerlInterpreter.xs
+++ b/Java/PerlInterpreter/PerlInterpreter.xs
@@ -1,187 +1,76 @@
-#include "stdlib.h"
-#include "string.h"
-#include "stdio.h"
-#include "stdarg.h"
-
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
 
 
 /* Include the JNI header file */
 #include "jni.h"
 
-
-void throw_ije(JNIEnv *env, char *msg){
-	jclass ije ;
-
-	ije = (*(env))->FindClass(env, "org/perl/inline/java/InlineJavaException") ;
-	if ((*(env))->ExceptionCheck(env)){
-		(*(env))->ExceptionDescribe(env) ;
-		(*(env))->ExceptionClear(env) ;
-		(*(env))->FatalError(env, "Can't find class InlineJavaException: exiting...") ;
-	}
-	(*(env))->ThrowNew(env, ije, msg) ;
-}
-
-
-JNIEXPORT void JNICALL Java_org_perl_inline_java_InlineJavaPerlInterpreters_Create(JNIEnv *env, jobject obj){
-}
-
+/* The PerlInterpreter handle */
+PerlInterpreter *interp = NULL ;
 
 
-/*****************************************************************************/
+/* XS initialisation stuff */
+void boot_DynaLoader(pTHX_ CV* cv) ;
 
-/*
-XS(boot_Inline__Java__Natives); 
-XS(boot_Inline__Java__Natives)
-{
-    dXSARGS;
 
-    XS_VERSION_BOOTCHECK ;
-
-    XSRETURN_YES;
+static void xs_init(pTHX){
+    char *file = __FILE__ ;
+    dXSUB_SYS ;
+    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file) ;
 }
-*/
-
-/* 
-	xsubpp doesn't like it when we don't specify a MODULE=... PACKAGE=...
-	line. But doing this results in calling function from libperl and we 
-	don't want that or else we will need to laod that to. So we simply let
-	xsubpp do it's substitutions and define macros the cancel out the effect.
-	Anyways that code will NEVER be called.
-*/
-
-void noop(){
-}
-
-#define XS(n)					void n()
-#define dXSARGS					noop()
-#define XS_VERSION_BOOTCHECK	noop()
-#define XSRETURN_YES			noop()
 
-#define PERL_UNUSED_VAR(var)	noop()
 
-MODULE = Inline::Java::PerlInterpreter   PACKAGE = Inline::Java::PerlInterpreter
-
-PROTOTYPES: DISABLE
-
-/* ################## DOUG'S STUFF #################### */
 
-/*
-#include "jni.h"
-#include "EXTERN.h"
-#include "perl.h"
-
-#define JENV (*env)
-
-#define PERL_PACKAGE "org/perl"
-
-void boot_DynaLoader(pTHX_ CV* cv);
-
-static void xs_init(pTHX)
-{
-    char *file = __FILE__;
-    dXSUB_SYS;
-    newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
-}
-
-static void perl_throw_exception(JNIEnv *env, char *msg)
-{
-    jclass errorClass = 
-        JENV->FindClass(env, PERL_PACKAGE "PerlException");
+void throw_ijp(JNIEnv *env, char *msg){
+	jclass ije ;
 
-    JENV->ThrowNew(env, errorClass, msg);
+	ije = (*(env))->FindClass(env, "org/perl/inline/java/InlineJavaPerlException") ;
+	if ((*(env))->ExceptionCheck(env)){
+		(*(env))->ExceptionDescribe(env) ;
+		(*(env))->ExceptionClear(env) ;
+		(*(env))->FatalError(env, "Can't find class InlineJavaPerlException: exiting...") ;
+	}
+	(*(env))->ThrowNew(env, ije, msg) ;
 }
 
-static PerlInterpreter *perl_get_pointer(JNIEnv *env, jobject obj) {
-    jfieldID pointer_field;
-    jclass cls;
-      
-    cls = JENV->GetObjectClass(env, obj);
 
-    pointer_field = JENV->GetFieldID(env, cls, "perlInterpreter", "I");
+JNIEXPORT void JNICALL Java_org_perl_inline_java_InlineJavaPerlInterpreter_construct(JNIEnv *env, jclass cls){
+	char *args[] = {"inline-java", "-e1"} ;
 
-    return (PerlInterpreter *)JENV->GetIntField(env, obj, pointer_field);
+	interp = perl_alloc() ;
+	perl_construct(interp) ;
+	perl_parse(interp, xs_init, 2, args, NULL) ;
+	perl_run(interp) ;
 }
 
-static void perl_set_pointer(JNIEnv *env, jobject obj, const void *ptr) {
-    jfieldID pointer_field;
-    int pointer_int;
-    jclass cls;
-    
-    cls = JENV->GetObjectClass(env, obj);
-
-    pointer_field = JENV->GetFieldID(env, cls, "perlInterpreter", "I");
-    pointer_int = (int)ptr;
 
-    JENV->SetIntField(env, obj, pointer_field, pointer_int);
+JNIEXPORT void JNICALL Java_org_perl_inline_java_InlineJavaPerlInterpreter_destruct(JNIEnv *env, jclass cls){
+	perl_destruct(interp) ;
+	perl_free(interp) ;
+	interp = NULL ;
 }
 
-JNIEXPORT jobject JNICALL Java_org_perl_PerlInterpreter_create
-(JNIEnv *env, jobject obj, jobject parent)
-{
-    PerlInterpreter *interp = NULL;
-
-    if (parent) {
-        PerlInterpreter *parent_perl = perl_get_pointer(env, parent);
-        interp = perl_clone(parent_perl, 0);
-    }
-    else {
-        char *args[] = {"java", "-e0"};
 
-        interp = perl_alloc();
-        perl_construct(interp);
-        perl_parse(interp, xs_init, 2, args, NULL);
-        perl_run(interp);
-    }
+JNIEXPORT void JNICALL Java_org_perl_inline_java_InlineJavaPerlInterpreter_evalNoReturn(JNIEnv *env, jclass cls, jstring code){
+	SV *sv = NULL ;
+	char *pcode = NULL ;
 
-    perl_set_pointer(env, obj, interp);
-
-    return NULL;
-}
-
-JNIEXPORT void JNICALL Java_org_perl_PerlInterpreter_destroy
-(JNIEnv *env, jobject obj)
-{
-    PerlInterpreter *perl = perl_get_pointer(env, obj);
-
-    perl_destruct(perl);
-    perl_free(perl);
+	pcode = (char *)((*(env))->GetStringUTFChars(env, code, NULL)) ;
+	sv = sv_2mortal(newSVpv(pcode, 0)) ;
+	/* sv = eval_pv(pcode, FALSE) ; */
+	eval_sv(sv, G_EVAL|G_KEEPERR) ;
+	(*(env))->ReleaseStringUTFChars(env, code, pcode) ;
+	if (SvTRUE(ERRSV)){
+		STRLEN n_a ;
+		throw_ijp(env, SvPV(ERRSV, n_a)) ;
+	}
 }
 
-JNIEXPORT jstring JNICALL Java_org_perl_PerlInterpreter_eval
-(JNIEnv *env, jobject obj, jstring jcode)
-{
-    PerlInterpreter *perl = perl_get_pointer(env, obj);
-    dTHXa(perl);
-    SV *sv = Nullsv;
-
-    const char *code = JENV->GetStringUTFChars(env, jcode, 0);
-
-    sv = eval_pv(code, FALSE);
 
-    if (SvTRUE(ERRSV)) {
-        perl_throw_exception(env, SvPVX(ERRSV));
-    }
 
-    if (SvTRUE(sv)) {
-        STRLEN n_a;
-        return JENV->NewStringUTF(env, SvPV(sv, n_a));
-    }
-
-    return NULL;
-}
-
-JNIEXPORT jstring JNICALL Java_org_perl_PerlInterpreter_call
-(JNIEnv *env, jobject obj, jstring jfunction, jobjectArray args)
-{
-    PerlInterpreter *perl = perl_get_pointer(env, obj);
-    dTHXa(perl);
+MODULE = Inline::Java::PerlInterpreter   PACKAGE = Inline::Java::PerlInterpreter
 
-    const char *function = JENV->GetStringUTFChars(env, jfunction, 0);
+PROTOTYPES: DISABLE
 
-    if (SvTRUE(ERRSV)) {
-        perl_throw_exception(env, SvPVX(ERRSV));
-    }
 
-    return NULL;
-}
-*/
diff --git a/Java/PerlInterpreter/dougm/test.pl b/Java/PerlInterpreter/dougm/test.pl
index e527281..0269514 100644
--- a/Java/PerlInterpreter/dougm/test.pl
+++ b/Java/PerlInterpreter/dougm/test.pl
@@ -1,41 +1,12 @@
-use strict;
-use warnings FATAL => 'all';
-
 use DynaLoader ();
 
-our $code;
-
 BEGIN {
     use Config;
     my $libperl = "$Config{installarchlib}/CORE/libperl.so";
 
     DynaLoader::dl_load_file($libperl, 0x01);
-
-    $Inline::Java::DEBUG = 1;
-
-    $code = <<EOF;
-
-class Jtest {
-
-    public Jtest () { }
-
-    public static void listProps() {
-        System.getProperties().list(System.out);
-    }
-}
-
-EOF
 }
 
-use blib '/home/dougm/build/Inline-Java-0.33';
-
-use Inline Java => $code,
-  AUTOSTUDY => 1, JNI => 2,
-  DIRECTORY => '/home/dougm/covalent/eam/PerlInterpreter/inline',
-  NAME => 'MyStuff';
-
-Jtest->new->listProps();
-
-print "ok\n";
 
-1;
+use Cwd ;
+print "OK\n" ;
diff --git a/Java/PerlInterpreter/dougm/test.sh b/Java/PerlInterpreter/dougm/test.sh
index f183745..ad7435b 100755
--- a/Java/PerlInterpreter/dougm/test.sh
+++ b/Java/PerlInterpreter/dougm/test.sh
@@ -2,4 +2,4 @@
 
 export LD_LIBRARY_PATH=`pwd`/src/jni
 
-java -cp ./dist/lib/PerlInterpreter.jar:/home/dougm/covalent/eam/PerlInterpreter/inline/lib/auto/MyStuff org.perl.PerlInterpreter
+/usr/java/j2sdk1.4.2_02/bin/java -cp ./dist/lib/PerlInterpreter.jar org.perl.PerlInterpreter
diff --git a/Java/sources/org/perl/inline/java/InlineJavaPerlException.java b/Java/sources/org/perl/inline/java/InlineJavaPerlException.java
index a8bf663..38fd631 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaPerlException.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaPerlException.java
@@ -6,9 +6,15 @@ public class InlineJavaPerlException extends Exception {
 
 
 	public InlineJavaPerlException(Object o){
+		super(o.toString()) ;
 		obj = o ;
 	}
 
+	public InlineJavaPerlException(String s){
+		super(s) ;
+		obj = s ;
+	}
+
 	public Object GetObject(){
 		return obj ;
 	}
diff --git a/Java/sources/org/perl/inline/java/InlineJavaPerlInterpreter.java b/Java/sources/org/perl/inline/java/InlineJavaPerlInterpreter.java
index b4ebe97..f9b877a 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaPerlInterpreter.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaPerlInterpreter.java
@@ -1,6 +1,10 @@
 package org.perl.inline.java ;
 
 
+import java.util.* ;
+import java.io.* ;
+
+
 /*
 	InlineJavaPerlInterpreter
 
@@ -14,24 +18,38 @@ package org.perl.inline.java ;
 public class InlineJavaPerlInterpreter extends InlineJavaPerlCaller {
 	static private boolean inited = false ;
 	static InlineJavaPerlInterpreter instance = null ;
-	private InlineJavaServer isj = null ;
+	static boolean test = false ;
+	static String libperl_so = "" ;
 
 
-	protected InlineJavaPerlInterpreter(int d) throws InlineJavaPerlException {
+	protected InlineJavaPerlInterpreter() throws InlineJavaPerlException, InlineJavaException {
 		init() ;
-		ijs = InlineJavaServer.jni_main(d) ;
+
+		construct() ;
+
+		if (! libperl_so.equals("")){
+			evalNoReturn("require DynaLoader ;") ;
+			evalNoReturn("DynaLoader::dl_load_file(\"" + libperl_so + "\", 0x01) ;") ;
+		}
+		if (test){
+			evalNoReturn("use blib ;") ;
+		}
+		evalNoReturn("use Inline::Java::PerlInterpreter ;") ;
 	}
 
 
-	public InlineJavaPerlInterpreter getInstance(int d) throws InlineJavaPerlException {
+	synchronized static public InlineJavaPerlInterpreter getInstance() throws InlineJavaPerlException, InlineJavaException {
 		if (instance == null){
-			instance = new InlineJavaPerlInterpreter(d) ;
+			// Here we create a temporary InlineJavaServer instance in order to be able to instanciate
+			// ourselves. When we create InlineJavaPerlInterpreter, the instance will be overriden.
+			InlineJavaServer.jni_main(0) ;
+			instance = new InlineJavaPerlInterpreter() ;
 		}
 		return instance ;
 	}
 
 
-	static protected void init() throws InlineJavaException {
+	synchronized static protected void init() throws InlineJavaException {
 		init("install") ;
 	}
 
@@ -39,19 +57,22 @@ public class InlineJavaPerlInterpreter extends InlineJavaPerlCaller {
 	synchronized static protected void init(String mode) throws InlineJavaException {
 		InlineJavaPerlCaller.init() ;
 		if (! inited){
+			test = (mode.equals("test") ? true : false) ;
 			try {
 				String perlinterpreter_so = GetBundle().getString("inline_java_perlinterpreter_so_" + mode) ;
-				File f = new File(natives_so) ;
+				File f = new File(perlinterpreter_so) ;
 				if (! f.exists()){
 					throw new InlineJavaException("Can't initialize PerlInterpreter " +
-						"functionnality: PerlInterpreter extension (" + natives_so +
+						"functionnality: PerlInterpreter extension (" + perlinterpreter_so +
 						") can't be found") ;
 				}
 
-				// Load the Natives shared object
+				// Load the PerlInterpreter shared object
 				InlineJavaUtils.debug(2, "loading shared library " + perlinterpreter_so) ;
 				System.load(perlinterpreter_so) ;
 
+				libperl_so = GetBundle().getString("inline_java_libperl_so") ;
+
 				inited = true ;
 			}
 			catch (MissingResourceException mre){
@@ -61,37 +82,27 @@ public class InlineJavaPerlInterpreter extends InlineJavaPerlCaller {
 	}
 
 
-	/*
-    int perlInterpreter = 0;
+	synchronized static private native void construct() ;
+
+
+	synchronized static private native void evalNoReturn(String code) throws InlineJavaPerlException ;
 
-    public PerlInterpreter() {
-        create(null);
-    }
 
-    public int getPerlInterpreter() {
-        return perlInterpreter;
-    }
+	synchronized static private native void destruct() ;
 
-    private native PerlInterpreter create(PerlInterpreter perl)
-        throws RuntimeException;
 
-    public native String eval(String code) throws PerlException;
+	public Object eval(String code) throws InlineJavaPerlException, InlineJavaException {
+		return CallPerl("Inline::Java::PerlInterpreter", "java_eval", new Object [] {code}) ;
+	}
 
-    public native void destroy();
 
-    public static void main(String[] args) {
-        try {
-            System.loadLibrary("PerlInterpreter");
+	public Object require(String module) throws InlineJavaPerlException, InlineJavaException {
+		return CallPerl("Inline::Java::PerlInterpreter", "java_require", new Object [] {module}) ;
+	}
 
-            PerlInterpreter perl = new PerlInterpreter();
-            System.setProperty("PERL", "XXX");
-            String val = perl.eval("require 'test.pl'");
-            System.out.println(val);
-            perl.destroy();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
-	*/
+	synchronized public void destroy() {
+		destruct() ;
+		instance = null ;
+	}
 }

-- 
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