Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-dbm.html" /> | |
13 | <link rel="prev" href="module-crypt.html" /> | |
14 | <link rel="parent" href="unix.html" /> | |
15 | <link rel="next" href="dl-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>8.5 dl -- Call C functions in shared objects</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="8.4 crypt " | |
25 | href="module-crypt.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="8. Unix Specific Services" | |
28 | href="unix.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="8.5.1 Dl Objects" | |
31 | href="dl-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-crypt.html">8.4 crypt </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="dl-objects.html">8.5.1 Dl Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0010500000000000000000"> | |
56 | 8.5 <tt class="module">dl</tt> -- | |
57 | Call C functions in shared objects</A> | |
58 | </H1> | |
59 | <A NAME="module-dl"></A> | |
60 | <p class="availability">Availability: <span | |
61 | class="platform">Unix</span>.</p> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">dl</tt> module defines an interface to the | |
65 | <tt class="cfunction">dlopen()</tt> function, which is the most common interface on | |
66 | <span class="Unix">Unix</span> platforms for handling dynamically linked libraries. It allows | |
67 | the program to call arbitrary functions in such a library. | |
68 | ||
69 | <P> | |
70 | <span class="note"><b class="label">Note:</b> | |
71 | This module will not work unless | |
72 | <code>sizeof(int) == sizeof(long) == sizeof(char *)</code> | |
73 | If this is not the case, <tt class="exception">SystemError</tt> will be raised on | |
74 | import.</span> | |
75 | ||
76 | <P> | |
77 | The <tt class="module">dl</tt> module defines the following function: | |
78 | ||
79 | <P> | |
80 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
81 | <td><nobr><b><tt id='l2h-2988' xml:id='l2h-2988' class="function">open</tt></b>(</nobr></td> | |
82 | <td><var>name</var><big>[</big><var>, mode<code> = RTLD_LAZY</code></var><big>]</big><var></var>)</td></tr></table></dt> | |
83 | <dd> | |
84 | Open a shared object file, and return a handle. Mode | |
85 | signifies late binding (<tt class="constant">RTLD_LAZY</tt>) or immediate binding | |
86 | (<tt class="constant">RTLD_NOW</tt>). Default is <tt class="constant">RTLD_LAZY</tt>. Note that some | |
87 | systems do not support <tt class="constant">RTLD_NOW</tt>. | |
88 | ||
89 | <P> | |
90 | Return value is a dlobject. | |
91 | </dl> | |
92 | ||
93 | <P> | |
94 | The <tt class="module">dl</tt> module defines the following constants: | |
95 | ||
96 | <P> | |
97 | <dl><dt><b><tt id='l2h-2989' xml:id='l2h-2989'>RTLD_LAZY</tt></b></dt> | |
98 | <dd> | |
99 | Useful as an argument to <tt class="function">open()</tt>. | |
100 | </dd></dl> | |
101 | ||
102 | <P> | |
103 | <dl><dt><b><tt id='l2h-2990' xml:id='l2h-2990'>RTLD_NOW</tt></b></dt> | |
104 | <dd> | |
105 | Useful as an argument to <tt class="function">open()</tt>. Note that on systems | |
106 | which do not support immediate binding, this constant will not appear | |
107 | in the module. For maximum portability, use <tt class="function">hasattr()</tt> to | |
108 | determine if the system supports immediate binding. | |
109 | </dd></dl> | |
110 | ||
111 | <P> | |
112 | The <tt class="module">dl</tt> module defines the following exception: | |
113 | ||
114 | <P> | |
115 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-2991' xml:id='l2h-2991' class="exception">error</tt></b></dt> | |
116 | <dd> | |
117 | Exception raised when an error has occurred inside the dynamic loading | |
118 | and linking routines. | |
119 | </dd></dl> | |
120 | ||
121 | <P> | |
122 | Example: | |
123 | ||
124 | <P> | |
125 | <div class="verbatim"><pre> | |
126 | >>> import dl, time | |
127 | >>> a=dl.open('/lib/libc.so.6') | |
128 | >>> a.call('time'), time.time() | |
129 | (929723914, 929723914.498) | |
130 | </pre></div> | |
131 | ||
132 | <P> | |
133 | This example was tried on a Debian GNU/Linux system, and is a good | |
134 | example of the fact that using this module is usually a bad alternative. | |
135 | ||
136 | <P> | |
137 | ||
138 | <p><br /></p><hr class='online-navigation' /> | |
139 | <div class='online-navigation'> | |
140 | <!--Table of Child-Links--> | |
141 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
142 | ||
143 | <UL CLASS="ChildLinks"> | |
144 | <LI><A href="dl-objects.html">8.5.1 Dl Objects</a> | |
145 | </ul> | |
146 | <!--End of Table of Child-Links--> | |
147 | </div> | |
148 | ||
149 | <DIV CLASS="navigation"> | |
150 | <div class='online-navigation'> | |
151 | <p></p><hr /> | |
152 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
153 | <tr> | |
154 | <td class='online-navigation'><a rel="prev" title="8.4 crypt " | |
155 | href="module-crypt.html"><img src='../icons/previous.png' | |
156 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
157 | <td class='online-navigation'><a rel="parent" title="8. Unix Specific Services" | |
158 | href="unix.html"><img src='../icons/up.png' | |
159 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
160 | <td class='online-navigation'><a rel="next" title="8.5.1 Dl Objects" | |
161 | href="dl-objects.html"><img src='../icons/next.png' | |
162 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
163 | <td align="center" width="100%">Python Library Reference</td> | |
164 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
165 | href="contents.html"><img src='../icons/contents.png' | |
166 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
167 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
168 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
169 | <td class='online-navigation'><a rel="index" title="Index" | |
170 | href="genindex.html"><img src='../icons/index.png' | |
171 | border='0' height='32' alt='Index' width='32' /></A></td> | |
172 | </tr></table> | |
173 | <div class='online-navigation'> | |
174 | <b class="navlabel">Previous:</b> | |
175 | <a class="sectref" rel="prev" href="module-crypt.html">8.4 crypt </A> | |
176 | <b class="navlabel">Up:</b> | |
177 | <a class="sectref" rel="parent" href="unix.html">8. Unix Specific Services</A> | |
178 | <b class="navlabel">Next:</b> | |
179 | <a class="sectref" rel="next" href="dl-objects.html">8.5.1 Dl Objects</A> | |
180 | </div> | |
181 | </div> | |
182 | <hr /> | |
183 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
184 | </DIV> | |
185 | <!--End of Navigation Panel--> | |
186 | <ADDRESS> | |
187 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
188 | </ADDRESS> | |
189 | </BODY> | |
190 | </HTML> |