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="api.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="api.html" title='Python/C API Reference Manual' /> | |
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="cell-objects.html" /> | |
13 | <link rel="prev" href="weakref-objects.html" /> | |
14 | <link rel="parent" href="otherObjects.html" /> | |
15 | <link rel="next" href="cell-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.5.9 CObjects </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="7.5.8 Weak Reference Objects" | |
25 | href="weakref-objects.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="7.5 Other Objects" | |
28 | href="otherObjects.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="7.5.10 Cell Objects" | |
31 | href="cell-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/C API Reference Manual</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'><img src='../icons/blank.png' | |
38 | border='0' height='32' alt='' width='32' /></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="weakref-objects.html">7.5.8 Weak Reference Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="cell-objects.html">7.5.10 Cell Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION009590000000000000000"></A><A NAME="cObjects"></A> | |
56 | <BR> | |
57 | 7.5.9 CObjects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | <a id='l2h-725' xml:id='l2h-725'></a>Refer to <em>Extending and Embedding the Python Interpreter</em>, | |
62 | section 1.12, ``Providing a C API for an Extension Module,'' for more | |
63 | information on using these objects. | |
64 | ||
65 | <P> | |
66 | <dl><dt><b><tt class="ctype"><a id='l2h-726' xml:id='l2h-726'>PyCObject</a></tt></b></dt> | |
67 | <dd> | |
68 | This subtype of <tt class="ctype">PyObject</tt> represents an opaque value, useful | |
69 | for C extension modules who need to pass an opaque value (as a | |
70 | <tt class="ctype">void*</tt> pointer) through Python code to other C code. It is | |
71 | often used to make a C function pointer defined in one module | |
72 | available to other modules, so the regular import mechanism can be | |
73 | used to access C APIs defined in dynamically loaded modules. | |
74 | </dl> | |
75 | ||
76 | <P> | |
77 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-727' xml:id='l2h-727' class="cfunction">PyCObject_Check</tt></b>(</nobr></td><td>PyObject *<var>p</var>)</td></tr></table></dt> | |
78 | <dd> | |
79 | Return true if its argument is a <tt class="ctype">PyCObject</tt>. | |
80 | </dd></dl> | |
81 | ||
82 | <P> | |
83 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-728' xml:id='l2h-728' class="cfunction">PyCObject_FromVoidPtr</tt></b>(</nobr></td><td>void* <var>cobj</var>, | |
84 | void (*destr)(void *))</td></tr></table></dt> | |
85 | <dd> | |
86 | <div class="refcount-info"> | |
87 | <span class="label">Return value:</span> | |
88 | <span class="value">New reference.</span> | |
89 | </div> | |
90 | Create a <tt class="ctype">PyCObject</tt> from the <code>void *</code><var>cobj</var>. The | |
91 | <var>destr</var> function will be called when the object is reclaimed, | |
92 | unless it is <tt class="constant">NULL</tt>. | |
93 | </dd></dl> | |
94 | ||
95 | <P> | |
96 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-729' xml:id='l2h-729' class="cfunction">PyCObject_FromVoidPtrAndDesc</tt></b>(</nobr></td><td>void* <var>cobj</var>, | |
97 | void* <var>desc</var>, void (*destr)(void *, void *))</td></tr></table></dt> | |
98 | <dd> | |
99 | <div class="refcount-info"> | |
100 | <span class="label">Return value:</span> | |
101 | <span class="value">New reference.</span> | |
102 | </div> | |
103 | Create a <tt class="ctype">PyCObject</tt> from the <tt class="ctype">void *</tt><var>cobj</var>. The | |
104 | <var>destr</var> function will be called when the object is reclaimed. | |
105 | The <var>desc</var> argument can be used to pass extra callback data for | |
106 | the destructor function. | |
107 | </dd></dl> | |
108 | ||
109 | <P> | |
110 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void* <b><tt id='l2h-730' xml:id='l2h-730' class="cfunction">PyCObject_AsVoidPtr</tt></b>(</nobr></td><td>PyObject* <var>self</var>)</td></tr></table></dt> | |
111 | <dd> | |
112 | Return the object <tt class="ctype">void *</tt> that the <tt class="ctype">PyCObject</tt> | |
113 | <var>self</var> was created with. | |
114 | </dd></dl> | |
115 | ||
116 | <P> | |
117 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>void* <b><tt id='l2h-731' xml:id='l2h-731' class="cfunction">PyCObject_GetDesc</tt></b>(</nobr></td><td>PyObject* <var>self</var>)</td></tr></table></dt> | |
118 | <dd> | |
119 | Return the description <tt class="ctype">void *</tt> that the <tt class="ctype">PyCObject</tt> | |
120 | <var>self</var> was created with. | |
121 | </dd></dl> | |
122 | ||
123 | <P> | |
124 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-732' xml:id='l2h-732' class="cfunction">PyCObject_SetVoidPtr</tt></b>(</nobr></td><td>PyObject* <var>self</var>, void* <var>cobj</var>)</td></tr></table></dt> | |
125 | <dd> | |
126 | Set the void pointer inside <var>self</var> to <var>cobj</var>. | |
127 | The <tt class="ctype">PyCObject</tt> must not have an associated destructor. | |
128 | Return true on success, false on failure. | |
129 | </dd></dl> | |
130 | ||
131 | <P> | |
132 | ||
133 | <DIV CLASS="navigation"> | |
134 | <div class='online-navigation'> | |
135 | <p></p><hr /> | |
136 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
137 | <tr> | |
138 | <td class='online-navigation'><a rel="prev" title="7.5.8 Weak Reference Objects" | |
139 | href="weakref-objects.html"><img src='../icons/previous.png' | |
140 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
141 | <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" | |
142 | href="otherObjects.html"><img src='../icons/up.png' | |
143 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
144 | <td class='online-navigation'><a rel="next" title="7.5.10 Cell Objects" | |
145 | href="cell-objects.html"><img src='../icons/next.png' | |
146 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
147 | <td align="center" width="100%">Python/C API Reference Manual</td> | |
148 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
149 | href="contents.html"><img src='../icons/contents.png' | |
150 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
151 | <td class='online-navigation'><img src='../icons/blank.png' | |
152 | border='0' height='32' alt='' width='32' /></td> | |
153 | <td class='online-navigation'><a rel="index" title="Index" | |
154 | href="genindex.html"><img src='../icons/index.png' | |
155 | border='0' height='32' alt='Index' width='32' /></A></td> | |
156 | </tr></table> | |
157 | <div class='online-navigation'> | |
158 | <b class="navlabel">Previous:</b> | |
159 | <a class="sectref" rel="prev" href="weakref-objects.html">7.5.8 Weak Reference Objects</A> | |
160 | <b class="navlabel">Up:</b> | |
161 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> | |
162 | <b class="navlabel">Next:</b> | |
163 | <a class="sectref" rel="next" href="cell-objects.html">7.5.10 Cell Objects</A> | |
164 | </div> | |
165 | </div> | |
166 | <hr /> | |
167 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
168 | </DIV> | |
169 | <!--End of Navigation Panel--> | |
170 | <ADDRESS> | |
171 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
172 | </ADDRESS> | |
173 | </BODY> | |
174 | </HTML> |