PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/package/boost_1_58_0/libs/python/doc/v2/with_custodian_and_ward.html

https://gitlab.com/cdeclare/intcrypt
HTML | 370 lines | 364 code | 1 blank | 5 comment | 0 complexity | 497302f8fccb5433ee8093a5ba95d610 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  3. <!-- Software License, Version 1.0. (See accompanying -->
  4. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  5. <html>
  6. <head>
  7. <meta name="generator" content=
  8. "HTML Tidy for Cygwin (vers 1st February 2003), see www.w3.org">
  9. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
  10. <link rel="stylesheet" type="text/css" href="../boost.css">
  11. <title>
  12. Boost.Python - &lt;boost/python/with_custodian_and_ward.hpp&gt;
  13. </title>
  14. </head>
  15. <body>
  16. <table border="0" cellpadding="7" cellspacing="0" width="100%"
  17. summary="header">
  18. <tr>
  19. <td valign="top" width="300">
  20. <h3>
  21. <a href="../../../../index.htm"><img height="86" width="277"
  22. alt="C++ Boost" src="../../../../boost.png" border="0">
  23. </a>
  24. </h3>
  25. </td>
  26. <td valign="top">
  27. <h1 align="center">
  28. <a href="../index.html">Boost.Python</a>
  29. </h1>
  30. <h2 align="center">
  31. Header &lt;boost/python/with_custodian_and_ward.hpp&gt;
  32. </h2>
  33. </td>
  34. </tr>
  35. </table>
  36. <hr>
  37. <h2>
  38. Contents
  39. </h2>
  40. <dl class="page-index">
  41. <dt>
  42. <a href="#introduction">Introduction</a>
  43. </dt>
  44. <dt>
  45. <a href="#classes">Classes</a>
  46. </dt>
  47. <dd>
  48. <dl class="page-index">
  49. <dt>
  50. <a href="#with_custodian_and_ward-spec">Class Template
  51. <code>with_custodian_and_ward</code></a>
  52. </dt>
  53. <dd>
  54. <dl class="page-index">
  55. <dt>
  56. <a href="#with_custodian_and_ward-spec-synopsis">Class
  57. Template <code>with_custodian_and_ward</code> synopsis</a>
  58. </dt>
  59. <dt>
  60. <a href="#with_custodian_and_ward-spec-statics">Class
  61. <code>with_custodian_and_ward</code> static functions</a>
  62. </dt>
  63. </dl>
  64. </dd>
  65. <dt>
  66. <a href="#with_custodian_and_ward_postcall-spec">Class Template
  67. <code>with_custodian_and_ward_postcall</code></a>
  68. </dt>
  69. <dd>
  70. <dl class="page-index">
  71. <dt>
  72. <a href=
  73. "#with_custodian_and_ward_postcall-spec-synopsis">Class
  74. Template <code>with_custodian_and_ward_postcall</code>
  75. synopsis</a>
  76. </dt>
  77. <dt>
  78. <a href=
  79. "#with_custodian_and_ward_postcall-spec-statics">Class
  80. <code>with_custodian_and_ward_postcall</code> static
  81. functions</a>
  82. </dt>
  83. </dl>
  84. </dd>
  85. </dl>
  86. </dd>
  87. <dt>
  88. <a href="#examples">Example</a>
  89. </dt>
  90. </dl>
  91. <hr>
  92. <h2>
  93. <a name="introduction">Introduction</a>
  94. </h2>This header provides facilities for establishing a lifetime
  95. dependency between two of a function's Python argument or result objects.
  96. The <i>ward</i> object will not be destroyed until after the custodian as
  97. long as the <i>custodian</i> object supports <a href=
  98. "http://www.python.org/doc/current/lib/module-weakref.html">weak
  99. references</a> (Boost.Python extension classes all support weak
  100. references). If the <i>custodian</i> object does not support weak
  101. references and is not <code>None</code>, an appropriate exception will be
  102. thrown. The two class templates <code>with_custodian_and_ward</code> and
  103. <code>with_custodian_and_ward_postcall</code> differ in the point at
  104. which they take effect.
  105. <p>
  106. In order to reduce the chance of inadvertently creating dangling
  107. pointers, the default is to do lifetime binding <i>before</i> the
  108. underlying C++ object is invoked. However, before invocation the result
  109. object is not available, so
  110. <code>with_custodian_and_ward_postcall</code> is provided to bind
  111. lifetimes after invocation. Also, if a C++ exception is thrown after
  112. <code>with_custodian_and_ward&lt;&gt;::precall</code> but before the
  113. underlying C++ object actually stores a pointer, the lifetime of the
  114. custodian and ward objects will be artificially bound together, so one
  115. might choose <code>with_custodian_and_ward_postcall</code> instead,
  116. depending on the semantics of the function being wrapped.
  117. </p>
  118. <p>
  119. Please note that this is <i>not</i> the appropriate tool to use when
  120. wrapping functions which <b>transfer ownership</b> of a raw pointer
  121. across the function-call boundary. Please see the <a href=
  122. "faq.html#ownership">FAQ</a> if you want to do that.
  123. </p>
  124. <h2>
  125. <a name="classes"></a>Classes
  126. </h2>
  127. <h3>
  128. <a name="with_custodian_and_ward-spec"></a>Class template
  129. <code>with_custodian_and_ward</code>
  130. </h3>
  131. <table border="1" summary="with_custodian_and_ward template parameters">
  132. <caption>
  133. <b><code>with_custodian_and_ward</code> template parameters</b>
  134. </caption>
  135. <tr>
  136. <th>
  137. Parameter
  138. </th>
  139. <th>
  140. Requirements
  141. </th>
  142. <th>
  143. Description
  144. </th>
  145. <th>
  146. Default
  147. </th>
  148. </tr>
  149. <tr>
  150. <td>
  151. <code>custodian</code>
  152. </td>
  153. <td>
  154. A positive compile-time constant of type <code>std::size_t</code>.
  155. </td>
  156. <td>
  157. The 1-based index of the parameter which is the dependency in the
  158. lifetime relationship to be established. If used to wrap a member
  159. function, parameter 1 is the target object (<code>*this</code>).
  160. Note that if the target Python object type doesn't support weak
  161. references, a Python <code>TypeError</code> exception will be
  162. raised when the C++ object being wrapped is called.
  163. </td>
  164. </tr>
  165. <tr>
  166. <td>
  167. <code>ward</code>
  168. </td>
  169. <td>
  170. A positive compile-time constant of type <code>std::size_t</code>.
  171. </td>
  172. <td>
  173. The 1-based index of the parameter which is the dependent in the
  174. lifetime relationship to be established. If used to wrap a member
  175. function, parameter 1 is the target object (<code>*this</code>).
  176. </td>
  177. </tr>
  178. <tr>
  179. <td>
  180. <code>Base</code>
  181. </td>
  182. <td>
  183. A model of <a href="CallPolicies.html">CallPolicies</a>
  184. </td>
  185. <td>
  186. Used for <a href="CallPolicies.html#composition">policy
  187. composition</a>.
  188. </td>
  189. <td>
  190. <code><a href=
  191. "default_call_policies.html#default_call_policies-spec">default_call_policies</a></code>
  192. </td>
  193. </tr>
  194. </table>
  195. <h4>
  196. <a name="with_custodian_and_ward-spec-synopsis"></a>Class template
  197. <code>with_custodian_and_ward</code> synopsis
  198. </h4>
  199. <pre>
  200. namespace boost { namespace python
  201. {
  202. template &lt;std::size_t custodian, std::size_t ward, class Base = default_call_policies&gt;
  203. struct with_custodian_and_ward : Base
  204. {
  205. static bool precall(PyObject* args);
  206. };
  207. }}
  208. </pre>
  209. <h4>
  210. <a name="with_custodian_and_ward-spec-statics"></a>Class
  211. <code>with_custodian_and_ward</code> static functions
  212. </h4>
  213. <pre>
  214. bool precall(PyObject* args);
  215. </pre>
  216. <dl class="function-semantics">
  217. <dt>
  218. <b>Requires:</b> <code><a href=
  219. "http://www.python.org/doc/2.2/api/tupleObjects.html#l2h-476">PyTuple_Check</a>(args)
  220. != 0</code>
  221. </dt>
  222. <dt>
  223. <b>Effects:</b> Makes the lifetime of the argument indicated by
  224. <code>ward</code> dependent on the lifetime of the argument indicated
  225. by <code>custodian</code>.
  226. </dt>
  227. <dt>
  228. <b>Returns:</b> <code>false</code> and <code><a href=
  229. "http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>()&nbsp;!=&nbsp;0</code>
  230. upon failure, <code>true</code> otherwise.
  231. </dt>
  232. </dl><!-- xxxxxx -->
  233. <h3>
  234. <a name="with_custodian_and_ward_postcall-spec"></a>Class template
  235. <code>with_custodian_and_ward_postcall</code>
  236. </h3>
  237. <table border="1" summary=
  238. "with_custodian_and_ward_postcall template parameters">
  239. <caption>
  240. <b><code>with_custodian_and_ward_postcall</code> template
  241. parameters</b>
  242. </caption>
  243. <tr>
  244. <th>
  245. Parameter
  246. </th>
  247. <th>
  248. Requirements
  249. </th>
  250. <th>
  251. Description
  252. </th>
  253. <th>
  254. Default
  255. </th>
  256. </tr>
  257. <tr>
  258. <td>
  259. <code>custodian</code>
  260. </td>
  261. <td>
  262. A compile-time constant of type <code>std::size_t</code>.
  263. </td>
  264. <td>
  265. The index of the parameter which is the dependency in the lifetime
  266. relationship to be established. Zero indicates the result object; 1
  267. indicates the first argument. If used to wrap a member function,
  268. parameter 1 is the target object (<code>*this</code>). Note that if
  269. the target Python object type doesn't support weak references, a
  270. Python <code>TypeError</code> exception will be raised when the C++
  271. object being wrapped is called.
  272. </td>
  273. </tr>
  274. <tr>
  275. <td>
  276. <code>ward</code>
  277. </td>
  278. <td>
  279. A compile-time constant of type <code>std::size_t</code>.
  280. </td>
  281. <td>
  282. The index of the parameter which is the dependent in the lifetime
  283. relationship to be established. Zero indicates the result object; 1
  284. indicates the first argument. If used to wrap a member function,
  285. parameter 1 is the target object (<code>*this</code>).
  286. </td>
  287. </tr>
  288. <tr>
  289. <td>
  290. <code>Base</code>
  291. </td>
  292. <td>
  293. A model of <a href="CallPolicies.html">CallPolicies</a>
  294. </td>
  295. <td>
  296. Used for <a href="CallPolicies.html#composition">policy
  297. composition</a>.
  298. </td>
  299. <td>
  300. <code><a href=
  301. "default_call_policies.html#default_call_policies-spec">default_call_policies</a></code>
  302. </td>
  303. </tr>
  304. </table>
  305. <h4>
  306. <a name="with_custodian_and_ward_postcall-spec-synopsis"></a>Class
  307. template <code>with_custodian_and_ward_postcall</code> synopsis
  308. </h4>
  309. <pre>
  310. namespace boost { namespace python
  311. {
  312. template &lt;std::size_t custodian, std::size_t ward, class Base = default_call_policies&gt;
  313. struct with_custodian_and_ward_postcall : Base
  314. {
  315. static PyObject* postcall(PyObject* args, PyObject* result);
  316. };
  317. }}
  318. </pre>
  319. <h4>
  320. <a name="with_custodian_and_ward_postcall-spec-statics"></a>Class
  321. <code>with_custodian_and_ward_postcall</code> static functions
  322. </h4>
  323. <pre>
  324. PyObject* postcall(PyObject* args, PyObject* result);
  325. </pre>
  326. <dl class="function-semantics">
  327. <dt>
  328. <b>Requires:</b> <code><a href=
  329. "http://www.python.org/doc/2.2/api/tupleObjects.html#l2h-476">PyTuple_Check</a>(args)
  330. != 0</code>, <code>result&nbsp;!=&nbsp;0</code>.
  331. </dt>
  332. <dt>
  333. <b>Effects:</b> Makes the lifetime of the object indicated by
  334. <code>ward</code> dependent on the lifetime of the object indicated
  335. by <code>custodian</code>.
  336. </dt>
  337. <dt>
  338. <b>Returns:</b> <code>0</code> and <code><a href=
  339. "http://www.python.org/doc/2.2/api/exceptionHandling.html#l2h-71">PyErr_Occurred</a>()&nbsp;!=&nbsp;0</code>
  340. upon failure, <code>true</code> otherwise.
  341. </dt>
  342. </dl>
  343. <h2>
  344. <a name="examples"></a>Example
  345. </h2>The following example shows how
  346. <code>with_custodian_and_ward_postcall</code> is used by the library to
  347. implement <code><a href=
  348. "return_internal_reference.html#return_internal_reference-spec">return_internal_reference</a></code>
  349. <pre>
  350. template &lt;std::size_t owner_arg = 1, class Base = default_call_policies&gt;
  351. struct return_internal_reference
  352. : with_custodian_and_ward_postcall&lt;0, owner_arg, Base&gt;
  353. {
  354. typedef <a href=
  355. "reference_existing_object.html#reference_existing_object-spec">reference_existing_object</a> result_converter;
  356. };
  357. </pre>
  358. <p>
  359. Revised
  360. <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
  361. 13 November, 2002
  362. <!--webbot bot="Timestamp" endspan i-checksum="39359" -->
  363. </p>
  364. <p>
  365. <i>&copy; Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
  366. Abrahams</a> 2002. </i>
  367. </p>
  368. </body>
  369. </html>