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