| Ticket UUID: | 1176470 | ||
| Title: | Invoke *_*Init() for each [load] | ||
| Type: | RFE | Created on: | 2005-04-04 16:31:24 |
| Submitter: | eriklns | Assigned to: | kennykb |
| Subsystem: | 40. Dynamic Loading | Severity: | |
| Priority: | 5 Medium | Last modified: | 2005-11-17 01:45:25 |
| Status: | Open | Closed by: | eriklns |
| Resolution: | Remind | Closed on: | 2005-04-06 16:52:42 |
| Version: | None | ||
| Description: | ||||
L.S.
Two unexpected results occur when importing packages
which load compiled code:
1. When doing [package forget], the entry of the
corresponding shared library is not removed from what's
returned by [info loaded].
2. After having done [package forget], and issuing
again [package require], an error message is returned:
"can't find package ..."
An example session that exercises the above sequence
for Tkhtml and Tktable is appended to this message.
A discussion in c.l.t. (started at 4-Apr-2005,
featuring Michael Schlenker, Don Porter and yours
truly) arrived at the point where dgp judges there is
either a bug here or a misfeature.
Erik Leunissen
==============
Example Tcl session:
---------------
% info loaded
{{} Tk}
% package require Tkhtml
2.0
% info loaded
{/usr/lib/tk8.4/../libtk8.4.so Tk}
{/usr/local/lib/Tkhtml2.0/libTkhtml2.0.so Tkhtml} {{} Tk}
% package forget Tkhtml
% info loaded
{/usr/lib/tk8.4/../libtk8.4.so Tk}
{/usr/local/lib/Tkhtml2.0/libTkhtml2.0.so Tkhtml} {{} Tk}
% package require Tkhtml
can't find package Tkhtml
% package require Tktable
2.8
% info loaded
{/usr/local/lib/Tktable2.8/libTktable2.8.so Tktable}
{/usr/lib/tk8.4/../libtk8.4.so Tk}
{/usr/local/lib/Tkhtml2.0/libTkhtml2.0.so Tkhtml} {{} Tk}
% info loaded
{/usr/local/lib/Tktable2.8/libTktable2.8.so Tktable}
{/usr/lib/tk8.4/../libtk8.4.so Tk}
{/usr/local/lib/Tkhtml2.0/libTkhtml2.0.so Tkhtml} {{} Tk}
% package forget Tktable
% info loaded
{/usr/local/lib/Tktable2.8/libTktable2.8.so Tktable}
{/usr/lib/tk8.4/../libtk8.4.so Tk}
{/usr/local/lib/Tkhtml2.0/libTkhtml2.0.so Tkhtml} {{} Tk}
% package require Tktable
can't find package Tktable
-- end of message --
--
leunissen@ nl | Merge the left part of these
two lines into one,
e. hccnet. | respecting a character's
position in a line.
| ||||
| User Comments: | ||||
dgp added on 2005-04-04 23:48:21:
Logged In: YES user_id=80530 I'd have expected each [load] command to call the *_Init() routine again. That said, [package forget] is a rather specialized operation; not really meant for much use in programs. Avoid if possible. hobbs added on 2005-04-05 00:30:58:
Logged In: YES
user_id=72656
This is clearly a misunderstanding on the part of the user.
Maybe the docs need clarification, but it's not a bug.
package forget forgets the 'ifneeded' part, which is of
course why the next package require will fail. It does
nothing else - it does not unload any packages. The 'info
loaded' is still 100% correct, as those dlls are still
loaded. You could still say 'load {} Tkhtml|Tktable' and
they will load.
dgp added on 2005-04-05 00:40:04:
Logged In: YES
user_id=80530
"package forget forgets the 'ifneeded' part, which is of
course why the next package require will fail."
Not so. [package forget] will forget all the
ifneeded scripts for all versions of Tkhtml, so
the next [package require Tkhtml] will invoke
[package unknown] to find those scripts again.
Nothing in the report suggests that second
search fails. The ifneeded script(s) get restored
back to the package database, but the report
is that they do not work the second time because
[load] doesn't work on the second pass.
"You could still say 'load {} Tkhtml|Tktable' and
they will load."
As I understand the report, this is not working.
dgp added on 2005-04-05 01:02:12:
Logged In: YES user_id=80530 Thinking more about this, having [load] call the same Foo_Init() routine a second time also has problems. It's quite likely many existing packages haven't had their Foo_Init() routines written to handle that case. Seems the only reasonable advice that can be given is: DO NOT USE [package forget]. hobbs added on 2005-04-05 02:17:46:
Logged In: YES
user_id=72656
As to the 'load {} Tkhtml|Tktable', it certainly does still
work, as would be expected when the library is still loaded.
Tested with Tktable just fine. I would agree that 'package
forget' mostly sucks in terms of being confusing/useless.
eriklns added on 2005-04-06 23:52:09:
Logged In: YES
user_id=113903
The manual page for [load] says:
"If a given fileName is loaded into multiple
interpreters, then the first load will load the code and
call the initialization procedure; subsequent loads will
call the initialization procedure without loading the code
again.
It is not possible to unload or reload a package."
I've tested this with a small package "loadtest", by letting
Loadtest_Init emit a message to stdout.
When exercising the following at the Tcl prompt you will
find that the message is emitted with the first [load]
command. I didn't see that message when issuing the command
the second time and the namespace ::loadtest, created at the
first load, then deleted with ::loadtest::terminate, was not
recreated with the second [load].
% load ./loadtest/loadtest.so
% namespace exists ::loadtest
1
% loadtest::terminate
% namespace exists ::loadtest
0
% info loaded
{./loadtest/loadtest.so Loadtest} {{} Tk}
% load {} Loadtest
% namespace exists ::loadtest
0
%
Therefore, I believe that the _Init proc is not called a
second time as the man page desscribes.
The C code with build script has been uploaded.
eriklns added on 2005-04-06 23:59:40:
Logged In: YES user_id=113903 I withdraw the last post. The case that I tested was when loading into the same main interp and that is not what the man page describes. _Init will only be called a second time when loading into a different interp. Sorry. dgp added on 2005-11-17 01:39:24:
Logged In: YES user_id=80530 Converting this into a Feature Request for Tcl 8.5 dgp added on 2005-11-17 01:45:23:
data_type - 360894 dgp added on 2005-11-17 01:45:25:
Logged In: YES user_id=80530 Converting this into a Feature Request for Tcl 8.5 Thing to watch out for is whether there are existing Foo_Init() routines that are not robust enough to accept multiple calls with the same interp argument. Note that the ability for a second [load] to call Foo_Init() to correct possible errors from the first Foo_Init() is more important since Bug 1162286 was fixed. | ||||
