Here's the documentation on the aolserver.com website, which describes how it
works in AOLserver 3:

"ns_eval evaluates the Tcl passed in to this function. The Tcl is evaluated in
all the Tcl interpreters for this virtual server. You can use this command to
maintain global variables. For example, if you execute:

ns_eval set g 1

in one interpreter, later operations will see $g equal to 1 no matter what
interpreter they are assigned to. "

The implementation in AOLserver 4 is very, very different.  The script is
executed then the ENTIRE set of namespaces and procs are saved to the
server's "tcl.script" pointer.

This means that when interpreters are updated (as happens when an
interpreter's created for a new thread, for instance) ALL of the global
variables in the new thread have the values in the old thread.  ns_eval {
...script ... } , then, is really a "synch all interpreters" command that
first evaluates the given script.

One EVIL side effect of this is that some of the standard ns_* Tcl API is
implemented in Tcl, in some cases using global variables.  So, for instance,
I have a test case in which the following code:

set form_size [ns_set size [ns_getform]]

fails because another script has done an ns_eval and _ns_form was set in that
thread to "t3".   In the failing thread [ns_getform] has never been called,
yet it's seeing _ns_form with the value t3 - an ns_set which does not exist
in its context, of course.

This is ... non-intuitive.  Especially if one RTFMs and expects the behavior
to be at least someone like the behavior that's described ...

Now the one use of ns_eval in OpenACS that causes the above problem can be
fixed by simply switching to nsvs (probably a good idea anyway) but the
documentation for ns_eval should be changed, perhaps?  I have a hard time
seeing the new functionality being all that useful ...

If I sound annoyed it's because I just spent about four hours tracking down
why one certain operation in OpenACS was causing ns_getform to fail after an
ns_returnredirect.   On the bright side I've been through all of the
AOLserver thread code and the connection thread code so know all about how
thread init and create callbacks are registered and more stuff than I even
want to think about at the moment ...

And there are only two ns_evals in the entire OpenACS toolkit and they'll be
easy to get rid of.


--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list: http://www.aolserver.com/listserv.html
List information and options: http://listserv.aol.com/

Reply via email to