Tcl Source Code

View Ticket
Login
Ticket UUID: 670042
Title: Tcl_StaticPackage fails interp registration.
Type: Bug Created on: 2003-01-17 22:58:32
Submitter: dgp Assigned to: kennykb
Subsystem: 40. Dynamic Loading Severity:
Priority: 5 Medium Last modified: 2003-02-02 06:43:36
Status: Closed Closed by: kennykb
Resolution: Fixed Closed on: 2003-02-01 23:43:36
Version: obsolete: 8.4.1
Description:
dgpIs line 481 of tclLoad.c a bug?
kennykbyes, dgp?
dgpRather than a return, shouldn't that be a goto down
to where the package is registered as loaded in a
non-NULL interp?
kennykbOK, let me walk through this slowly.
dgpAs is, Tcl_StaticPackage(one,...);
Tcl_StaticPackage(two,...);
kennykbWe've discovered that there's a package with
the same name and procedures statically loaded in SOME
interp.
dgpwill cause [info loaded {}] in interp one, to
include foo, but [info loaded {}] in interp two will not.
kennykbBut it doesn't have to be the current one.
dgp"statically loaded" is a per-process question.
kennykbHmm, but then the code down below actually has
to check that the package ISN'T already loaded in the
current interp?
dgpfirstPkgPtr is a process-wide resource.
Out of a cloud of smoke, miguel appears!
dgpAs I understand it, it's up to the caller to get
this right.
kennykbexcuse me.  we've discovered that a static
package is provided in the process... but we don't know
that it's in [info loaded] in the current interp.
dgpSo if the caller calls Foo_Init(two) directly, it's
up to that caller to also call
Tcl_StaticPackage(two,...) to keep the [info loaded]
results correct.
kennykbSo, you want to replace the Tcl_MutexUnlock and
return with a break, then condition the next paragraph
upon pkgPtr == null, yes?
kennykbHmm, I was more concerned with two
Tcl_StaticPackage calls for the same package in the
same interp.
kennykbIs that illegal, or should it simply do nothing?
dgpthat's cleaner than the goto, yes.
dgpIt would seem that s per-interp search for already
registered packages would be need then, yes.
kennykb... probably up at the top, so we can do it
without acquiring the lock.
kennykbHmm, then we need two more test cases, one to
make sure that Tcl_StaticPackage gets [imfo loaded]
right in the second interp, and one to make sure that
you can Tcl_StaticPackage the same package twice.


....

dgpWhat got me started was trying to grok the intent
of Tcl_StaticPackage's modes of operation.
kennykbOK, well, you did indeed find a bug.
kennykbAnd you're right that the 'package' there is a
misnomer, I quite forgot the conversation where I
argued you into that position. 
dgpapparently, the interp==NULL mode is just for
saying "hey, there are two routines available, Foo_Init
and Foo_SafeInit, and the [load] command in the future
should associate them with the "Foo" value in its
"package" argument.
dgp...in all interps.
dgpThe (interp!=NULL) mode, though, seems intended to
make a stronger claim.
dgpHey, that association should be made, *and*, btw,
I've called one of those routines on this interp already.
dgpIf that understanding is correct, I'd note that I
derived that from looking at the code, not at the docs
for Tcl_StaticPackage, which could be clearer.
kennykb... and we ought to update the docs to reflect
that understanding.