dynaloader.html

来自「perl教程」· HTML 代码 · 共 545 行 · 第 1/2 页

HTML
545
字号
</dd>
<dd>
<p>Some unusual systems, such as VMS, require special filename handling in
order to deal with symbolic names for files (i.e., VMS's Logical Names).</p>
</dd>
<dd>
<p>To support these systems a <a href="#item_dl_expandspec"><code>dl_expandspec()</code></a> function can be implemented
either in the <em>dl_*.xs</em> file or code can be added to the autoloadable
<a href="#item_dl_expandspec"><code>dl_expandspec()</code></a> function in <em>DynaLoader.pm</em>.  See <em>DynaLoader.pm</em> for
more information.</p>
</dd>
</li>
<dt><strong><a name="item_dl_load_file"><code>dl_load_file()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    $libref = dl_load_file($filename, $flags)</pre>
</dd>
<dd>
<p>Dynamically load $filename, which must be the path to a shared object
or library.  An opaque 'library reference' is returned as a handle for
the loaded object.  Returns undef on error.</p>
</dd>
<dd>
<p>The $flags argument to alters dl_load_file behaviour.  
Assigned bits:</p>
</dd>
<dd>
<pre>
 <span class="number">0x01</span>  <span class="variable">make</span> <span class="variable">symbols</span> <span class="variable">available</span> <span class="keyword">for</span> <span class="variable">linking</span> <span class="variable">later</span> <span class="variable">dl_load_file's</span><span class="operator">.</span>
       <span class="operator">(</span><span class="variable">only</span> <span class="variable">known</span> <span class="variable">to</span> <span class="variable">work</span> <span class="variable">on</span> <span class="variable">Solaris</span> <span class="number">2</span> <span class="variable">using</span> <span class="variable">dlopen</span><span class="operator">(</span><span class="variable">RTLD_GLOBAL</span><span class="operator">))</span>
       <span class="operator">(</span><span class="variable">ignored</span> <span class="variable">under</span> <span class="variable">VMS</span><span class="operator">;</span> <span class="variable">this</span> <span class="variable">is</span> <span class="variable">a</span> <span class="variable">normal</span> <span class="variable">part</span> <span class="variable">of</span> <span class="variable">image</span> <span class="variable">linking</span><span class="operator">)</span>
</pre>
</dd>
<dd>
<p>(On systems that provide a handle for the loaded object such as SunOS
and HPUX, $libref will be that handle.  On other systems $libref will
typically be $filename or a pointer to a buffer containing $filename.
The application should not examine or alter $libref in any way.)</p>
</dd>
<dd>
<p>This is the function that does the real work.  It should use the
current values of @dl_require_symbols and @dl_resolve_using if required.</p>
</dd>
<dd>
<pre>
    <span class="variable">SunOS</span><span class="operator">:</span> <span class="variable">dlopen</span><span class="operator">(</span><span class="variable">$filename</span><span class="operator">)</span>
    <span class="variable">HP</span><span class="operator">-</span><span class="variable">UX</span><span class="operator">:</span> <span class="variable">shl_load</span><span class="operator">(</span><span class="variable">$filename</span><span class="operator">)</span>
    <span class="variable">Linux</span><span class="operator">:</span> <span class="variable">dld_create_reference</span><span class="operator">(</span><span class="variable">@dl_require_symbols</span><span class="operator">);</span> <span class="variable">dld_link</span><span class="operator">(</span><span class="variable">$filename</span><span class="operator">)</span>
    <span class="variable">NeXT</span><span class="operator">:</span>  <span class="variable">rld_load</span><span class="operator">(</span><span class="variable">$filename</span><span class="operator">,</span> <span class="variable">@dl_resolve_using</span><span class="operator">)</span>
    <span class="variable">VMS</span><span class="operator">:</span>   <span class="variable">lib</span><span class="variable">$find_image_symbol</span><span class="operator">(</span><span class="variable">$filename</span><span class="operator">,</span><span class="variable">$dl_require_symbols</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><span class="operator">)</span>
</pre>
</dd>
<dd>
<p>(The <code>dlopen()</code> function is also used by Solaris and some versions of
Linux, and is a common choice when providing a &quot;wrapper&quot; on other
mechanisms as is done in the OS/2 port.)</p>
</dd>
</li>
<dt><strong><a name="item_dl_unload_file"><code>dl_unload_file()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    $status = dl_unload_file($libref)</pre>
</dd>
<dd>
<p>Dynamically unload $libref, which must be an opaque 'library reference' as
returned from dl_load_file.  Returns one on success and zero on failure.</p>
</dd>
<dd>
<p>This function is optional and may not necessarily be provided on all platforms.
If it is defined, it is called automatically when the interpreter exits for
every shared object or library loaded by DynaLoader::bootstrap.  All such
library references are stored in @dl_librefs by DynaLoader::Bootstrap as it
loads the libraries.  The files are unloaded in last-in, first-out order.</p>
</dd>
<dd>
<p>This unloading is usually necessary when embedding a shared-object perl (e.g.
one configured with -Duseshrplib) within a larger application, and the perl
interpreter is created and destroyed several times within the lifetime of the
application.  In this case it is possible that the system dynamic linker will
unload and then subsequently reload the shared libperl without relocating any
references to it from any files DynaLoaded by the previous incarnation of the
interpreter.  As a result, any shared objects opened by DynaLoader may point to
a now invalid 'ghost' of the libperl shared object, causing apparently random
memory corruption and crashes.  This behaviour is most commonly seen when using
Apache and mod_perl built with the APXS mechanism.</p>
</dd>
<dd>
<pre>
    SunOS: dlclose($libref)
    HP-UX: ???
    Linux: ???
    NeXT:  ???
    VMS:   ???</pre>
</dd>
<dd>
<p>(The <code>dlclose()</code> function is also used by Solaris and some versions of
Linux, and is a common choice when providing a &quot;wrapper&quot; on other
mechanisms as is done in the OS/2 port.)</p>
</dd>
</li>
<dt><strong><a name="item_dl_load_flags"><code>dl_load_flags()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    <span class="variable">$flags</span> <span class="operator">=</span> <span class="variable">dl_load_flags</span> <span class="variable">$modulename</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>Designed to be a method call, and to be overridden by a derived class
(i.e. a class which has DynaLoader in its @ISA).  The definition in
DynaLoader itself returns 0, which produces standard behavior from
dl_load_file().</p>
</dd>
</li>
<dt><strong><a name="item_dl_find_symbol"><code>dl_find_symbol()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    $symref = dl_find_symbol($libref, $symbol)</pre>
</dd>
<dd>
<p>Return the address of the symbol $symbol or <a href="../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if not found.  If the
target system has separate functions to search for symbols of different
types then <a href="#item_dl_find_symbol"><code>dl_find_symbol()</code></a> should search for function symbols first and
then other types.</p>
</dd>
<dd>
<p>The exact manner in which the address is returned in $symref is not
currently defined.  The only initial requirement is that $symref can
be passed to, and understood by, dl_install_xsub().</p>
</dd>
<dd>
<pre>
    SunOS: dlsym($libref, $symbol)
    HP-UX: shl_findsym($libref, $symbol)
    Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
    NeXT:  rld_lookup(&quot;_$symbol&quot;)
    VMS:   lib$find_image_symbol($libref,$symbol)</pre>
</dd>
</li>
<dt><strong><a name="item_dl_find_symbol_anywhere"><code>dl_find_symbol_anywhere()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    $symref = dl_find_symbol_anywhere($symbol)</pre>
</dd>
<dd>
<p>Applies <a href="#item_dl_find_symbol"><code>dl_find_symbol()</code></a> to the members of @dl_librefs and returns
the first match found.</p>
</dd>
</li>
<dt><strong><a name="item_dl_undef_symbols"><code>dl_undef_symbols()</code></a></strong>

<dd>
<p>Example</p>
</dd>
<dd>
<pre>
    @symbols = dl_undef_symbols()</pre>
</dd>
<dd>
<p>Return a list of symbol names which remain undefined after load_file().
Returns <code>()</code> if not known.  Don't worry if your platform does not provide
a mechanism for this.  Most do not need it and hence do not provide it,
they just return an empty list.</p>
</dd>
</li>
<dt><strong><a name="item_dl_install_xsub"><code>dl_install_xsub()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    dl_install_xsub($perl_name, $symref [, $filename])</pre>
</dd>
<dd>
<p>Create a new Perl external subroutine named $perl_name using $symref as
a pointer to the function which implements the routine.  This is simply
a direct call to newXSUB().  Returns a reference to the installed
function.</p>
</dd>
<dd>
<p>The $filename parameter is used by Perl to identify the source file for
the function if required by die(), <a href="../lib/Pod/perlfunc.html#item_caller"><code>caller()</code></a> or the debugger.  If
$filename is not defined then &quot;DynaLoader&quot; will be used.</p>
</dd>
</li>
<dt><strong><a name="item_bootstrap"><code>bootstrap()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<p><a href="#item_bootstrap"><code>bootstrap($module)</code></a></p>
</dd>
<dd>
<p>This is the normal entry point for automatic dynamic loading in Perl.</p>
</dd>
<dd>
<p>It performs the following actions:</p>
</dd>
<ul>
<li>
<p>locates an auto/$module directory by searching @INC</p>
</li>
<li>
<p>uses <a href="#item_dl_findfile"><code>dl_findfile()</code></a> to determine the filename to load</p>
</li>
<li>
<p>sets @dl_require_symbols to <code>(&quot;boot_$module&quot;)</code></p>
</li>
<li>
<p>executes an <em>auto/$module/$module.bs</em> file if it exists
(typically used to add to @dl_resolve_using any files which
are required to load the module on the current platform)</p>
</li>
<li>
<p>calls <a href="#item_dl_load_flags"><code>dl_load_flags()</code></a> to determine how to load the file.</p>
</li>
<li>
<p>calls <a href="#item_dl_load_file"><code>dl_load_file()</code></a> to load the file</p>
</li>
<li>
<p>calls <a href="#item_dl_undef_symbols"><code>dl_undef_symbols()</code></a> and warns if any symbols are undefined</p>
</li>
<li>
<p>calls <a href="#item_dl_find_symbol"><code>dl_find_symbol()</code></a> for &quot;boot_$module&quot;</p>
</li>
<li>
<p>calls <a href="#item_dl_install_xsub"><code>dl_install_xsub()</code></a> to install it as &quot;${module}::bootstrap&quot;</p>
</li>
<li>
<p>calls &amp;{&quot;${module}::bootstrap&quot;} to bootstrap the module (actually
it uses the function reference returned by dl_install_xsub for speed)</p>
</li>
</ul>
</dl>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Tim Bunce, 11 August 1994.</p>
<p>This interface is based on the work and comments of (in no particular
order): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
Siegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.</p>
<p>Larry Wall designed the elegant inherited bootstrap mechanism and
implemented the first Perl 5 dynamic loader using it.</p>
<p>Solaris global loading added by Nick Ing-Simmons with design/coding
assistance from Tim Bunce, January 1996.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?