The existing TclBlend (1.2.6) code doesn't quite work.  If one tries to do a
"new tcl.lang.Interp()" in the JVM before Tclblend_Init() is called, an
access violation happens in Java_tcl_lang_Interp_create():

jlong JNICALL
Java_tcl_lang_Interp_create(
    JNIEnv *env,                /* Java environment. */
    jobject interpObj)          /* Handle to Interp object. */
{
    jlong lvalue;
    Tcl_Interp *interp;
    JNIEnv *oldEnv;

    JAVA_LOCK();      /* !!!!!!! this line triggers an access violation
!!!!!! */
    /* ... stuff to create the native TCL interpreter ... */
    JAVA_UNLOCK();
    return lvalue;
}

JAVA_LOCK macro tries to access the global java.NativeLock, which is not set
up if Tclblend_Init is not called.  I will open a bug and supply a patch to
fix this initialization problem.

As to using multiple native TCL interpreters in multiple Java threads, it
probably requires a bit more work in the TclBlend code.  The main issue
seems to be with the use of a single global Notifier object.  Even if one
creates more than one Interp object, all Interp objects are using the same
global Notifier object.  That doesn't seem right.  If I have more time, I
may look into fixing this issue.  Using multiple interpreters in my server
may be beneficial.

-- Jiang Wu
   [EMAIL PROTECTED]

-----Original Message-----
From: Mo DeJong [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 02, 2000 3:41 PM
To: [EMAIL PROTECTED]
Subject: [Tcl Java] Re: [Tcl Java] Using native TCL in JVM


Here is a note from the original author of Tcl Blend on this subject.

Mo Dejong
Red Hat Inc.


Jiang Wu said:

 > Then there is TclBlend, which does a nice job of linking a native TCL
 > interpreter with JVM.  But TclBlend assumes that the TCL interpreter 
starts
 > first, then it creates a JVM to run the Java code.  That is the reverse 
of
 > my setup, in which the JVM starts first, then loads the TCL
interpreter.

TclBlend can also be used from inside a preexisting JVM.  TclBlend should 
only create a new JVM if it can't find one already running.  You can use 
the tcl.lang.Interp class to create a new Tcl interpreter and then 
evaluate scripts in it.  Your sample code seemed correct without any 
modifications to blend.  The initialization code in Tclblend_Init is only 
needed if you are loading the package from C initially.  It mostly just 
creates a new Interp object to wrap the already existing C interpreter.  
If you are creating the initial interpreter from Java, then it doesn't 
need to do this.

----------------------------------------------------------------
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