[libinline-java-perl] 218/398: 0.40 is pretty much finished.
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:43:05 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 6b3cfd2fc48297ea29486acfee18499998ba5eb3
Author: patrick_leb <>
Date: Wed Apr 9 01:56:13 2003 +0000
0.40 is pretty much finished.
---
Java.pm | 29 +++++++++++++++++++++++------
Java.pod | 3 ++-
Java/Array.pm | 22 +++++++++++-----------
Java/JVM.pm | 17 ++++++++++++++++-
Java/Makefile.PL | 26 +++++++++++++++-----------
Java/Object.pm | 16 ++++++++--------
Java/Portable.pm | 12 ++++++++----
Java/Protocol.pm | 6 +++---
Java/sources/InlineJavaServer.java | 4 ++--
MANIFEST | 14 ++++++++++++++
Makefile.PL | 13 +++++++++----
README | 5 ++++-
TODO | 10 +++++++---
t/05_arrays.t | 11 ++++++++++-
t/10_5_shared_fork.t | 7 ++++++-
t/no_const.class | Bin 231 -> 231 bytes
t/t1.pl | 24 +++---------------------
t/types.class | Bin 15 -> 489 bytes
18 files changed, 141 insertions(+), 78 deletions(-)
diff --git a/Java.pm b/Java.pm
index a659662..512bffb 100644
--- a/Java.pm
+++ b/Java.pm
@@ -35,7 +35,7 @@ use Inline::Java::Callback ;
# Must be last.
use Inline::Java::JVM ;
# Our default J2SK
-require File::Spec->catfile('Java', 'DefaultJ2SDK.pl') ;
+require File::Spec->catfile('Java', 'default_j2sdk.pl') ;
# This is set when the script is over.
@@ -139,10 +139,10 @@ sub validate {
if ($o->get_java_config('PORT') == -1){
if ($o->get_java_config('SHARED_JVM')){
- $o->set_java_config('PORT') = 7891 ;
+ $o->set_java_config('PORT', 7890) ;
}
else{
- $o->set_java_config('PORT') = 7890 ;
+ $o->set_java_config('PORT', -7890) ;
}
}
@@ -255,14 +255,29 @@ sub build {
($cwd) = $cwd =~ /(.*)/ ;
}
+ # We must grab this before we change to the build dir because
+ # it could be relative...
+ my $server_jar = get_server_jar() ;
+
# Create the build dir and go there
my $build_dir = $o->get_api('build_dir') ;
$o->mkpath($build_dir) ;
chdir $build_dir ;
my $code = $o->get_api('code') ;
+ my $pcode = $code ;
my $study_only = ($code =~ /^(STUDY|SERVER)$/) ;
my $source = ($study_only ? '' : $o->get_api('modfname') . ".java") ;
+
+ # Parse code to check for public class
+ $pcode =~ s/\\\"//g ;
+ $pcode =~ s/\"(.*?)\"//g ;
+ $pcode =~ s/\/\*(.*?)\*\///gs ;
+ $pcode =~ s/\/\/(.*)$//gm ;
+ if ($pcode =~ /public\s+class\s+(\w+)/){
+ # $source = "$1.java" ;
+ }
+
my $install_dir = File::Spec->catdir($o->get_api('install_lib'),
'auto', $o->get_api('modpname')) ;
$o->mkpath($install_dir) ;
@@ -288,12 +303,13 @@ sub build {
}
my $cp = $ENV{CLASSPATH} || '' ;
- $ENV{CLASSPATH} = make_classpath($o->get_java_config('CLASSPATH'), get_server_jar(), @prev_install_dirs) ;
+ $ENV{CLASSPATH} = make_classpath($o->get_java_config('CLASSPATH'), $server_jar, @prev_install_dirs) ;
+ Inline::Java::debug(2, "classpath: $ENV{CLASSPATH}") ;
my $cmd = "\"$javac\" -d \"$install_dir\" $source > cmd.out $redir" ;
if ($o->get_config('UNTAINT')){
($cmd) = $cmd =~ /(.*)/ ;
}
- Inline::Java::debug(1, "$cmd") ;
+ Inline::Java::debug(2, "$cmd") ;
my $res = system($cmd) ;
$res and do {
croak $o->compile_error_msg($cmd) ;
@@ -385,6 +401,7 @@ sub load {
if (! $JVM){
my $cp = $ENV{CLASSPATH} || '' ;
$ENV{CLASSPATH} = get_server_jar() ;
+ Inline::Java::debug(2, "classpath: $ENV{CLASSPATH}") ;
$JVM = new Inline::Java::JVM($o) ;
$ENV{CLASSPATH} = $cp ;
@@ -999,4 +1016,4 @@ sub caught {
}
-1 ;
\ No newline at end of file
+1 ;
diff --git a/Java.pod b/Java.pod
index f557e05..7b8da00 100644
--- a/Java.pod
+++ b/Java.pod
@@ -109,7 +109,8 @@ behavior of C<Inline::Java>:
Specifies the starting port number for the server. If many
C<Inline::Java> blocks are declared, the port number is
incremented each time.
- Default is 7890.
+ Default is 0 (next available port number).
+ Default for SHARED_JVM mode is 7890.
Ex: PORT => 4567
Note: This configuration option only has an effect on the first
'use Inline Java' call inside a Perl script, since all other calls
diff --git a/Java/Array.pm b/Java/Array.pm
index 18232c7..8903a2f 100644
--- a/Java/Array.pm
+++ b/Java/Array.pm
@@ -151,8 +151,6 @@ sub DESTROY {
$OBJECTS->{$this} = undef ;
}
else{
- # Here we can't untie because we still have a reference in $OBJECTS
- # untie @{$this} ;
Inline::Java::debug(4, "destroying Inline::Java::Array") ;
}
}
@@ -435,9 +433,12 @@ sub ValidateArray {
croak "'$ref' is not an array reference" ;
}
+ my $map = $this->{map} ;
+ if (! exists($map->{$level}->{max})){
+ $map->{$level}->{max} = 0 ;
+ }
$this->ValidateElements($ref, $array, $level) ;
- my $map = $this->{map} ;
foreach my $elem (@{$ref}){
if ((defined($elem))&&(UNIVERSAL::isa($elem, "ARRAY"))){
# All the elements at this level are sub-arrays.
@@ -457,7 +458,7 @@ sub ValidateArray {
my @dims = () ;
my $max_cells = 1 ;
foreach my $l (@levels){
- push @dims, ($map->{$l}->{max} || 0) ;
+ push @dims, $map->{$l}->{max} ;
$max_cells *= $map->{$l}->{max} ;
}
my $nb_cells = ($map->{$last}->{count} || 0) ;
@@ -485,10 +486,8 @@ sub ValidateElements {
my $level = shift ;
my $map = $this->{map} ;
-
my $cnt = scalar(@{$ref}) ;
- my $max = $map->{$level}->{max} || 0 ;
-
+ my $max = $map->{$level}->{max} ;
if ($cnt > $max){
$map->{$level}->{max} = $cnt ;
}
@@ -513,8 +512,7 @@ sub ValidateElements {
}
$map->{$level}->{count}++ ;
}
-}
-
+}
sub CheckMap {
my $this = shift ;
@@ -555,7 +553,9 @@ sub FillArray {
my $max = $map->{$level}->{max} ;
my $nb = scalar(@{$array}) ;
- if ($map->{$level}->{type} eq "SUB_ARRAY"){
+ my $type = $map->{$level}->{type} ;
+ # Type can be undefined when array is zero length.
+ if ((defined($type))&&($map->{$level}->{type} eq "SUB_ARRAY")){
foreach my $elem (@{$array}){
if (! defined($elem)){
$elem = [] ;
@@ -627,4 +627,4 @@ sub MakeElementList {
}
-1 ;
\ No newline at end of file
+1 ;
diff --git a/Java/JVM.pm b/Java/JVM.pm
index 405165f..74f425a 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -60,6 +60,21 @@ sub new {
$this->{port} = $o->get_java_config('PORT') ;
$this->{host} = "localhost" ;
+ # Grab the next free port number and release it.
+ if ($this->{port} < 0){
+ my $sock = IO::Socket::INET->new(
+ Listen => 0, Proto => 'tcp',
+ LocalAddr => 'localhost', LocalPort => 0) ;
+ if ($sock){
+ $this->{port} = $sock->sockport() ;
+ close($sock) ;
+ }
+ else{
+ # Revert to the default.
+ $this->{port} = - $this->{port} ;
+ }
+ }
+
# Check if JVM is already running
if ($this->{shared}){
eval {
@@ -76,7 +91,7 @@ sub new {
my $shared = ($this->{shared} ? "true" : "false") ;
my $cmd = "\"$java\" org.perl.inline.java.InlineJavaServer $debug $this->{port} $shared" ;
- Inline::Java::debug(1, $cmd) ;
+ Inline::Java::debug(2, $cmd) ;
if ($o->get_config('UNTAINT')){
($cmd) = $cmd =~ /(.*)/ ;
}
diff --git a/Java/Makefile.PL b/Java/Makefile.PL
index d06d272..1109d22 100644
--- a/Java/Makefile.PL
+++ b/Java/Makefile.PL
@@ -6,7 +6,7 @@ use File::Spec ;
require "Portable.pm" ;
# The file we just produced in the parent Makefile.PL
-require "DefaultJ2SDK.pl" ;
+require "default_j2sdk.pl" ;
# Some shortcuts while developing
@@ -43,6 +43,7 @@ my $files = {
foreach my $f (@files){
$files->{$f}->{selected} = undef ;
$files->{$f}->{choices} = [] ;
+ $files->{$f}->{default_choice} = 1 ;
}
@@ -58,10 +59,17 @@ if (($build_jni || AskYN("Do you wish to build the JNI extension?", 'y'))){
$jdk_dir = Inline::Java::get_default_j2sdk() ;
- my $type = FindDefaultVMType() ;
-
find(\&search, $jdk_dir) ;
+ my $type = FindDefaultVMType() ;
+ my $cnt = 1 ;
+ foreach my $c (@{$files->{$jvm_lib}->{choices}}){
+ if ($c =~ /$type/){
+ $files->{$jvm_lib}->{default_choice} = $cnt ;
+ }
+ $cnt++ ;
+ }
+
my $done = 0 ;
foreach my $f (@files){
my $cnt = scalar(@{$files->{$f}->{choices}}) ;
@@ -74,7 +82,7 @@ if (($build_jni || AskYN("Do you wish to build the JNI extension?", 'y'))){
$files->{$f}->{selected} = $files->{$f}->{choices}->[0] ;
}
else{
- Choose($f, $type) ;
+ Choose($f) ;
}
}
if (! $done){
@@ -195,20 +203,16 @@ sub FindDefaultVMType {
sub Choose {
my $f = shift ;
- my $type = shift ;
my $o = $files->{$f} ;
my $cnt = 0 ;
my $def = undef ;
foreach my $f (@{$o->{choices}}){
$cnt++ ;
- if ($f =~ /$type/){
- $def = $cnt ;
- }
- print "$cnt- $f\n" ;
+ print "$cnt) $f\n" ;
}
- my $idx = AskSub("Please select from the above list (using the corresponding number) which '$f' to use:",
- $def, sub {(($_[0] >= 1)&&($_[0] <= $cnt))}) ;
+ my $idx = AskSub("Please select from the above list which '$f' to use:",
+ $o->{default_choice}, sub {(($_[0] >= 1)&&($_[0] <= $cnt))}) ;
$o->{selected} = $o->{choices}->[int($idx) - 1] ;
print "\n" ;
diff --git a/Java/Object.pm b/Java/Object.pm
index 0b5edc6..6f6c9e9 100644
--- a/Java/Object.pm
+++ b/Java/Object.pm
@@ -329,9 +329,15 @@ sub DESTROY {
Inline::Java::debug(4, "destroying Inline::Java::Object::Tie") ;
if (! Inline::Java::get_DONE()){
+
+ my $class = $this->__get_private()->{class} ;
+ Inline::Java::debug(2, "destroying object in java ($class):") ;
+
+ # I can't find any other trace of this weak_ref stuff, but
+ # it's not a bad idea...
if (! $this->__get_private()->{weak_ref}){
# This one is very tricky:
- # Here we want to be carefull since this can be called
+ # Here we want to be careful since this can be called
# at scope end, but the scope end might be triggered
# by another croak, so we need to record and propagate
# the current $@
@@ -370,12 +376,6 @@ sub DESTROY {
}
}
else{
- # Here we can't untie because we still have a reference in $PRIVATES
- # untie %{$this} ;
-
- my $class = $this->__get_private()->{class} ;
- Inline::Java::debug(2, "destroying object in java ($class):") ;
-
Inline::Java::debug(4, "destroying Inline::Java::Object") ;
}
}
@@ -544,4 +544,4 @@ sub DESTROY {
-1 ;
\ No newline at end of file
+1 ;
diff --git a/Java/Portable.pm b/Java/Portable.pm
index 1750a41..dfb0208 100644
--- a/Java/Portable.pm
+++ b/Java/Portable.pm
@@ -63,19 +63,21 @@ sub make_classpath {
push @fcp, (-d $p ? Cwd::abs_path($p) : $p) ;
delete $cp{$p} ;
}
+ else{
+ Inline::Java::debug(2, "classpath candidate '$p' scraped") ;
+ }
}
my $cp = join($sep, @fcp) ;
- Inline::Java::debug(1, "classpath: $cp") ;
return (wantarray ? @fcp : $cp) ;
}
sub get_jar_dir {
- return File::Spec->catdir(
+ return Cwd::abs_path(File::Spec->catpath(
(File::Spec->splitpath($INC{"Inline/Java.pm"}))[0,1],
- 'Java') ;
+ 'Java', '')) ;
}
@@ -120,6 +122,7 @@ sub portable {
SO_LIB_PATH_VAR => 'LD_LIBRARY_PATH',
ENV_VAR_PATH_SEP_CP => ':',
IO_REDIR => '2>&1',
+ MAKE => 'make',
DEV_NULL => '/dev/null',
COMMAND_COM => 0,
SUB_FIX_CLASSPATH => undef,
@@ -132,6 +135,7 @@ sub portable {
ENV_VAR_PATH_SEP_CP => ';',
# 2>&1 doesn't work under command.com
IO_REDIR => ($COMMAND_COM ? '' : undef),
+ MAKE => 'nmake',
DEV_NULL => 'nul',
COMMAND_COM => $COMMAND_COM,
SO_LIB_PATH_VAR => 'PATH',
@@ -205,4 +209,4 @@ sub portable {
}
-1 ;
\ No newline at end of file
+1 ;
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index a318c6b..c287367 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -32,7 +32,7 @@ sub AddClassPath {
return () ;
}
else{
- Inline::Java::debug(1, "adding to classpath: '$e'") ;
+ Inline::Java::debug(2, "adding to classpath: '$e'") ;
$CLASSPATH_ENTRIES{$e} = 1 ;
}
$e ;
@@ -283,7 +283,7 @@ sub CreateSignature {
my $proto = shift ;
my $del = shift || ", " ;
- my @p = map {$_ || ''} @{$proto} ;
+ my @p = map {(defined($_) ? $_ : '')} @{$proto} ;
return "(" . join($del, @p) . ")" ;
}
@@ -428,4 +428,4 @@ sub DESTROY {
}
-1 ;
\ No newline at end of file
+1 ;
diff --git a/Java/sources/InlineJavaServer.java b/Java/sources/InlineJavaServer.java
index 806a24f..79ac279 100644
--- a/Java/sources/InlineJavaServer.java
+++ b/Java/sources/InlineJavaServer.java
@@ -45,8 +45,8 @@ public class InlineJavaServer {
while (true){
try {
- // For now we pass our own InlineJavaUserClassLoader, but later we can implement
- // privacy by creating a new one.
+ // For now we pass our own InlineJavaUserClassLoader, but later
+ // we can implement privacy by creating a new one.
InlineJavaServerThread ijt = new InlineJavaServerThread(this, ss.accept(), ijucl) ;
ijt.start() ;
if (! shared_jvm){
diff --git a/MANIFEST b/MANIFEST
index 0e9445a..13f2bb8 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -17,6 +17,20 @@ Java/JVM.pm
Java/JNI.pm
Java/JNI.xs
Java/typemap
+Java/sources/InlineJavaArray.java
+Java/sources/InlineJavaCastException.java
+Java/sources/InlineJavaClass.java
+Java/sources/InlineJavaException.java
+Java/sources/InlineJavaInvocationTargetException.java
+Java/sources/InlineJavaPerlCaller.java
+Java/sources/InlineJavaPerlException.java
+Java/sources/InlineJavaProtocol.java
+Java/sources/InlineJavaServer.java
+Java/sources/InlineJavaServerThread.java
+Java/sources/InlineJavaThrown.java
+Java/sources/InlineJavaUserClassLink.java
+Java/sources/InlineJavaUserClassLoader.java
+Java/sources/InlineJavaUtils.java
t/01_init.t
t/02_primitives.t
t/03_objects.t
diff --git a/Makefile.PL b/Makefile.PL
index f255d8e..ff8fbb6 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -23,9 +23,9 @@ foreach my $arg (@ARGV){
@ARGV = @new_args ;
if (! $jdk_dir){
- my $def_pl = File::Spec->catfile('Java', 'DefaultJ2SDK.pl') ;
+ my $def_pl = File::Spec->catfile('Java', 'default_j2sdk.pl') ;
if (-e $def_pl){
- require File::Spec->catfile('Java', 'DefaultJ2SDK.pl') ;
+ require File::Spec->catfile('Java', 'default_j2sdk.pl') ;
$jdk_dir = Inline::Java::get_default_j2sdk() ;
}
else{
@@ -59,9 +59,9 @@ foreach my $f ('javac', 'jar', 'java'){
# Now we have the J2SDK directory and it exists.
-# We will create the DefaultJ2SDK.pl file that
+# We will create the default_j2sdk.pl file that
# will contain that value for future use.
-my $def_jdk = File::Spec->catfile('Java', 'DefaultJ2SDK.pl') ;
+my $def_jdk = File::Spec->catfile('Java', 'default_j2sdk.pl') ;
open(J2SDK, ">$def_jdk") or
die("Can't open '$def_jdk' for writing: $!") ;
print J2SDK <<J2SDK_PL;
@@ -169,3 +169,8 @@ if (Inline::Java::Portable::portable('COMMAND_COM')){
close(MAKEFILE) ;
}
+my $make = Inline::Java::Portable::portable('MAKE') ;
+print "\nYou can continue the installation with the following commands:\n" ;
+print " % $make java\n" ;
+print " % $make\n" ;
+print " % $make test\n" ;
diff --git a/README b/README
index 2fae358..3e75c1e 100644
--- a/README
+++ b/README
@@ -70,7 +70,10 @@ WARNING: THIS IS ALPHA SOFTWARE. It is incomplete and possibly unreliable.
Inline::Java version 0.40 is a major upgrade that includes:
+ Patch by Doug MacEachern to allow running under servlet engines
-+ Other minor bug fixes and documentation corrections
++ Patch by John Kinsley for handling empty arrays
++ Custom ClassLoader allows for better isolation of user code and
+ dynamic 'CLASSPATH'
++ Many bug fixes and documentation corrections
Inline::Java version 0.33 is a minor upgrade that includes:
+ Improved and more flexible debug output
diff --git a/TODO b/TODO
index bb4b04e..87348d1 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,14 @@
CODE:
- Parse source code for "public class \w+" and use this for file name.
-- Fix install and compilation of jars.
-- Fix installation script for JNI.
+
+$code =~ s/\\\"//g ;
+$code =~ s/\"(.*?)\"//g ;
+$code =~ s/\/\*(.*?)\*\///gs ;
+$code =~ s/\/\/(.*)$///gm ;
+
- Write a test for a public class in a package.
- Retest all the small test stuff under Linux.
-- Restore Alpha status
+- Fix MANIFEST
TEST:
- Alpha
diff --git a/t/05_arrays.t b/t/05_arrays.t
index ee3ace7..c32b1a7 100644
--- a/t/05_arrays.t
+++ b/t/05_arrays.t
@@ -9,7 +9,7 @@ use Inline(
) ;
BEGIN {
- plan(tests => 50) ;
+ plan(tests => 55) ;
}
@@ -112,6 +112,7 @@ my $t = new types5() ;
eval {pop @{$b}} ; ok($@, qr/Operation POP/) ;
eval {shift @{$b}} ; ok($@, qr/Operation SHIFT/) ;
eval {splice(@{$b}, 0, 1)} ; ok($@, qr/Operation SPLICE/) ;
+ eval {$b->[10] = 5} ; ok($@, qr/out of bounds/) ;
# Cool stuff on arrays
$a = $t->_byte([12, 34, 56]) ;
@@ -119,6 +120,14 @@ my $t = new types5() ;
foreach my $e (@{$a}){
ok($e =~ /^(123|34|56)$/) ;
}
+
+ # Zero length arrays
+ $a = $t->_Byte([]) ;
+ ok(scalar(@$a), 0) ;
+ $a = $t->_StringString([[], []]) ;
+ ok(scalar(@{$a}), 2) ;
+ ok(scalar(@{$a->[0]}), 0) ;
+ ok(scalar(@{$a->[1]}), 0) ;
}
ok($t->__get_private()->{proto}->ObjectCount(), 1) ;
diff --git a/t/10_5_shared_fork.t b/t/10_5_shared_fork.t
index df46f66..f9e0264 100755
--- a/t/10_5_shared_fork.t
+++ b/t/10_5_shared_fork.t
@@ -16,7 +16,7 @@ BEGIN {
}
else{
$t10::nb = 10 ;
- plan(tests => $t10::nb + 1) ;
+ plan(tests => $t10::nb + 3) ;
}
}
@@ -50,6 +50,11 @@ for (my $i = 0 ; $i < $nb ; $i++){
ok($t10::t10::i, $sum) ;
+# Bring down the JVM
+ok(! Inline::Java::i_am_JVM_owner()) ;
+Inline::Java::capture_JVM() ;
+ok(Inline::Java::i_am_JVM_owner()) ;
+
sub do_child {
my $i = shift ;
diff --git a/t/no_const.class b/t/no_const.class
index 79d98bc..98ea5ef 100644
Binary files a/t/no_const.class and b/t/no_const.class differ
diff --git a/t/t1.pl b/t/t1.pl
index c1667e0..f909af6 100755
--- a/t/t1.pl
+++ b/t/t1.pl
@@ -4,20 +4,12 @@ use blib ;
use Inline Java => <<'END_OF_JAVA_CODE' ;
- class Pod_alu extends InlineJavaPerlCaller {
+
+class Pod_alu {
public Pod_alu(){
}
- public int add(int i, int j) throws InlineJavaException {
- try {
- CallPerl("main", "tt", null) ;
- CallPerl("main", "tt", new Object [] {"hello"}) ;
- CallPerl("main", "tt", new Object [] {"die"}) ;
- }
- catch (PerlException pe){
- System.out.println("perl died : " + (String)pe.GetObject()) ;
- }
-
+ public int add(int i, int j){
return i + j ;
}
@@ -28,16 +20,6 @@ use Inline Java => <<'END_OF_JAVA_CODE' ;
END_OF_JAVA_CODE
-sub tt {
- my $arg = shift ;
-
- print "$arg: it works!\n" ;
- if ($arg eq "die"){
- die("ouch!") ;
- }
-}
-
-
my $alu = new Pod_alu() ;
print($alu->add(9, 16) . "\n") ; # prints 25
print($alu->subtract(9, 16) . "\n") ; # prints -7
diff --git a/t/types.class b/t/types.class
index fc9e393..918c408 100644
Binary files a/t/types.class and b/t/types.class differ
--
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