On 2005.02.06, Dan Chak <[EMAIL PROTECTED]> wrote:
>
> I've noticed some strange behavior in AOLServer when renaming the proc
> command.  I put the following example stub definition in the tcl
> library before the rest of the library loads:

What version of AOLserver?  Did you put it in the shared Tcl library, or
the private Tcl library?

> My tcl library loads fine, but when I try to load a page, I get the
> following errors in my log (and a page error):
>
> [06/Feb/2005:14:39:01][2824.25187840][-conn:web2-users::0] Error:
> invalid command name "proc"
> invalid command name "proc"
>     while executing
> "proc ::load {args} {
>             set libfile [lindex $args 0]
>             for {set i 0} {$i < [llength $::_pkglist]} {incr i} {
>                 set to..."
> [06/Feb/2005:14:39:01][2824.25187840][-conn:web2-users::0] Error:
> invalid command name "ns_sourceproc"
> invalid command name "ns_sourceproc"
>     while executing
> "ns_sourceproc {}"

Looks like you've got enabletclpages = true, and this is a request for a
.tcl page.

> It seems like the 'rename' and the definition of the new proc command
> happen in different contexts, the latter of which is not seen by the
> main interpreter process.  Any ideas on how to get this working?

Well, since Tcl doesn't have a "clone this interp" capability, we kind
of "fake it" in AOLserver.  We create a "master interp" which sources
all the Tcl at start-up, then dump its contents as best we can (which
generally means capturing the proc definitions for all procs listed in
[info procs]), building up a Tcl script used to initialize new interps.
[ns_ictl get] will dump you a copy of the script that the server is
using.

Of course, there's no way to ask a Tcl interp "tell me about all the
[rename]'s that have happened in this interp since it was created" so
that we could include them in the master init script.  (Thought: we
could rename the [rename] proc, replacing it with a wedge that logs what
procs are being renamed then actually performing the rename, but we'd
need to do it in the right sequence in the master init script or else we
stand a chance of breaking things.)

If you want to do things other than define procs in your Tcl libraries
at start-up which you want to have happen in all subsequent interps, you
want to look at [ns_ictl oninit] or [ns_ictl oncreate], whichever is
appropriate.  In this particular case, you probably want [ns_ictl
oncreate], like so:

    ns_ictl oncreate {
        rename proc _proc
        _proc proc {name args body} {
            ns_log notice "proc: $name $args"
            _proc $name $args $body
        }
    }

Why is it important to rename AND redefine [proc] in the same oncreate
script block?  Because you want this to happen right after the interp is
created, before the "master init script" is sourced.  If you define the
[proc] proc in your regular Tcl script, it'll get defined in the master
interp. (which may be what you want -- more on this later), and captured
and put into the master init script.  Why is this bad?  Because your new
definition of [proc] will likely come somewhere in that master init
script, but the [rename proc _proc] will happen at the very beginning.
So, if anything tries to define a proc in the master init script before
your new [proc] definition happens, well ... it'll throw a Tcl error
while it's sourcing.

So, what IF you want to rename the [proc] proc to affect how the rest of
the startup Tcl is sourced, AND any future interps as well?  You may
want to try something like this:

    set script {
        rename proc _proc
        _proc proc {name args body} {
            ns_log notice "proc: $name $args"
            _proc $name $args $body
        }
    }
    ns_ictl oncreate $script
    eval $script

Of course, for maximum effect, you want to make sure that this snippet
is the first thing to get executed in the master interp.  You may want
to even put this in the config.tcl rather than in the Tcl library to
ensure it gets sourced before anything in either of the Tcl libraries,
but I haven't tested this.

HTH,

-- Dossy

--
Dossy Shiobara                       mail: [EMAIL PROTECTED]
Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> 
with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: 
field of your email blank.

Reply via email to