| 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="cObjects.html" /> |
| 13 | <link rel="prev" href="slice-objects.html" /> |
| 14 | <link rel="parent" href="otherObjects.html" /> |
| 15 | <link rel="next" href="cObjects.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>7.5.8 Weak Reference 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="7.5.7 Slice Objects" |
| 25 | href="slice-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.9 CObjects" |
| 31 | href="cObjects.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="slice-objects.html">7.5.7 Slice 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="cObjects.html">7.5.9 CObjects</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION009580000000000000000"></A><A NAME="weakref-objects"></A> |
| 56 | <BR> |
| 57 | 7.5.8 Weak Reference Objects |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | Python supports <em>weak references</em> as first-class objects. There |
| 62 | are two specific object types which directly implement weak |
| 63 | references. The first is a simple reference object, and the second |
| 64 | acts as a proxy for the original object as much as it can. |
| 65 | |
| 66 | <P> |
| 67 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-718' xml:id='l2h-718' class="cfunction">PyWeakref_Check</tt></b>(</nobr></td><td>ob)</td></tr></table></dt> |
| 68 | <dd> |
| 69 | Return true if <var>ob</var> is either a reference or proxy object. |
| 70 | |
| 71 | <span class="versionnote">New in version 2.2.</span> |
| 72 | |
| 73 | </dd></dl> |
| 74 | |
| 75 | <P> |
| 76 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-719' xml:id='l2h-719' class="cfunction">PyWeakref_CheckRef</tt></b>(</nobr></td><td>ob)</td></tr></table></dt> |
| 77 | <dd> |
| 78 | Return true if <var>ob</var> is a reference object. |
| 79 | |
| 80 | <span class="versionnote">New in version 2.2.</span> |
| 81 | |
| 82 | </dd></dl> |
| 83 | |
| 84 | <P> |
| 85 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-720' xml:id='l2h-720' class="cfunction">PyWeakref_CheckProxy</tt></b>(</nobr></td><td>ob)</td></tr></table></dt> |
| 86 | <dd> |
| 87 | Return true if <var>ob</var> is a proxy object. |
| 88 | |
| 89 | <span class="versionnote">New in version 2.2.</span> |
| 90 | |
| 91 | </dd></dl> |
| 92 | |
| 93 | <P> |
| 94 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-721' xml:id='l2h-721' class="cfunction">PyWeakref_NewRef</tt></b>(</nobr></td><td>PyObject *<var>ob</var>, |
| 95 | PyObject *<var>callback</var>)</td></tr></table></dt> |
| 96 | <dd> |
| 97 | <div class="refcount-info"> |
| 98 | <span class="label">Return value:</span> |
| 99 | <span class="value">New reference.</span> |
| 100 | </div> |
| 101 | Return a weak reference object for the object <var>ob</var>. This will |
| 102 | always return a new reference, but is not guaranteed to create a new |
| 103 | object; an existing reference object may be returned. The second |
| 104 | parameter, <var>callback</var>, can be a callable object that receives |
| 105 | notification when <var>ob</var> is garbage collected; it should accept a |
| 106 | single parameter, which will be the weak reference object itself. |
| 107 | <var>callback</var> may also be <code>None</code> or <tt class="constant">NULL</tt>. If <var>ob</var> |
| 108 | is not a weakly-referencable object, or if <var>callback</var> is not |
| 109 | callable, <code>None</code>, or <tt class="constant">NULL</tt>, this will return <tt class="constant">NULL</tt> and |
| 110 | raise <tt class="exception">TypeError</tt>. |
| 111 | |
| 112 | <span class="versionnote">New in version 2.2.</span> |
| 113 | |
| 114 | </dd></dl> |
| 115 | |
| 116 | <P> |
| 117 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-722' xml:id='l2h-722' class="cfunction">PyWeakref_NewProxy</tt></b>(</nobr></td><td>PyObject *<var>ob</var>, |
| 118 | PyObject *<var>callback</var>)</td></tr></table></dt> |
| 119 | <dd> |
| 120 | <div class="refcount-info"> |
| 121 | <span class="label">Return value:</span> |
| 122 | <span class="value">New reference.</span> |
| 123 | </div> |
| 124 | Return a weak reference proxy object for the object <var>ob</var>. This |
| 125 | will always return a new reference, but is not guaranteed to create |
| 126 | a new object; an existing proxy object may be returned. The second |
| 127 | parameter, <var>callback</var>, can be a callable object that receives |
| 128 | notification when <var>ob</var> is garbage collected; it should accept a |
| 129 | single parameter, which will be the weak reference object itself. |
| 130 | <var>callback</var> may also be <code>None</code> or <tt class="constant">NULL</tt>. If <var>ob</var> is not |
| 131 | a weakly-referencable object, or if <var>callback</var> is not callable, |
| 132 | <code>None</code>, or <tt class="constant">NULL</tt>, this will return <tt class="constant">NULL</tt> and raise |
| 133 | <tt class="exception">TypeError</tt>. |
| 134 | |
| 135 | <span class="versionnote">New in version 2.2.</span> |
| 136 | |
| 137 | </dd></dl> |
| 138 | |
| 139 | <P> |
| 140 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-723' xml:id='l2h-723' class="cfunction">PyWeakref_GetObject</tt></b>(</nobr></td><td>PyObject *<var>ref</var>)</td></tr></table></dt> |
| 141 | <dd> |
| 142 | <div class="refcount-info"> |
| 143 | <span class="label">Return value:</span> |
| 144 | <span class="value">Borrowed reference.</span> |
| 145 | </div> |
| 146 | Return the referenced object from a weak reference, <var>ref</var>. If |
| 147 | the referent is no longer live, returns <code>None</code>. |
| 148 | |
| 149 | <span class="versionnote">New in version 2.2.</span> |
| 150 | |
| 151 | </dd></dl> |
| 152 | |
| 153 | <P> |
| 154 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-724' xml:id='l2h-724' class="cfunction">PyWeakref_GET_OBJECT</tt></b>(</nobr></td><td>PyObject *<var>ref</var>)</td></tr></table></dt> |
| 155 | <dd> |
| 156 | <div class="refcount-info"> |
| 157 | <span class="label">Return value:</span> |
| 158 | <span class="value">Borrowed reference.</span> |
| 159 | </div> |
| 160 | Similar to <tt class="cfunction">PyWeakref_GetObject()</tt>, but implemented as a |
| 161 | macro that does no error checking. |
| 162 | |
| 163 | <span class="versionnote">New in version 2.2.</span> |
| 164 | |
| 165 | </dd></dl> |
| 166 | |
| 167 | <P> |
| 168 | |
| 169 | <DIV CLASS="navigation"> |
| 170 | <div class='online-navigation'> |
| 171 | <p></p><hr /> |
| 172 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 173 | <tr> |
| 174 | <td class='online-navigation'><a rel="prev" title="7.5.7 Slice Objects" |
| 175 | href="slice-objects.html"><img src='../icons/previous.png' |
| 176 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 177 | <td class='online-navigation'><a rel="parent" title="7.5 Other Objects" |
| 178 | href="otherObjects.html"><img src='../icons/up.png' |
| 179 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 180 | <td class='online-navigation'><a rel="next" title="7.5.9 CObjects" |
| 181 | href="cObjects.html"><img src='../icons/next.png' |
| 182 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 183 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 184 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 185 | href="contents.html"><img src='../icons/contents.png' |
| 186 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 187 | <td class='online-navigation'><img src='../icons/blank.png' |
| 188 | border='0' height='32' alt='' width='32' /></td> |
| 189 | <td class='online-navigation'><a rel="index" title="Index" |
| 190 | href="genindex.html"><img src='../icons/index.png' |
| 191 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 192 | </tr></table> |
| 193 | <div class='online-navigation'> |
| 194 | <b class="navlabel">Previous:</b> |
| 195 | <a class="sectref" rel="prev" href="slice-objects.html">7.5.7 Slice Objects</A> |
| 196 | <b class="navlabel">Up:</b> |
| 197 | <a class="sectref" rel="parent" href="otherObjects.html">7.5 Other Objects</A> |
| 198 | <b class="navlabel">Next:</b> |
| 199 | <a class="sectref" rel="next" href="cObjects.html">7.5.9 CObjects</A> |
| 200 | </div> |
| 201 | </div> |
| 202 | <hr /> |
| 203 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 204 | </DIV> |
| 205 | <!--End of Navigation Panel--> |
| 206 | <ADDRESS> |
| 207 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 208 | </ADDRESS> |
| 209 | </BODY> |
| 210 | </HTML> |