1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Digest.html">
<link rel="next" href="Ephemeron.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of extensions" rel=Appendix href="index_extensions.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Bool" rel="Chapter" href="Bool.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Bytes" rel="Chapter" href="Bytes.html">
<link title="BytesLabels" rel="Chapter" href="BytesLabels.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html">
<link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html">
<link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Ephemeron" rel="Chapter" href="Ephemeron.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Float" rel="Chapter" href="Float.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Fun" rel="Chapter" href="Fun.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int" rel="Chapter" href="Int.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Ocaml_operators" rel="Chapter" href="Ocaml_operators.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Option" rel="Chapter" href="Option.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Result" rel="Chapter" href="Result.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Seq" rel="Chapter" href="Seq.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Spacetime" rel="Chapter" href="Spacetime.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Stdlib" rel="Chapter" href="Stdlib.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Uchar" rel="Chapter" href="Uchar.html">
<link title="Unit" rel="Chapter" href="Unit.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Dynamic loading of compiled files" rel="Section" href="#1_Dynamicloadingofcompiledfiles">
<link title="Access control" rel="Section" href="#1_Accesscontrol">
<link title="Error reporting" rel="Section" href="#1_Errorreporting">
<title>Dynlink</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Digest.html" title="Digest">Previous</a>
<a class="up" href="index.html" title="Index">Up</a>
<a class="post" href="Ephemeron.html" title="Ephemeron">Next</a>
</div>
<h1>Module <a href="type_Dynlink.html">Dynlink</a></h1>
<pre><span id="MODULEDynlink"><span class="keyword">module</span> Dynlink</span>: <code class="code"><span class="keyword">sig</span></code> <a href="Dynlink.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<div class="info-desc">
<p>Dynamic loading of .cmo, .cma and .cmxs files.</p>
</div>
</div>
<hr width="100%">
<pre><span id="VALis_native"><span class="keyword">val</span> is_native</span> : <code class="type">bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="keyword">true</span></code> if the program is native,
<code class="code"><span class="keyword">false</span></code> if the program is bytecode.</p>
</div>
</div>
<h2 id="1_Dynamicloadingofcompiledfiles">Dynamic loading of compiled files</h2>
<pre><span id="VALloadfile"><span class="keyword">val</span> loadfile</span> : <code class="type">string -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>In bytecode: load the given bytecode object file (<code class="code">.cmo</code> file) or
bytecode library file (<code class="code">.cma</code> file), and link it with the running
program. In native code: load the given OCaml plugin file (usually
<code class="code">.cmxs</code>), and link it with the running program.</p>
<p>All toplevel expressions in the loaded compilation units
are evaluated. No facilities are provided to
access value names defined by the unit. Therefore, the unit
must itself register its entry points with the main program (or a
previously-loaded library) e.g. by modifying tables of functions.</p>
<p>An exception will be raised if the given library defines toplevel
modules whose names clash with modules existing either in the main
program or a shared library previously loaded with <code class="code">loadfile</code>.
Modules from shared libraries previously loaded with
<code class="code">loadfile_private</code> are not included in this restriction.</p>
<p>The compilation units loaded by this function are added to the
"allowed units" list (see <a href="Dynlink.html#VALset_allowed_units"><code class="code"><span class="constructor">Dynlink</span>.set_allowed_units</code></a>).</p>
</div>
</div>
<pre><span id="VALloadfile_private"><span class="keyword">val</span> loadfile_private</span> : <code class="type">string -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">loadfile</code>, except that the compilation units just loaded
are hidden (cannot be referenced) from other modules dynamically
loaded afterwards.</p>
<p>An exception will be raised if the given library defines toplevel
modules whose names clash with modules existing in either the main
program or a shared library previously loaded with <code class="code">loadfile</code>.
Modules from shared libraries previously loaded with
<code class="code">loadfile_private</code> are not included in this restriction.</p>
<p>An exception will also be raised if the given library defines
toplevel modules whose name matches that of an interface depended
on by a module existing in either the main program or a shared
library previously loaded with <code class="code">loadfile</code>. This applies even if
such dependency is only a "module alias" dependency (i.e. just on
the name rather than the contents of the interface).</p>
<p>The compilation units loaded by this function are not added to the
"allowed units" list (see <a href="Dynlink.html#VALset_allowed_units"><code class="code"><span class="constructor">Dynlink</span>.set_allowed_units</code></a>) since they cannot
be referenced from other compilation units.</p>
</div>
</div>
<pre><span id="VALadapt_filename"><span class="keyword">val</span> adapt_filename</span> : <code class="type">string -> string</code></pre><div class="info ">
<div class="info-desc">
<p>In bytecode, the identity function. In native code, replace the last
extension with <code class="code">.cmxs</code>.</p>
</div>
</div>
<h2 id="1_Accesscontrol">Access control</h2>
<pre><span id="VALset_allowed_units"><span class="keyword">val</span> set_allowed_units</span> : <code class="type">string list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Set the list of compilation units that may be referenced from units that
are dynamically loaded in the future to be exactly the given value.</p>
<p>Initially all compilation units composing the program currently running
are available for reference from dynamically-linked units.
<code class="code">set_allowed_units</code> can be used to restrict access to a subset of these
units, e.g. to the units that compose the API for
dynamically-linked code, and prevent access to all other units,
e.g. private, internal modules of the running program.</p>
<p>Note that <a href="Dynlink.html#VALloadfile"><code class="code"><span class="constructor">Dynlink</span>.loadfile</code></a> changes the allowed-units list.</p>
</div>
</div>
<pre><span id="VALallow_only"><span class="keyword">val</span> allow_only</span> : <code class="type">string list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">allow_only units</code> sets the list of allowed units to be the intersection
of the existing allowed units and the given list of units. As such it
can never increase the set of allowed units.</p>
</div>
</div>
<pre><span id="VALprohibit"><span class="keyword">val</span> prohibit</span> : <code class="type">string list -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">prohibit units</code> prohibits dynamically-linked units from referencing
the units named in list <code class="code">units</code> by removing such units from the allowed
units list. This can be used to prevent access to selected units,
e.g. private, internal modules of the running program.</p>
</div>
</div>
<pre><span id="VALmain_program_units"><span class="keyword">val</span> main_program_units</span> : <code class="type">unit -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Return the list of compilation units that form the main program (i.e.
are not dynamically linked).</p>
</div>
</div>
<pre><span id="VALpublic_dynamically_loaded_units"><span class="keyword">val</span> public_dynamically_loaded_units</span> : <code class="type">unit -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Return the list of compilation units that have been dynamically loaded via
<code class="code">loadfile</code> (and not via <code class="code">loadfile_private</code>). Note that compilation units
loaded dynamically cannot be unloaded.</p>
</div>
</div>
<pre><span id="VALall_units"><span class="keyword">val</span> all_units</span> : <code class="type">unit -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Return the list of compilation units that form the main program together
with those that have been dynamically loaded via <code class="code">loadfile</code> (and not via
<code class="code">loadfile_private</code>).</p>
</div>
</div>
<pre><span id="VALallow_unsafe_modules"><span class="keyword">val</span> allow_unsafe_modules</span> : <code class="type">bool -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Govern whether unsafe object files are allowed to be
dynamically linked. A compilation unit is 'unsafe' if it contains
declarations of external functions, which can break type safety.
By default, dynamic linking of unsafe object files is
not allowed. In native code, this function does nothing; object files
with external functions are always allowed to be dynamically linked.</p>
</div>
</div>
<h2 id="1_Errorreporting">Error reporting</h2>
<pre><code><span id="TYPElinking_error"><span class="keyword">type</span> <code class="type"></code>linking_error</span> = private </code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlinking_error.Undefined_global"><span class="constructor">Undefined_global</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlinking_error.Unavailable_primitive"><span class="constructor">Unavailable_primitive</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlinking_error.Uninitialized_global"><span class="constructor">Uninitialized_global</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr></table>
<pre><code><span id="TYPEerror"><span class="keyword">type</span> <code class="type"></code>error</span> = private </code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Not_a_bytecode_file"><span class="constructor">Not_a_bytecode_file</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Inconsistent_import"><span class="constructor">Inconsistent_import</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Unavailable_unit"><span class="constructor">Unavailable_unit</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Unsafe_file"><span class="constructor">Unsafe_file</span></span></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Linking_error"><span class="constructor">Linking_error</span></span> <span class="keyword">of</span> <code class="type">string * <a href="Dynlink.html#TYPElinking_error">linking_error</a></code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Corrupted_interface"><span class="constructor">Corrupted_interface</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Cannot_open_dynamic_library"><span class="constructor">Cannot_open_dynamic_library</span></span> <span class="keyword">of</span> <code class="type">exn</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Library's_module_initializers_failed"><span class="constructor">Library's_module_initializers_failed</span></span> <span class="keyword">of</span> <code class="type">exn</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Inconsistent_implementation"><span class="constructor">Inconsistent_implementation</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Module_already_loaded"><span class="constructor">Module_already_loaded</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTerror.Private_library_cannot_implement_interface"><span class="constructor">Private_library_cannot_implement_interface</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>
</tr></table>
<pre><span id="EXCEPTIONError"><span class="keyword">exception</span> Error</span> <span class="keyword">of</span> <code class="type"><a href="Dynlink.html#TYPEerror">error</a></code></pre>
<div class="info ">
<div class="info-desc">
<p>Errors in dynamic linking are reported by raising the <code class="code"><span class="constructor">Error</span></code>
exception with a description of the error.
A common case is the dynamic library not being found on the system: this
is reported via <code class="code"><span class="constructor">Cannot_open_dynamic_library</span></code> (the enclosed exception may
be platform-specific).</p>
</div>
</div>
<pre><span id="VALerror_message"><span class="keyword">val</span> error_message</span> : <code class="type"><a href="Dynlink.html#TYPEerror">error</a> -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Convert an error description to a printable message.</p>
</div>
</div>
</body></html>
|