| 1 |
'\" |
| 2 |
'\" Copyright (c) 2003 George Petasis <[email protected]>. |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH unload n 8.5 Tcl "Tcl Built-In Commands" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 11 |
.SH NAME |
| 12 |
unload \- Unload machine code |
| 13 |
.SH SYNOPSIS |
| 14 |
\fBunload \fR?\fIswitches\fR? \fIfileName\fR |
| 15 |
.br |
| 16 |
\fBunload \fR?\fIswitches\fR? \fIfileName prefix\fR |
| 17 |
.br |
| 18 |
\fBunload \fR?\fIswitches\fR? \fIfileName prefix interp\fR |
| 19 |
.BE |
| 20 |
.SH DESCRIPTION |
| 21 |
.PP |
| 22 |
This command tries to unload shared libraries previously loaded |
| 23 |
with \fBload\fR from the application's address space. \fIfileName\fR |
| 24 |
is the name of the file containing the library file to be unload; it |
| 25 |
must be the same as the filename provided to \fBload\fR for |
| 26 |
loading the library. |
| 27 |
The \fIprefix\fR argument is the prefix (as |
| 28 |
determined by or passed to \fBload\fR), and is used to |
| 29 |
compute the name of the unload procedure; if not supplied, it is |
| 30 |
computed from \fIfileName\fR in the same manner as \fBload\fR. |
| 31 |
The \fIinterp\fR argument is the path name of the interpreter from |
| 32 |
which to unload the package (see the \fBinterp\fR manual entry for |
| 33 |
details); if \fIinterp\fR is omitted, it defaults to the |
| 34 |
interpreter in which the \fBunload\fR command was invoked. |
| 35 |
.PP |
| 36 |
If the initial arguments to \fBunload\fR start with \fB\-\fR then |
| 37 |
they are treated as switches. The following switches are |
| 38 |
currently supported: |
| 39 |
.TP |
| 40 |
\fB\-nocomplain\fR |
| 41 |
. |
| 42 |
Suppresses all error messages. If this switch is given, \fBunload\fR will |
| 43 |
never report an error. |
| 44 |
.TP |
| 45 |
\fB\-keeplibrary\fR |
| 46 |
. |
| 47 |
This switch will prevent \fBunload\fR from issuing the operating system call |
| 48 |
that will unload the library from the process. |
| 49 |
.TP |
| 50 |
\fB\-\|\-\fR |
| 51 |
. |
| 52 |
Marks the end of switches. The argument following this one will |
| 53 |
be treated as a \fIfileName\fR even if it starts with a \fB\-\fR. |
| 54 |
.SS "UNLOAD OPERATION" |
| 55 |
.PP |
| 56 |
When a file containing a shared library is loaded through the |
| 57 |
\fBload\fR command, Tcl associates two reference counts to the library |
| 58 |
file. The first counter shows how many times the library has been |
| 59 |
loaded into normal (trusted) interpreters while the second describes how many |
| 60 |
times the library has been loaded into safe interpreters. As a file containing |
| 61 |
a shared library can be loaded only once by Tcl (with the first \fBload\fR |
| 62 |
call on the file), these counters track how many interpreters use the library. |
| 63 |
Each subsequent call to \fBload\fR after the first simply increments the |
| 64 |
proper reference count. |
| 65 |
.PP |
| 66 |
\fBunload\fR works in the opposite direction. As a first step, \fBunload\fR |
| 67 |
will check whether the library is unloadable: an unloadable library exports |
| 68 |
a special unload procedure. The name of the unload procedure is determined by |
| 69 |
\fIprefix\fR and whether or not the target interpreter |
| 70 |
is a safe one. For normal interpreters the name of the initialization |
| 71 |
procedure will have the form \fIpfx\fB_Unload\fR, where \fIpfx\fR |
| 72 |
is the same as \fIprefix\fR except that the first letter is |
| 73 |
converted to upper case and all other letters |
| 74 |
are converted to lower case. For example, if \fIprefix\fR is |
| 75 |
\fBfoo\fR or \fBFOo\fR, the initialization procedure's name will |
| 76 |
be \fBFoo_Unload\fR. |
| 77 |
If the target interpreter is a safe interpreter, then the name |
| 78 |
of the initialization procedure will be \fIpkg\fB_SafeUnload\fR |
| 79 |
instead of \fIpkg\fB_Unload\fR. |
| 80 |
.PP |
| 81 |
If \fBunload\fR determines that a library is not unloadable (or unload |
| 82 |
functionality has been disabled during compilation), an error will be returned. |
| 83 |
If the library is unloadable, then \fBunload\fR will call the unload |
| 84 |
procedure. If the unload procedure returns \fBTCL_OK\fR, \fBunload\fR will proceed |
| 85 |
and decrease the proper reference count (depending on the target interpreter |
| 86 |
type). When both reference counts have reached 0, the library will be |
| 87 |
detached from the process. |
| 88 |
.SS "UNLOAD HOOK PROTOTYPE" |
| 89 |
.PP |
| 90 |
The unload procedure must match the following prototype: |
| 91 |
.PP |
| 92 |
.CS |
| 93 |
typedef int \fBTcl_PackageUnloadProc\fR( |
| 94 |
Tcl_Interp *\fIinterp\fR, |
| 95 |
int \fIflags\fR); |
| 96 |
.CE |
| 97 |
.PP |
| 98 |
The \fIinterp\fR argument identifies the interpreter from which the |
| 99 |
library is to be unloaded. The unload procedure must return |
| 100 |
\fBTCL_OK\fR or \fBTCL_ERROR\fR to indicate whether or not it completed |
| 101 |
successfully; in the event of an error it should set the interpreter's result |
| 102 |
to point to an error message. In this case, the result of the |
| 103 |
\fBunload\fR command will be the result returned by the unload procedure. |
| 104 |
.PP |
| 105 |
The \fIflags\fR argument can be either \fBTCL_UNLOAD_DETACH_FROM_INTERPRETER\fR |
| 106 |
or \fBTCL_UNLOAD_DETACH_FROM_PROCESS\fR. In case the library will remain |
| 107 |
attached to the process after the unload procedure returns (i.e. because |
| 108 |
the library is used by other interpreters), |
| 109 |
\fBTCL_UNLOAD_DETACH_FROM_INTERPRETER\fR will be defined. However, if the |
| 110 |
library is used only by the target interpreter and the library will be |
| 111 |
detached from the application as soon as the unload procedure returns, |
| 112 |
the \fIflags\fR argument will be set to \fBTCL_UNLOAD_DETACH_FROM_PROCESS\fR. |
| 113 |
.SS NOTES |
| 114 |
.PP |
| 115 |
The \fBunload\fR command cannot unload libraries that are statically |
| 116 |
linked with the application. |
| 117 |
If \fIfileName\fR is an empty string, then the \fIprefix\fR argument must |
| 118 |
be specified. |
| 119 |
.PP |
| 120 |
If \fIprefix\fR is omitted or specified as an empty string, |
| 121 |
Tcl tries to guess the prefix. This may be done differently on |
| 122 |
different platforms. The default guess, which is used on most |
| 123 |
UNIX platforms, is to take the last element of |
| 124 |
\fIfileName\fR, strip off the first three characters if they |
| 125 |
are \fBlib\fR, and use any following alphabetic and |
| 126 |
underline characters, converted to titlecase as the prefix. |
| 127 |
For example, the command \fBunload libxyz4.2.so\fR uses the prefix |
| 128 |
\fBXyz\fR and the command \fBunload bin/last.so {}\fR uses the |
| 129 |
prefix \fBLast\fR. |
| 130 |
.SH "PORTABILITY ISSUES" |
| 131 |
.TP |
| 132 |
\fBUnix\fR\0\0\0\0\0 |
| 133 |
. |
| 134 |
Not all unix operating systems support library unloading. Under such |
| 135 |
an operating system \fBunload\fR returns an error (unless \fB\-nocomplain\fR |
| 136 |
has been specified). |
| 137 |
.SH BUGS |
| 138 |
.PP |
| 139 |
If the same file is \fBload\fRed by different \fIfileName\fRs, it will |
| 140 |
be loaded into the process's address space multiple times. The |
| 141 |
behavior of this varies from system to system (some systems may |
| 142 |
detect the redundant loads, others may not). In case a library has been |
| 143 |
silently detached by the operating system (and as a result Tcl thinks the |
| 144 |
library is still loaded), it may be dangerous to use |
| 145 |
\fBunload\fR on such a library (as the library will be completely detached |
| 146 |
from the application while some interpreters will continue to use it). |
| 147 |
.SH EXAMPLE |
| 148 |
.PP |
| 149 |
If an unloadable module in the file \fBfoobar.dll\fR had been loaded |
| 150 |
using the \fBload\fR command like this (on Windows): |
| 151 |
.PP |
| 152 |
.CS |
| 153 |
load c:/some/dir/foobar.dll |
| 154 |
.CE |
| 155 |
.PP |
| 156 |
then it would be unloaded like this: |
| 157 |
.PP |
| 158 |
.CS |
| 159 |
\fBunload\fR c:/some/dir/foobar.dll |
| 160 |
.CE |
| 161 |
.PP |
| 162 |
This allows a C code module to be installed temporarily into a |
| 163 |
long-running Tcl program and then removed again (either because it is |
| 164 |
no longer needed or because it is being updated with a new version) |
| 165 |
without having to shut down the overall Tcl process. |
| 166 |
.SH "SEE ALSO" |
| 167 |
info sharedlibextension, load(n), safe(n) |
| 168 |
.SH KEYWORDS |
| 169 |
binary code, unloading, safe interpreter, shared library |
| 170 |
.\" Local Variables: |
| 171 |
.\" mode: nroff |
| 172 |
.\" End: |