1unload(n)                    Tcl Built-In Commands                   unload(n)


8       unload - Unload machine code


11       unload ?switches? fileName
12       unload ?switches? fileName packageName
13       unload ?switches? fileName packageName interp


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.
29       If  the  initial arguments to unload start with - then they are treated
30       as switches.  The following switches are currently supported:
32       -nocomplain
33              Suppresses all error messages. If this switch is  given,  unload
34              will never report an error.
36       -keeplibrary
37              This  switch will prevent unload from issuing the operating sys‐
38              tem call that will unload the library from the process.
40       --     Marks the end of switches.  The argument following this one will
41              be treated as a fileName even if it starts with a -.
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.
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.
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.
75       The unload procedure must match the following prototype:
77              typedef int Tcl_PackageUnloadProc(
78                      Tcl_Interp *interp,
79                      int flags);
81       The  interp  argument identifies the interpreter from which the library
82       is to  be  unloaded.   The  unload  procedure  must  return  TCL_OK  or
83       TCL_ERROR to indicate whether or not it completed successfully;  in the
84       event of an error it should set the interpreter's result to point to an
85       error  message.  In this case, the result of the unload command will be
86       the result returned by the unload procedure.
88       The flags argument can be either TCL_UNLOAD_DETACH_FROM_INTERPRETER  or
89       TCL_UNLOAD_DETACH_FROM_PROCESS.   In   case  the  library  will  remain
90       attached to the  process  after  the  unload  procedure  returns  (i.e.
91       because    the    library    is    used    by    other   interpreters),
92       TCL_UNLOAD_DETACH_FROM_INTERPRETER will be  defined.  However,  if  the
93       library  is used only by the target interpreter and the library will be
94       detached from the application as soon as the unload procedure  returns,
95       the flags argument will be set to TCL_UNLOAD_DETACH_FROM_PROCESS.
97   NOTES
98       The  unload  command cannot unload libraries that are statically linked
99       with the application.  If fileName is an empty string, then the  packa‐
100       geName argument must be specified.
102       If packageName is omitted or specified as an empty string, Tcl tries to
103       guess the name of the package.  This may be done differently on differ‐
104       ent  platforms.   The  default  guess, which is used on most UNIX plat‐
105       forms, is to take the last element of fileName,  strip  off  the  first
106       three  characters if they are lib, and use any following alphabetic and
107       underline characters as the module  name.   For  example,  the  command
108       unload  libxyz4.2.so  uses  the  module name xyz and the command unload
109       bin/last.so {} uses the module name last.


112       Unix
113              Not all unix operating systems support library unloading.  Under
114              such an operating system unload returns an error (unless -nocom‐
115              plain has been specified).


118       If the same file is loaded by different fileNames, it  will  be  loaded
119       into  the process's address space multiple times.  The behavior of this
120       varies from system to system (some systems  may  detect  the  redundant
121       loads, others may not). In case a library has been silently detached by
122       the operating system (and as a result Tcl thinks the library  is  still
123       loaded),  it  may  be dangerous to use unload on such a library (as the
124       library will be completely detached from  the  application  while  some
125       interpreters will continue to use it).


128       If  an  unloadable  module in the file foobar.dll had been loaded using
129       the load command like this (on Windows):
131              load c:/some/dir/foobar.dll
133       then it would be unloaded like this:
135              unload c:/some/dir/foobar.dll
137       This allows a C code module to be installed temporarily  into  a  long-
138       running  Tcl  program  and  then removed again (either because it is no
139       longer needed or because it is being updated with a new version)  with‐
140       out having to shut down the overall Tcl process.


143       info sharedlibextension, load(n), safe(n)


146       binary code, unloading, safe interpreter, shared library
150Tcl                                   8.5                            unload(n)