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 b214691274283509e17c81a144e039285bf80cc5
Author: Patrick LeBoutillier <p...@cpan.org>
Date:   Tue Dec 18 22:23:24 2001 +0000

    *** empty log message ***
---
 Java.pm          |  2 ++
 Java/Callback.pm | 74 ++++++++++++++++++++++++++++++++-----------
 Java/Init.pm     | 30 ++++++++++++++++--
 Java/JNI.pm      |  3 +-
 Java/Makefile.PL | 16 ++++------
 Java/Protocol.pm | 27 +++++++++++++---
 TODO             | 10 ++++--
 t/13_callbacks.t | 96 ++++++++++++++++++++++++++++++++++++++++++--------------
 8 files changed, 194 insertions(+), 64 deletions(-)

diff --git a/Java.pm b/Java.pm
index 7fee281..5133f76 100644
--- a/Java.pm
+++ b/Java.pm
@@ -1238,6 +1238,7 @@ sub portable {
                PATH_SEP                        =>      '/',
                PATH_SEP_RE                     =>      '/',
                RE_FILE                         =>  [],
+               RE_FILE_JAVA            =>  [],
                IO_REDIR                        =>  '2>&1',
                GOT_ALARM                       =>  1,
                COMMAND_COM                     =>  0,
@@ -1252,6 +1253,7 @@ sub portable {
                        PATH_SEP                        =>      '\\',
                        PATH_SEP_RE                     =>      '\\\\',
                        RE_FILE                         =>  ['/', '\\'],
+                       RE_FILE_JAVA            =>  ['\\\\', '\\\\'],
                        # 2>&1 doesn't work under command.com
                        IO_REDIR                        =>  ($COMMAND_COM ? '' 
: undef),
                        GOT_ALARM                       =>  0,
diff --git a/Java/Callback.pm b/Java/Callback.pm
index 1c23638..40c7003 100644
--- a/Java/Callback.pm
+++ b/Java/Callback.pm
@@ -14,8 +14,8 @@ sub InterceptCallback {
        my $resp = shift ;
 
        # With JNI we need to store the object somewhere since we
-       # can't drag it along all the wat through Java land...
-       if (! defined($inline)){ 
+       # can't drag it along all the way through Java land...
+       if (! defined($inline)){
                $inline = $Inline::Java::JNI::INLINE_HOOK ;
        }
 
@@ -37,18 +37,30 @@ sub ProcessCallback {
        my @sargs = @_ ;
 
        my $pc = new Inline::Java::Protocol(undef, $inline) ;
-       my @args = map {$pc->DeserializeObject(0, $_)} @sargs ;
-
-       Inline::Java::debug(" processing callback $module" . "::" . 
"$function(" . 
-               join(", ", @args) . ")") ;
-
-       no strict 'refs' ;
-       my $sub = "$module" . "::" . $function ;
-       my $ret = $sub->(@args) ;
+       my $thrown = 'false' ;
+       my $ret = undef ;
+       eval {
+               my @args = map {$pc->DeserializeObject(0, $_)} @sargs ;
+
+               Inline::Java::debug(" processing callback $module" . "::" . 
"$function(" . 
+                       join(", ", @args) . ")") ;
+
+               no strict 'refs' ;
+               my $sub = "$module" . "::" . $function ;
+               $ret = $sub->(@args) ;
+       } ;
+       if ($@){
+               $ret = $@ ;
+               $thrown = 'true' ;
+
+               if ((ref($ret))&&(! UNIVERSAL::isa($ret, 
"Inline::Java::Object"))){
+                       croak "Can't propagate non-Inline::Java reference 
exception ($ret) to Java" ;
+               }
+       }
 
        ($ret) = $pc->ValidateArgs([$ret]) ;
 
-       return "callback $ret" ;
+       return "callback $thrown $ret" ;
 }
 
 
@@ -59,26 +71,50 @@ __DATA__
 */
 public class InlineJavaPerlCaller {
        public InlineJavaPerlCaller(){
-               if (InlineJavaServer.instance == null){
-                       System.err.println("Can't use InlineJavaPerlCaller 
outside of an Inline::Java context") ;
-                       System.err.flush() ;
+       }
+
+
+       class InlineJavaException extends Exception {
+               private InlineJavaServer.InlineJavaException ije = null ;
+               
+               InlineJavaException(InlineJavaServer.InlineJavaException e) {
+                       ije = e ;
+               }
+
+               public InlineJavaServer.InlineJavaException GetException(){
+                       return ije ;
                }
        }
 
 
-       class InlineJavaPerlCallerException extends Exception {
-               InlineJavaPerlCallerException(String s) {
-                       super(s) ;
+       class PerlException extends Exception {
+               private Object obj = null ;
+
+               PerlException(Object o) {
+                       obj = o ;
+               }
+
+               public Object GetObject(){
+                       return obj ;
                }
        }
 
 
-       public Object CallPerl(String pkg, String method, Object args[]) throws 
InlineJavaPerlCallerException {
+       public Object CallPerl(String pkg, String method, Object args[]) throws 
InlineJavaException, PerlException {
+               if (InlineJavaServer.instance == null){
+                       System.err.println("Can't use InlineJavaPerlCaller 
outside of an Inline::Java context") ;
+                       System.err.flush() ;
+                       System.exit(1) ;
+               }
+
                try {
                        return InlineJavaServer.instance.Callback(pkg, method, 
args) ;
                }
                catch (InlineJavaServer.InlineJavaException e){
-                       throw new InlineJavaPerlCallerException(e.getMessage()) 
;
+                       throw new InlineJavaException(e) ;
+               }
+               catch (InlineJavaServer.InlineJavaPerlException e){
+                       throw new PerlException(e.GetObject()) ;
                }
        }
 }
diff --git a/Java/Init.pm b/Java/Init.pm
index 4d234ad..90e4eac 100644
--- a/Java/Init.pm
+++ b/Java/Init.pm
@@ -254,7 +254,7 @@ public class InlineJavaServer {
        }
 
 
-       public Object Callback(String pkg, String method, Object args[]) throws 
InlineJavaException {
+       public Object Callback(String pkg, String method, Object args[]) throws 
InlineJavaException, InlineJavaPerlException {
                Object ret = null ;
 
                try {
@@ -290,8 +290,14 @@ public class InlineJavaServer {
                                StringTokenizer st = new StringTokenizer(resp, 
" ") ;
                                String c = st.nextToken() ;
                                if (c.equals("callback")){
+                                       boolean thrown = new 
Boolean(st.nextToken()).booleanValue() ;
                                        String arg = st.nextToken() ;
                                        ret = 
ijc.CastArgument(java.lang.Object.class, arg) ;
+
+                                       if (thrown){
+                                               throw new 
InlineJavaPerlException(ret) ;
+                                       }
+
                                        break ;
                                }       
                                else{
@@ -392,6 +398,23 @@ public class InlineJavaServer {
 
 
        /*
+               Exception thrown by Perl callbacks.
+       */
+       class InlineJavaPerlException extends Exception {
+               private Object obj = null ;
+
+
+               InlineJavaPerlException(Object o) {
+                       obj = o ;
+               }
+
+               public Object GetObject(){
+                       return obj ;
+               }
+       }
+
+
+       /*
                Exception thrown by this code while trying to cast arguments
        */
        class InlineJavaCastException extends InlineJavaException {
@@ -401,6 +424,7 @@ public class InlineJavaServer {
        }
 
 
+
        class InlineJavaInvocationTargetException extends InlineJavaException {
                Throwable t = null ;
 
@@ -409,7 +433,7 @@ public class InlineJavaServer {
                        t = _t ;
                }
 
-               public Throwable getThrowable(){
+               public Throwable GetThrowable(){
                        return t ;
                }
        }
@@ -471,7 +495,7 @@ class InlineJavaServerThrown {
                t = _t ;
        }
 
-       public Throwable getThrowable(){
+       public Throwable GetThrowable(){
                return t ;
        }
 }
diff --git a/Java/JNI.pm b/Java/JNI.pm
index 653ab93..3476a8b 100644
--- a/Java/JNI.pm
+++ b/Java/JNI.pm
@@ -39,7 +39,8 @@ sub dl_load_flags {
        my $f = basename($so) ;
        my $sep = Inline::Java::portable("PATH_SEP") ;
 
-       $Inline::Java::JNI::SO = Cwd::abs_path($dir) . $sep . $f ;
+       $Inline::Java::JNI::SO = Inline::Java::portable("RE_FILE", 
Cwd::abs_path($dir) . $sep . $f) ;
+       $Inline::Java::JNI::SO = Inline::Java::portable("RE_FILE_JAVA", 
$Inline::Java::JNI::SO) ;
 
        return DynaLoader::dl_load_flags() ;
 }
diff --git a/Java/Makefile.PL b/Java/Makefile.PL
index 76cdc35..d7d83be 100644
--- a/Java/Makefile.PL
+++ b/Java/Makefile.PL
@@ -117,19 +117,15 @@ sub wanted {
                $java_include_os = $File::Find::dir ;
        }
        if ($file eq $jvm_lib){
-               if ($File::Find::dir =~ /$JNI_VM/){
-                       print "Found $jvm_lib in $File::Find::dir...\n" ;
-                       $java_lib = $File::Find::dir ;
-               }
+               print "Found $jvm_lib in $File::Find::dir...\n" ;
+               $java_lib = $File::Find::dir ;
        }
        if ($file eq $jvm_so){
-               if ($File::Find::dir =~ /$JNI_VM/){
-                       print "Found $jvm_so in $File::Find::dir...\n" ;
-                       if (! defined($java_so)){
-                               $java_so = [] ;
-                       }
-                       push @{$java_so}, $File::Find::dir ;
+               print "Found $jvm_so in $File::Find::dir...\n" ;
+               if (! defined($java_so)){
+                       $java_so = [] ;
                }
+               push @{$java_so}, $File::Find::dir ;
        }
 }
 
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 01070a6..bc6f006 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -3,7 +3,7 @@ package Inline::Java::Protocol ;
 
 use strict ;
 
-$Inline::Java::Protocol::VERSION = '0.30' ;
+$Inline::Java::Protocol::VERSION = '0.31' ;
 
 use Inline::Java::Object ;
 use Inline::Java::Array ;
@@ -352,7 +352,13 @@ sub DeserializeObject {
 
                        if ($thrown){
                                Inline::Java::debug("throwing stub...") ;
-                               die $obj ;
+                               my ($msg, $score) = 
$obj->__isa('InlineJavaPerlCaller$PerlException') ;
+                               if ($msg){
+                                       die $obj ;
+                               }
+                               else{
+                                       die $obj->GetObject() ;
+                               }
                        }
                        else{
                                Inline::Java::debug("returning stub...") ;
@@ -541,7 +547,13 @@ class InlineJavaProtocol {
                                SetResponse(o) ;
                        }
                        catch (InlineJavaInvocationTargetException ite){
-                               SetResponse(new 
InlineJavaServerThrown(ite.getThrowable())) ;
+                               Throwable t = ite.GetThrowable() ;
+                               if (t instanceof 
InlineJavaPerlCaller.InlineJavaException){
+                                       throw 
((InlineJavaPerlCaller.InlineJavaException)t).GetException() ;
+                               }
+                               else{
+                                       SetResponse(new 
InlineJavaServerThrown(t)) ;
+                               }
                        }
                }
                else{
@@ -610,7 +622,12 @@ class InlineJavaProtocol {
                                String type = t.getClass().getName() ;
                                String msg = t.getMessage() ;
                                ijs.debug("Method " + name + " in class " + 
class_name + " threw exception " + type + ": " + msg) ;
-                               SetResponse(new InlineJavaServerThrown(t)) ;
+                               if (t instanceof 
InlineJavaPerlCaller.InlineJavaException){
+                                       throw 
((InlineJavaPerlCaller.InlineJavaException)t).GetException() ;
+                               }
+                               else{
+                                       SetResponse(new 
InlineJavaServerThrown(t)) ;
+                               }
                        }
                }
        }
@@ -944,7 +961,7 @@ class InlineJavaProtocol {
                        boolean thrown = false ;
                        if (o instanceof InlineJavaServerThrown){ 
                                thrown = true ;
-                               o = ((InlineJavaServerThrown)o).getThrowable() ;
+                               o = ((InlineJavaServerThrown)o).GetThrowable() ;
                        }                       
                        int id = ijs.objid ;
                        ijs.PutObject(id, o) ;
diff --git a/TODO b/TODO
index eb58166..152e437 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,12 @@
 CODE:
-- Callbacks
+- Add comments to place that may not be thread safe (in Perl)
+- Do more research on JNI and threads to make JNI mode
+  more robust
+
 
 TEST:
-- Add test script for configuration options (other than BIN)
+
+
+DOCUMENTATION:
+- Callbacks
 
diff --git a/t/13_callbacks.t b/t/13_callbacks.t
index a44b347..418feac 100644
--- a/t/13_callbacks.t
+++ b/t/13_callbacks.t
@@ -14,7 +14,7 @@ use Inline::Java qw(caught) ;
 
 
 BEGIN {
-       plan(tests => 14) ;
+       plan(tests => 17) ;
 }
 
 my $t = new t10() ;
@@ -37,20 +37,24 @@ my $t = new t10() ;
 
                ok($t->cat_via_perl("Inline", "Java"), "InlineJava") ;
 
-               eval {$t->death_via_perl()} ; ok($@, qr/death/) ;
+               ok(twister(20, 0, 0), "return perl twister") ;
+               ok($t->twister(20, 0, 0), "return java twister") ;
 
+               eval {twister(20, 0, 1)} ; ok($@, qr/^throw perl twister/) ;
+                               
                my $msg = '' ;
-               eval {$t->except()} ; 
+               eval {$t->twister(20, 0, 1)} ;
                if ($@) {
-                       if 
(caught('InlineJavaPerlCaller$InlineJavaPerlCallerException')){
+                       if (caught('t10$OwnException')){
                                $msg = $@->getMessage() ;
                        }
                        else{
                                die $@ ;
                        }
                }
-               ok($msg, "test") ;
-       
+               ok($msg, "throw java twister") ;
+
+               eval {$t->bug()} ; ok($@, qr/^bug/) ;
        } ;
        if ($@){
                if (caught("java.lang.Throwable")){
@@ -107,8 +111,22 @@ sub add_via_java_t {
 }
 
 
-sub death {
-       die("death") ;
+sub twister {
+       my $max = shift ;
+       my $cnt = shift ;
+       my $explode = shift ;
+
+       if ($cnt == $max){
+               if ($explode){
+                       die("throw perl twister") ;
+               }
+               else{
+                       return "return perl twister" ;
+               }
+       }
+       else{
+               return $t->twister($max, $cnt+1, $explode) ;
+       }
 }
 
 
@@ -120,6 +138,13 @@ __Java__
 import java.io.* ;
 
 class t10 extends InlineJavaPerlCaller {
+       class OwnException extends Exception {
+               OwnException(String msg){
+                       super(msg) ;
+               }
+       }
+
+
        public t10() {
        }
 
@@ -139,7 +164,7 @@ class t10 extends InlineJavaPerlCaller {
                return a * b ;
        }
 
-       public int silly_mul_via_perl(int a, int b) throws 
InlineJavaPerlCallerException {
+       public int silly_mul_via_perl(int a, int b) throws InlineJavaException, 
PerlException {
                int ret = 0 ;
                for (int i = 0 ; i < b ; i++){
                        ret = add_via_perl(ret, a) ;
@@ -148,44 +173,37 @@ class t10 extends InlineJavaPerlCaller {
        }
 
 
-       public int add_via_perl(int a, int b) throws 
InlineJavaPerlCallerException {
+       public int add_via_perl(int a, int b) throws InlineJavaException, 
PerlException {
                String val = (String)CallPerl("main", "add", 
                        new Object [] {new Integer(a), new Integer(b)}) ;
 
                return new Integer(val).intValue() ;
        }
 
-       public void death_via_perl() throws InlineJavaPerlCallerException {     
        
+       public void death_via_perl() throws InlineJavaException, PerlException {
                InlineJavaPerlCaller c = new InlineJavaPerlCaller() ;
                c.CallPerl("main", "death", null) ;
        }
 
-       public void except() throws InlineJavaPerlCallerException {             
-               throw new 
InlineJavaPerlCaller.InlineJavaPerlCallerException("test") ;
+       public void except() throws InlineJavaException, PerlException {        
        
+               throw new PerlException("test") ;
        }
 
-       public int mul_via_perl(int a, int b) throws 
InlineJavaPerlCallerException {
+       public int mul_via_perl(int a, int b) throws InlineJavaException, 
PerlException {
                String val = (String)CallPerl("main", "mul", 
                        new Object [] {new Integer(a), new Integer(b)}) ;
 
                return new Integer(val).intValue() ;
        }
 
-       public String cat_via_perl(String a, String b) throws 
InlineJavaPerlCallerException {
-               String val = (String)CallPerl("main", "cat", 
-                       new Object [] {a, b}) ;
-
-               return val ;
-       }
-
-       public int add_via_perl_via_java(int a, int b) throws 
InlineJavaPerlCallerException {
+       public int add_via_perl_via_java(int a, int b) throws 
InlineJavaException, PerlException {
                String val = (String)CallPerl("main", "add_via_java", 
                        new Object [] {new Integer(a), new Integer(b)}) ;
 
                return new Integer(val).intValue() ;
        }
 
-       static public int add_via_perl_via_java_t(t10 t, int a, int b) throws 
InlineJavaPerlCallerException {
+       static public int add_via_perl_via_java_t(t10 t, int a, int b) throws 
InlineJavaException, PerlException {
                InlineJavaPerlCaller c = new InlineJavaPerlCaller() ;
                String val = (String)c.CallPerl("main", "add_via_java_t", 
                        new Object [] {t, new Integer(a), new Integer(b)}) ;
@@ -193,7 +211,8 @@ class t10 extends InlineJavaPerlCaller {
                return new Integer(val).intValue() ;
        }
 
-       public int silly_mul_via_perl_via_java(int a, int b) throws 
InlineJavaPerlCallerException {
+
+       public int silly_mul_via_perl_via_java(int a, int b) throws 
InlineJavaException, PerlException {
                int ret = 0 ;
                for (int i = 0 ; i < b ; i++){
                        String val = (String)CallPerl("main", "add_via_java", 
@@ -202,5 +221,34 @@ class t10 extends InlineJavaPerlCaller {
                }
                return ret ;
        }
+
+
+       public String cat_via_perl(String a, String b) throws 
InlineJavaException, PerlException {
+               String val = (String)CallPerl("main", "cat", 
+                       new Object [] {a, b}) ;
+
+               return val ;
+       }
+
+       public String twister(int max, int cnt, int explode) throws 
InlineJavaException, PerlException, OwnException {
+               if (cnt == max){
+                       if (explode > 0){
+                               throw new OwnException("throw java twister") ;
+                       }
+                       else{
+                               return "return java twister" ;
+                       }
+               }
+               else{
+                       return (String)CallPerl("main", "twister", 
+                               new Object [] {new Integer(max), new 
Integer(cnt+1), new Integer(explode)}) ;
+               }
+       }
+
+
+       public void bug() throws InlineJavaException {
+               throw new InlineJavaException(
+                       InlineJavaServer.instance. new 
InlineJavaException("bug")) ;
+       }
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to