Hi all.

I have a new patch that adds support for loading of
TclBlend into a Java, it is a little less complex
than the solution Jiang proposed.


Here is the source file I am using.

% cat LoadTclBlend.java 
import tcl.lang.*;

public class LoadTclBlend {
  public static void main(String[] args) throws Exception {
    Interp i = new Interp();
    i.setVar("i", "1", 0);
    i.eval("puts \"i is $i\"");

    i.eval("package require java");
    i.eval("set str [java::new String \"I am a Java String\"]");
    i.eval("puts [$str toString]");
  }
}

Here are the results with IBM JDK 1.3.

% java LoadTclBlend
i is 1
I am a Java String


Here is the patch I used:


Index: src/native/java.h
===================================================================
RCS file: /home/cvs/external/tcljava/src/native/java.h,v
retrieving revision 1.6
diff -u -r1.6 java.h
--- java.h      2000/06/15 09:47:06     1.6
+++ java.h      2000/06/15 13:37:18
@@ -133,7 +133,9 @@
     jmethodID invokeTimer;
 } JavaInfo;
 
+/* These are defined in javaCmd.c */
 extern JavaInfo java;
+extern JNIEnv *currentEnv;
 
 /*
  * The following macros are used to enter and leave the global
Index: src/native/javaCmd.c
===================================================================
RCS file: /home/cvs/external/tcljava/src/native/javaCmd.c,v
retrieving revision 1.9
diff -u -r1.9 javaCmd.c
--- javaCmd.c   2000/06/15 09:47:06     1.9
+++ javaCmd.c   2000/06/15 13:37:18
@@ -62,7 +62,7 @@
  * will contain the environment for the default thread.
  */
 
-static JNIEnv *currentEnv = NULL; /* JNI pointer for current thread. */
+JNIEnv *currentEnv = NULL; /* JNI pointer for current thread. */
 
 /*
  * The following variable contains the pointer to the current Java VM,
Index: src/native/javaInterp.c
===================================================================
RCS file: /home/cvs/external/tcljava/src/native/javaInterp.c,v
retrieving revision 1.6
diff -u -r1.6 javaInterp.c
--- javaInterp.c        2000/06/15 09:47:07     1.6
+++ javaInterp.c        2000/06/15 13:37:19
@@ -101,8 +101,11 @@
     jlong lvalue;
     Tcl_Interp *interp;
     JNIEnv *oldEnv;
+    int loadedFromJava = (currentEnv == NULL); /* true if Tcl Blend was 
loaded into Java */
 
-    PUSH_JAVA_ENV();
+    if (! loadedFromJava) {
+        PUSH_JAVA_ENV();
+    }
 
     interp = Tcl_CreateInterp();
     if (JavaSetupJava(env, interp) != TCL_OK) {
@@ -116,7 +119,9 @@
        *(Tcl_Interp**)&lvalue = interp;
     }
 
-    POP_JAVA_ENV();
+    if (! loadedFromJava) {
+        POP_JAVA_ENV();
+    }
     return lvalue;
 }


What do you think? We still need to solve some other deadlocking
problems, but at least it loads without a SIGSEGV now :)

Mo Dejong
Red Hat Inc.

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to