[libinline-java-perl] 134/398: Initial revision
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 e35a29da80d307bda8eb2da9e882004bd7d26a0d
Author: Patrick LeBoutillier <patl at cpan.org>
Date: Wed Jan 9 16:11:15 2002 +0000
Initial revision
---
Java/Portable.pm | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
t/09_shared_alone.t | 45 ++++++++++++++++++
t/10_shared_mult.t | 84 ++++++++++++++++++++++++++++++++
t/11_shared_fork.t | 79 +++++++++++++++++++++++++++++++
4 files changed, 342 insertions(+)
diff --git a/Java/Portable.pm b/Java/Portable.pm
new file mode 100644
index 0000000..82fcc53
--- /dev/null
+++ b/Java/Portable.pm
@@ -0,0 +1,134 @@
+package Inline::Java::Portable ;
+ at Inline::Java::Portable::ISA = qw(Exporter) ;
+
+ at EXPORT = qw(portable) ;
+
+
+use strict ;
+
+$Inline::Java::Portable::VERSION = '0.31' ;
+
+
+use Exporter ;
+use Carp ;
+use Config ;
+
+# Here is some code to figure out if we are running on command.com
+# shell under Windows.
+my $COMMAND_COM =
+ (
+ ($^O eq 'MSWin32')&&
+ (
+ ($ENV{PERL_INLINE_JAVA_COMMAND_COM})||
+ (
+ (defined($ENV{COMSPEC}))&&
+ ($ENV{COMSPEC} =~ /(command|4dos)\.com/i)
+ )||
+ (`ver` =~ /win(dows )?(9[58]|m[ei])/i)
+ )
+ ) || 0 ;
+
+
+# Used when this module is used by itself, this stubs the requirements
+sub use_alone {
+ *Inline::Java::debug = sub {} ;
+}
+
+
+sub portable {
+ my $key = shift ;
+ my $val = shift ;
+
+ my $defmap = {
+ EXE_EXTENSION => $Config{exe_ext},
+ GOT_ALARM => $Config{d_alarm},
+ GOT_FORK => $Config{d_fork},
+ ENV_VAR_PATH_SEP => $Config{path_sep},
+ ENV_VAR_PATH_SEP_CP => ':',
+ IO_REDIR => '2>&1',
+ COMMAND_COM => 0,
+ SUB_FIX_CLASSPATH => undef,
+ JVM_LIB => 'libjvm.so',
+ JVM_SO => 'libjvm.so',
+ } ;
+
+ my $map = {
+ MSWin32 => {
+ ENV_VAR_PATH_SEP_CP => ';',
+ # 2>&1 doesn't work under command.com
+ IO_REDIR => ($COMMAND_COM ? '' : undef),
+ COMMAND_COM => $COMMAND_COM,
+ JVM_LIB => 'jvm.lib',
+ JVM_SO => 'jvm.dll',
+ },
+ cygwin => {
+ ENV_VAR_PATH_SEP_CP => ';',
+ SUB_FIX_CLASSPATH => sub {
+ my $val = shift ;
+ if (defined($val)&&($val)){
+ $val = `cygpath -w \"$val\"` ;
+ chomp($val) ;
+ }
+ return $val ;
+ },
+ JVM_LIB => 'jvm.lib',
+ JVM_SO => 'jvm.dll',
+ },
+ } ;
+
+ if (! exists($defmap->{$key})){
+ croak "Portability issue $key not defined!" ;
+ }
+
+ if ((defined($map->{$^O}))&&(defined($map->{$^O}->{$key}))){
+ if ($key =~ /^RE_/){
+ if (defined($val)){
+ my $f = $map->{$^O}->{$key}->[0] ;
+ my $t = $map->{$^O}->{$key}->[1] ;
+ $val =~ s/$f/$t/g ;
+ Inline::Java::debug("portable: $key => $val for $^O is '$val'") ;
+ return $val ;
+ }
+ else{
+ Inline::Java::debug("portable: $key for $^O is 'undef'") ;
+ return undef ;
+ }
+ }
+ elsif ($key =~ /^SUB_/){
+ my $sub = $map->{$^O}->{$key} ;
+ if (defined($sub)){
+ $val = $sub->($val) ;
+ Inline::Java::debug("portable: $key => $val for $^O is '$val'") ;
+ return $val ;
+ }
+ else{
+ return $val ;
+ }
+ }
+ else{
+ Inline::Java::debug("portable: $key for $^O is '$map->{$^O}->{$key}'") ;
+ return $map->{$^O}->{$key} ;
+ }
+ }
+ else{
+ if ($key =~ /^RE_/){
+ Inline::Java::debug("portable: $key => $val for $^O is default '$val'") ;
+ return $val ;
+ }
+ if ($key =~ /^SUB_/){
+ Inline::Java::debug("portable: $key => $val for $^O is default '$val'") ;
+ return $val ;
+ }
+ else{
+ Inline::Java::debug("portable: $key for $^O is default '$defmap->{$key}'") ;
+ return $defmap->{$key} ;
+ }
+ }
+}
+
+
+1 ;
+
+
+
+
diff --git a/t/09_shared_alone.t b/t/09_shared_alone.t
new file mode 100644
index 0000000..212a0d4
--- /dev/null
+++ b/t/09_shared_alone.t
@@ -0,0 +1,45 @@
+use strict ;
+use Test ;
+
+use Inline Config =>
+ DIRECTORY => './_Inline_test' ;
+
+use Inline (
+ Java => 'DATA',
+ SHARED_JVM => 1,
+) ;
+
+
+my $JNI = Inline::Java::__get_JVM()->{JNI} ;
+plan(tests => ($JNI ? 1 : 3)) ;
+
+
+if ($JNI){
+ skip("JNI", 1) ;
+ Inline::Java::shutdown_JVM() ;
+ exit ;
+}
+
+
+my $t = new t9() ;
+
+{
+ ok($t->{i}, 5) ;
+ ok(Inline::Java::i_am_JVM_owner()) ;
+}
+
+ok($t->__get_private()->{proto}->ObjectCount(), 1) ;
+
+
+__END__
+
+__Java__
+
+class t9 {
+ static public int i = 5 ;
+
+ public t9(){
+ }
+}
+
+
diff --git a/t/10_shared_mult.t b/t/10_shared_mult.t
new file mode 100644
index 0000000..1dd1dd3
--- /dev/null
+++ b/t/10_shared_mult.t
@@ -0,0 +1,84 @@
+package t10 ;
+
+use strict ;
+use Test ;
+
+
+use Inline Config =>
+ DIRECTORY => './_Inline_test' ;
+
+
+use Inline (
+ Java => 't/shared.java',
+ SHARED_JVM => 1,
+ NAME => 't10',
+) ;
+
+my $JNI = Inline::Java::__get_JVM()->{JNI} ;
+plan(tests => ($JNI ? 1 : 8)) ;
+
+if ($JNI){
+ skip("JNI", 1) ;
+ Inline::Java::shutdown_JVM() ;
+ exit ;
+}
+
+
+
+eval <<CODE1;
+ my \$t = new t10::t10() ;
+ {
+ ok(\$t->{i}++, 5) ;
+ ok(Inline::Java::i_am_JVM_owner()) ;
+ Inline::Java::release_JVM() ;
+ ok(! Inline::Java::i_am_JVM_owner()) ;
+ }
+CODE1
+if ($@){
+ die($@) ;
+}
+
+my $JVM1 = Inline::Java::__get_JVM() ;
+$JVM1->{destroyed} = 1 ;
+Inline::Java::__clear_JVM() ;
+
+eval <<CODE2;
+ use Inline (
+ Java => 't/shared.java',
+ SHARED_JVM => 1,
+ NAME => 't10',
+ ) ;
+
+ my \$t = new t10::t10() ;
+ {
+ ok(\$t->{i}++, 6) ;
+ ok(! Inline::Java::i_am_JVM_owner()) ;
+ }
+CODE2
+if ($@){
+ die($@) ;
+}
+
+my $JVM2 = Inline::Java::__get_JVM() ;
+$JVM2->{destroyed} = 1 ;
+Inline::Java::__clear_JVM() ;
+
+eval <<CODE3;
+ use Inline (
+ Java => 't/shared.java',
+ SHARED_JVM => 1,
+ NAME => 't10',
+ ) ;
+
+ my \$t = new t10::t10() ;
+ {
+ ok(\$t->{i}, 7) ;
+ ok(! Inline::Java::i_am_JVM_owner()) ;
+ Inline::Java::capture_JVM() ;
+ ok(Inline::Java::i_am_JVM_owner()) ;
+ }
+CODE3
+if ($@){
+ die($@) ;
+}
+
diff --git a/t/11_shared_fork.t b/t/11_shared_fork.t
new file mode 100644
index 0000000..029b560
--- /dev/null
+++ b/t/11_shared_fork.t
@@ -0,0 +1,79 @@
+use strict ;
+use Test ;
+
+use Inline Config =>
+ DIRECTORY => './_Inline_test' ;
+
+use Inline (
+ Java => 'DATA',
+ SHARED_JVM => 1,
+) ;
+
+
+my $nb = 10 ;
+
+my $JNI = Inline::Java::__get_JVM()->{JNI} ;
+my $fork = Inline::Java::portable('GOT_FORK') ;
+plan(tests => ($JNI ? 1 : ($fork ? $nb + 1 : 1))) ;
+
+
+if ($JNI){
+ skip("JNI", 1) ;
+ Inline::Java::shutdown_JVM() ;
+ exit ;
+}
+
+if (! $fork){
+ skip("fork", 1) ;
+ Inline::Java::shutdown_JVM() ;
+ exit ;
+}
+
+
+$t13::i = 0 ;
+
+my $sum = (($nb) * ($nb + 1)) / 2 ;
+for (my $i = 0 ; $i < $nb ; $i++){
+ if (! fork()){
+ do_child($i) ;
+ }
+}
+
+
+# Wait for kids to finish
+for (my $i = 0 ; $i < $nb ; $i++){
+ sleep(1) ;
+ ok(1) ;
+}
+
+ok($t13::i, $sum) ;
+
+
+sub do_child {
+ my $i = shift ;
+
+ Inline::Java::reconnect_JVM() ;
+
+ my $t = new t13() ;
+ for (my $j = 0 ; $j <= $i ; $j++){
+ $t->incr_i() ;
+ }
+ exit ;
+}
+
+
+__DATA__
+
+__Java__
+
+
+class t13 {
+ static public int i = 0 ;
+
+ public t13(){
+ }
+
+ public void incr_i(){
+ i++ ;
+ }
+}
--
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