1unload(n) Tcl Built-In Commands unload(n)
2
3
4
5______________________________________________________________________________
6
8 unload - Unload machine code
9
11 unload ?switches? fileName
12 unload ?switches? fileName packageName
13 unload ?switches? fileName packageName interp
14_________________________________________________________________
15
17 This command tries to unload shared libraries previously loaded with
18 load from the application's address space. fileName is the name of the
19 file containing the library file to be unload; it must be the same as
20 the filename provided to load for loading the library. The packageName
21 argument is the name of the package (as determined by or passed to
22 load), and is used to compute the name of the unload procedure; if not
23 supplied, it is computed from fileName in the same manner as load. The
24 interp argument is the path name of the interpreter from which to
25 unload the package (see the interp manual entry for details); if interp
26 is omitted, it defaults to the interpreter in which the unload command
27 was invoked.
28
29 If the initial arguments to unload start with - then they are treated
30 as switches. The following switches are currently supported:
31
32 -nocomplain
33 Suppresses all error messages. If this switch is given, unload
34 will never report an error.
35
36 -keeplibrary
37 This switch will prevent unload from issuing the operating sys‐
38 tem call that will unload the library from the process.
39
40 -- Marks the end of switches. The argument following this one will
41 be treated as a fileName even if it starts with a -.
42
43 UNLOAD OPERATION
44 When a file containing a shared library is loaded through the load com‐
45 mand, Tcl associates two reference counts to the library file. The
46 first counter shows how many times the library has been loaded into
47 normal (trusted) interpreters while the second describes how many times
48 the library has been loaded into safe interpreters. As a file contain‐
49 ing a shared library can be loaded only once by Tcl (with the first
50 load call on the file), these counters track how many interpreters use
51 the library. Each subsequent call to load after the first simply
52 increments the proper reference count.
53
54 unload works in the opposite direction. As a first step, unload will
55 check whether the library is unloadable: an unloadable library exports
56 a special unload procedure. The name of the unload procedure is deter‐
57 mined by packageName and whether or not the target interpreter is a
58 safe one. For normal interpreters the name of the initialization pro‐
59 cedure will have the form pkg_Unload, where pkg is the same as package‐
60 Name except that the first letter is converted to upper case and all
61 other letters are converted to lower case. For example, if packageName
62 is foo or FOo, the initialization procedure's name will be Foo_Unload.
63 If the target interpreter is a safe interpreter, then the name of the
64 initialization procedure will be pkg_SafeUnload instead of pkg_Unload.
65
66 If unload determines that a library is not unloadable (or unload func‐
67 tionality has been disabled during compilation), an error will be
68 returned. If the library is unloadable, then unload will call the
69 unload procedure. If the unload procedure returns TCL_OK, unload will
70 proceed and decrease the proper reference count (depending on the tar‐
71 get interpreter type). When both reference counts have reached 0, the
72 library will be detached from the process.
73
74 UNLOAD HOOK PROTOTYPE
75 The unload procedure must match the following prototype:
76 typedef int Tcl_PackageUnloadProc(Tcl_Interp *interp, int flags);
77
78 The interp argument identifies the interpreter from which the library
79 is to be unloaded. The unload procedure must return TCL_OK or
80 TCL_ERROR to indicate whether or not it completed successfully; in the
81 event of an error it should set the interpreter's result to point to an
82 error message. In this case, the result of the unload command will be
83 the result returned by the unload procedure.
84
85 The flags argument can be either TCL_UNLOAD_DETACH_FROM_INTERPRETER or
86 TCL_UNLOAD_DETACH_FROM_PROCESS. In case the library will remain
87 attached to the process after the unload procedure returns (i.e.
88 because the library is used by other interpreters),
89 TCL_UNLOAD_DETACH_FROM_INTERPRETER will be defined. However, if the
90 library is used only by the target interpreter and the library will be
91 detached from the application as soon as the unload procedure returns,
92 the flags argument will be set to TCL_UNLOAD_DETACH_FROM_PROCESS.
93
94 NOTES
95 The unload command cannot unload libraries that are statically linked
96 with the application. If fileName is an empty string, then the packa‐
97 geName argument must be specified.
98
99 If packageName is omitted or specified as an empty string, Tcl tries to
100 guess the name of the package. This may be done differently on differ‐
101 ent platforms. The default guess, which is used on most UNIX plat‐
102 forms, is to take the last element of fileName, strip off the first
103 three characters if they are lib, and use any following alphabetic and
104 underline characters as the module name. For example, the command
105 unload libxyz4.2.so uses the module name xyz and the command unload
106 bin/last.so {} uses the module name last.
107
109 Unix
110 Not all unix operating systems support library unloading. Under
111 such an operating system unload returns an error (unless -nocom‐
112 plain has been specified).
113
115 If the same file is loaded by different fileNames, it will be loaded
116 into the process's address space multiple times. The behavior of this
117 varies from system to system (some systems may detect the redundant
118 loads, others may not). In case a library has been silently detached by
119 the operating system (and as a result Tcl thinks the library is still
120 loaded), it may be dangerous to use unload on such a library (as the
121 library will be completely detached from the application while some
122 interpreters will continue to use it).
123
125 If an unloadable module in the file foobar.dll had been loaded using
126 the load command like this (on Windows):
127 load c:/some/dir/foobar.dll
128 then it would be unloaded like this:
129 unload c:/some/dir/foobar.dll
130
131 This allows a C code module to be installed temporarily into a long-
132 running Tcl program and then removed again (either because it is no
133 longer needed or because it is being updated with a new version) with‐
134 out having to shut down the overall Tcl process.
135
137 info sharedlibextension, load(n), safe(n)
138
140 binary code, unloading, safe interpreter, shared library
141
142
143
144Tcl 8.5 unload(n)