[libinline-java-perl] 206/398: Changed encoding api (but not technique used) and added dynaload of -lthread under Solaris

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:04 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 d6b9bc0f56b19d408a0ddbe3b262676cc8353980
Author: patrick_leb <>
Date:   Thu Jul 11 14:56:53 2002 +0000

    Changed encoding api (but not technique used)
    and added dynaload of -lthread under Solaris
---
 Java/Class.pm    |  8 ++++----
 Java/Init.pm     | 12 ++++++++++--
 Java/JNI.pm      | 15 +++++++++++++++
 Java/JVM.pm      | 50 +-------------------------------------------------
 Java/Protocol.pm | 44 ++++++++++++++++++++++++++++----------------
 5 files changed, 58 insertions(+), 71 deletions(-)

diff --git a/Java/Class.pm b/Java/Class.pm
index 6b2e84d..28e0ed3 100644
--- a/Java/Class.pm
+++ b/Java/Class.pm
@@ -578,7 +578,7 @@ class InlineJavaClass {
 				}
 			}
 			else if (type.equals("scalar")){
-				String arg = ijp.pack((String)tokens.get(1)) ;
+				String arg = ijp.decode((String)tokens.get(1)) ;
 				ijs.debug(4, "args is scalar -> forcing to " + ap.getName()) ;
 				try	{
 					ret = ijp.CreateObject(ap, new Object [] {arg}, new Class [] {String.class}) ;
@@ -599,7 +599,7 @@ class InlineJavaClass {
 				ijs.debug(4, " result is " + ret.toString()) ;
 			}
 			else if (type.equals("scalar")){
-				String arg = ijp.pack(((String)tokens.get(1)).toLowerCase()) ;
+				String arg = ijp.decode(((String)tokens.get(1)).toLowerCase()) ;
 				ijs.debug(4, "args is scalar -> forcing to bool") ;
 				if ((arg.equals(""))||(arg.equals("0"))){
 					arg = "false" ;
@@ -621,7 +621,7 @@ class InlineJavaClass {
 				ijs.debug(4, " result is " + ret.toString()) ;
 			}
 			else if (type.equals("scalar")){
-				String arg = ijp.pack((String)tokens.get(1)) ;
+				String arg = ijp.decode((String)tokens.get(1)) ;
 				ijs.debug(4, "args is scalar -> forcing to char") ;
 				char c = '\0' ;
 				if (arg.length() == 1){
@@ -648,7 +648,7 @@ class InlineJavaClass {
 				// Here if we need a java.lang.Object.class, it's probably
 				// because we can store anything, so we use a String object.
 				if (p == java.lang.Object.class){
-					String arg = ijp.pack((String)tokens.get(1)) ;
+					String arg = ijp.decode((String)tokens.get(1)) ;
 					ret = arg ;
 				}
 				else{
diff --git a/Java/Init.pm b/Java/Init.pm
index 14f7de4..8f21487 100644
--- a/Java/Init.pm
+++ b/Java/Init.pm
@@ -155,7 +155,7 @@ public class InlineJavaServer {
 				resp = ijp.response ;
 			}
 			catch (InlineJavaException e){
-				String err = "error scalar:" + ijp.unpack(e.getMessage()) ;
+				String err = "error scalar:" + ijp.encode(e.getMessage()) ;
 				debug(3, "packet sent is " + err) ;
 				resp = err ;
 			}
@@ -339,7 +339,7 @@ public class InlineJavaServer {
 		if ((debug > 0)&&(debug >= level)){
 			StringBuffer sb = new StringBuffer() ;
 			for (int i = 0 ; i < level ; i++){
-				sb.append(" ") ;				
+				sb.append(" ") ;
 			}
 			System.err.println("[java][" + level + "]" + sb.toString() + s) ;
 			System.err.flush() ;
@@ -347,6 +347,14 @@ public class InlineJavaServer {
 	}
 
 
+	boolean reverse_members() {
+		String v = System.getProperty("java.version") ;
+		boolean no_rev = ((v.startsWith("1.2"))||(v.startsWith("1.3"))) ;
+
+		return (! no_rev) ;
+	}
+
+
 	/*
 		Startup
 	*/
diff --git a/Java/JNI.pm b/Java/JNI.pm
index 200c62e..4403187 100644
--- a/Java/JNI.pm
+++ b/Java/JNI.pm
@@ -11,6 +11,21 @@ use Carp ;
 use File::Basename ;
 
 
+if ($^O eq 'solaris'){
+	load_lib('-lthread') ;
+}
+
+
+sub load_lib {
+	my $l = shift ;
+	my $lib = (DynaLoader::dl_findfile($l))[0] ;	
+	
+    if ((! $lib)||(! defined(DynaLoader::dl_load_file($lib, 0x01)))){
+		carp("Couldn't load $l.") ;
+	}
+}
+
+
 # A place to attach the Inline object that is currently in Java land
 $Inline::Java::JNI::INLINE_HOOK = undef ;
 
diff --git a/Java/JVM.pm b/Java/JVM.pm
index f45a9ff..2ac123f 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -128,55 +128,6 @@ sub launch {
 }
 
 
-sub fork_launch {
-	my $this = shift ;
-	my $cmd = shift ;
-
-	# Setup pipe with our child
-	my $c2p = new IO::Pipe() ;
-
-	my $gcpid = undef ;
-	my $cpid = fork() ;
-	if (! defined($cpid)){
-		croak("Can't fork to detach JVM: $!") ;
-	}
-	elsif(! $cpid){
-		# Child
-		$c2p->writer() ; autoflush $c2p 1 ;
-
-		# Now we need to get $gcpid back to our script...
-		eval {
- 			$gcpid = $this->launch($cmd) ;
-		} ;
-		if ($@){
-			print $c2p "$@\n" ;
-		}
-		else{
-			print $c2p "pid: $gcpid\n" ;
-		}
-		close($c2p) ;
-		Inline::Java::set_DONE() ;
-		CORE::exit() ;
-	}
-	else{
-		# Parent
-		$c2p->reader() ;
-		my $line = <$c2p> ;
-		close($c2p) ;
-		chomp($line) ;
-		if ($line =~ /^pid: (.*)$/){
-			$gcpid = $1 ;
-		}
-		else{
-			croak $line ;
-		}
-		waitpid($cpid, 0) ;
-	}
-
-	return $gcpid ;
-}
-
-
 sub DESTROY {
 	my $this = shift ;
 
@@ -392,6 +343,7 @@ sub process_command {
 			$Inline::Java::JNI::INLINE_HOOK = $inline ;
 			$resp = $this->{JNI}->process_command($data) ;
 		}
+		chomp($resp) ;
 
 		Inline::Java::debug(3, "packet recv is $resp") ;
 
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 4dd670a..546ff68 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -250,7 +250,7 @@ sub ValidateArgs {
 			push @ret, "object:$class:$id" ;
 		}
 		else{
-			push @ret, "scalar:" . join(".", unpack("C*", $arg)) ;
+			push @ret, "scalar:" . encode($arg) ;
 		}
 	}
 
@@ -279,8 +279,8 @@ sub Send {
 	my $inline = Inline::Java::get_INLINE($this->{module}) ;
 	my $resp = Inline::Java::__get_JVM()->process_command($inline, $data) ;
 
-	if ($resp =~ /^error scalar:([\d.]*)$/){
-		my $msg = pack("C*", split(/\./, $1)) ;
+	if ($resp =~ /^error scalar:([\d.-]*)$/){
+		my $msg = decode($1) ;
 		Inline::Java::debug(3, "packet recv error: $msg") ;
 		croak $msg ;
 	}
@@ -297,8 +297,8 @@ sub DeserializeObject {
 	my $const = shift ;
 	my $resp = shift ;
 
-	if ($resp =~ /^scalar:([\d.]*)$/){
-		return pack("C*", split(/\./, $1)) ; 
+	if ($resp =~ /^scalar:([\d.-]*)$/){
+		return decode($1) ; 
 	}
 	elsif ($resp =~ /^undef:$/){
 		return undef ;
@@ -390,6 +390,20 @@ sub DeserializeObject {
 }
 
 
+sub encode {
+	my $s = shift ;
+
+	return join(".", unpack("C*", $s)) ;
+}
+
+
+sub decode {
+	my $s = shift ;
+
+	return pack("C*", split(/\./, $s)) ;
+}
+
+
 sub DESTROY {
 	my $this = shift ;
 
@@ -478,7 +492,7 @@ class InlineJavaProtocol {
 		StringTokenizer st2 = new StringTokenizer(st.nextToken(), ":") ;
 		st2.nextToken() ;
 
-		StringTokenizer st3 = new StringTokenizer(pack(st2.nextToken()), " ") ;
+		StringTokenizer st3 = new StringTokenizer(decode(st2.nextToken()), " ") ;
 
 		ArrayList class_list = new ArrayList() ;
 		while (st3.hasMoreTokens()){
@@ -523,7 +537,7 @@ class InlineJavaProtocol {
 			}
 
 			for (int j = 0 ; j < fields.length ; j++){
-				Field x = fields[j] ;
+				Field x = fields[(ijs.reverse_members() ? (fields.length - 1 - j) : j)] ;
 				String stat = (Modifier.isStatic(x.getModifiers()) ? " static " : " instance ") ;
 				Class decl = x.getDeclaringClass() ;
 				Class type = x.getType() ;
@@ -915,7 +929,7 @@ class InlineJavaProtocol {
 		ArrayList fl = new ArrayList(fa.length) ;
 		Class param = null ;
 		for (int i = 0 ; i < fa.length ; i++){
-			Field f = fa[i] ;
+			Field f = fa[(ijs.reverse_members() ? (fa.length - 1 - i) : i)] ;
 
 			if (f.getName().equals(name)){
 				ijs.debug(3, "found a " + name + " member") ;
@@ -929,7 +943,7 @@ class InlineJavaProtocol {
 			}
 		}
 
-		// Now we got a list of matching methods. 
+		// Now we got a list of matching members. 
 		// We have to figure out which one we will call.
 		if (fl.size() == 0){
 			throw new InlineJavaException(
@@ -940,7 +954,7 @@ class InlineJavaProtocol {
 			// Now we need to force the arguments received to match
 			// the methods signature.
 
-			// If we have more that one, we use tha last one, which is the most
+			// If we have more that one, we use the last one, which is the most
 			// specialized
 			Field f = (Field)fl.get(fl.size() - 1) ;
 			param = f.getType() ;
@@ -977,11 +991,11 @@ class InlineJavaProtocol {
 			return "undef:" ;
 		}
 		else if ((ijc.ClassIsNumeric(o.getClass()))||(ijc.ClassIsChar(o.getClass()))||(ijc.ClassIsString(o.getClass()))){
-			return "scalar:" + unpack(o.toString()) ;
+			return "scalar:" + encode(o.toString()) ;
 		}
 		else if (ijc.ClassIsBool(o.getClass())){
 			String b = o.toString() ;
-			return "scalar:" + unpack((b.equals("true") ? "1" : "0")) ;
+			return "scalar:" + encode((b.equals("true") ? "1" : "0")) ;
 		}
 		else {
 			// Here we need to register the object in order to send
@@ -1000,8 +1014,7 @@ class InlineJavaProtocol {
 
 
 
-	/* Equivalent to Perl pack */
-	public String pack(String s){
+	public String decode(String s){
 		StringTokenizer st = new StringTokenizer(s, ".") ;
 		StringBuffer sb = new StringBuffer() ;
 		while (st.hasMoreTokens()){
@@ -1014,8 +1027,7 @@ class InlineJavaProtocol {
 	}
 
 
-	/* Equivalent to Perl unpack */
-	public String unpack(String s){
+	public String encode(String s){
 		byte b[] = s.getBytes() ;
 		StringBuffer sb = new StringBuffer() ;
 		for (int i = 0 ; i < b.length ; 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