mirror of
https://github.com/boostorg/python.git
synced 2026-01-20 16:52:15 +00:00
Compare commits
152 Commits
boost-1.35
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b627d19486 | ||
|
|
61fc9cf054 | ||
|
|
b3e91f845e | ||
|
|
d67cd6717d | ||
|
|
c44100afda | ||
|
|
1dee81dc71 | ||
|
|
801326275f | ||
|
|
98f20f30d6 | ||
|
|
b01e0e6b9c | ||
|
|
b0a9b11c9c | ||
|
|
304277b806 | ||
|
|
a334649b0c | ||
|
|
79b7f88df6 | ||
|
|
a33ed032c6 | ||
|
|
b316819925 | ||
|
|
52245de2e5 | ||
|
|
2f1f79ce87 | ||
|
|
863bff9072 | ||
|
|
2213cf98c6 | ||
|
|
2dba3148ce | ||
|
|
48aa6ab9a9 | ||
|
|
6ba5067e0b | ||
|
|
60f4f5e54c | ||
|
|
7ee9cf679b | ||
|
|
03a72363a4 | ||
|
|
38cc1a0c15 | ||
|
|
ff44521920 | ||
|
|
0ac7e3f858 | ||
|
|
5cbb539ec5 | ||
|
|
40e4940877 | ||
|
|
ab0911cf53 | ||
|
|
0d81eb6695 | ||
|
|
e0b535df1e | ||
|
|
d2517faa78 | ||
|
|
8cd4ff8950 | ||
|
|
26f77691ee | ||
|
|
6e7f594027 | ||
|
|
eada30f0cb | ||
|
|
e919ffdac4 | ||
|
|
1cf41fd031 | ||
|
|
7b67118271 | ||
|
|
e14c702a40 | ||
|
|
d303ea16fc | ||
|
|
65114d8637 | ||
|
|
597dfc586b | ||
|
|
6a3085ad5d | ||
|
|
190d0d7ea6 | ||
|
|
8b915a15ff | ||
|
|
90c5c19220 | ||
|
|
cfe6f96f69 | ||
|
|
77907c5369 | ||
|
|
512b30c971 | ||
|
|
f005518686 | ||
|
|
274a219965 | ||
|
|
abc4abf84a | ||
|
|
94a3ced83a | ||
|
|
7eb0c678ee | ||
|
|
92460adce6 | ||
|
|
8cfd3fb2ef | ||
|
|
62ef542eaf | ||
|
|
5809078ba9 | ||
|
|
04e54d670c | ||
|
|
dd7c0a7f3d | ||
|
|
71f54cc920 | ||
|
|
9de994c0d1 | ||
|
|
e9caacc428 | ||
|
|
5070e84f70 | ||
|
|
fe23d9885f | ||
|
|
e7ee17b71b | ||
|
|
5edb63d01c | ||
|
|
f4b3aab7d4 | ||
|
|
6af67d1a4c | ||
|
|
16d975ba5c | ||
|
|
4fc5cafd40 | ||
|
|
1b5cd10f7c | ||
|
|
0f91872518 | ||
|
|
dc6b2979e4 | ||
|
|
50034140c4 | ||
|
|
08a6f35ec2 | ||
|
|
67236ffbad | ||
|
|
96ab7a80a4 | ||
|
|
d8c3ff199e | ||
|
|
0c4ebef579 | ||
|
|
8fe9d41b58 | ||
|
|
8a4590b2ef | ||
|
|
d67b040683 | ||
|
|
2db61657f2 | ||
|
|
6d2ee96ba3 | ||
|
|
a74c8e3da3 | ||
|
|
9f4d39d9fe | ||
|
|
31c19644ed | ||
|
|
600d444136 | ||
|
|
c3bd0fcbad | ||
|
|
991a7c198a | ||
|
|
9b67f0447d | ||
|
|
b714f6cc23 | ||
|
|
479a6ba4fc | ||
|
|
d78836b828 | ||
|
|
7a59131d37 | ||
|
|
5ab00bc9c8 | ||
|
|
94500ae36d | ||
|
|
5e5d34cc36 | ||
|
|
c6f2aa4ef2 | ||
|
|
c7fb2f7047 | ||
|
|
afedc1cd9a | ||
|
|
070e02d7d5 | ||
|
|
ccc56c2a4c | ||
|
|
e00a88ff49 | ||
|
|
e527bc860f | ||
|
|
921e306b9a | ||
|
|
bed1d26904 | ||
|
|
41a342f026 | ||
|
|
cee8e07046 | ||
|
|
0806e89964 | ||
|
|
f5421ca6b2 | ||
|
|
eea7697175 | ||
|
|
777ce7b561 | ||
|
|
864ece5539 | ||
|
|
2610eb9acb | ||
|
|
567a2c7b89 | ||
|
|
05070faf12 | ||
|
|
ad8069314d | ||
|
|
9366c48351 | ||
|
|
5a14319753 | ||
|
|
279a4f7888 | ||
|
|
d3418d494c | ||
|
|
c839427246 | ||
|
|
dd3a136b18 | ||
|
|
48696918de | ||
|
|
88be35ddc2 | ||
|
|
9ee0d36a1d | ||
|
|
f240e0bab6 | ||
|
|
4081605e4b | ||
|
|
f332ff2d89 | ||
|
|
ec77608840 | ||
|
|
f5a69a1dab | ||
|
|
a1e865061c | ||
|
|
596e92404a | ||
|
|
2640f5af94 | ||
|
|
0605e9fdcf | ||
|
|
cf68da0b19 | ||
|
|
d3c474b295 | ||
|
|
c9300e07c2 | ||
|
|
cab94a7bba | ||
|
|
caa9cb8268 | ||
|
|
66ac61450e | ||
|
|
59f81def56 | ||
|
|
92862028b7 | ||
|
|
b0ba7dfc50 | ||
|
|
fe3abeda9f | ||
|
|
3fdfb30e33 | ||
|
|
cdcf8633bb |
@@ -11,7 +11,7 @@
|
||||
:alt: Boost C++ Libraries:
|
||||
:class: boost-logo
|
||||
|
||||
__ ../index.htm
|
||||
__ ../index.html
|
||||
|
||||
|
||||
.. section-numbering::
|
||||
|
||||
@@ -375,6 +375,27 @@
|
||||
application modules, including GUI and post-processing of results.</p>
|
||||
</dd>
|
||||
|
||||
<dt><b><a href="http://polybori.sourceforge.net/">PolyBoRi</a></b></dt>
|
||||
|
||||
<dd>
|
||||
<p><a href="mailto:brickenstein@mfo.de"
|
||||
>Michael Brickenstein</a> writes:</p>
|
||||
|
||||
<blockquote>
|
||||
<p>The core of PolyBoRi is a C++ library, which provides
|
||||
high-level data types for Boolean polynomials and monomials,
|
||||
exponent vectors, as well as for the underlying polynomial
|
||||
rings and subsets of the powerset of the Boolean variables. As
|
||||
a unique approach, binary decision diagrams are used as
|
||||
internal storage type for polynomial structures. On top of
|
||||
this C++-library we provide a Python interface. This allows
|
||||
parsing of complex polynomial systems, as well as sophisticated
|
||||
and extendable strategies for Gröbner basis computation.
|
||||
Boost.Python has helped us to create this interface in a
|
||||
very clean way.</p>
|
||||
</blockquote>
|
||||
</dd>
|
||||
|
||||
<dt><b><a href="http://www.rationaldiscovery.com">Rational Discovery
|
||||
LLC</a></b></dt>
|
||||
|
||||
@@ -435,11 +456,11 @@
|
||||
</dl>
|
||||
<hr>
|
||||
|
||||
<p>Revised
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
15 July, 2003</p>
|
||||
29 May, 2008</p>
|
||||
|
||||
<p><i>© Copyright <a href="http://www.boost.org/people/dave_abrahams.htm">Dave
|
||||
Abrahams</a> 2002-2003.</i></p>
|
||||
Abrahams</a> 2002-2008.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Chapter 1. python 1.0</title>
|
||||
<link rel="stylesheet" href="../../../../../../doc/html/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
|
||||
<link rel="start" href="index.html" title="Chapter 1. python 1.0">
|
||||
<link rel="next" href="python/hello.html" title="Building Hello World">
|
||||
<link rel="next" href="python/hello.html" title=" Building Hello World">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../index.htm">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/people/people.htm">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../people/people.htm">People</a></td>
|
||||
<td align="center"><a href="../../../../../../more/faq.htm">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
@@ -31,7 +31,7 @@
|
||||
<div><p class="copyright">Copyright © 2002-2005 Joel
|
||||
de Guzman, David Abrahams</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id2625929"></a><p>
|
||||
<a name="id455917"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">
|
||||
http://www.boost.org/LICENSE_1_0.txt </a>)
|
||||
@@ -93,10 +93,10 @@
|
||||
code takes on the look of a kind of declarative interface definition language
|
||||
(IDL).
|
||||
</p>
|
||||
<a name="quickstart.hello_world"></a><h3>
|
||||
<a name="id2625972"></a>
|
||||
<a name="quickstart.hello_world"></a><h2>
|
||||
<a name="id385257"></a>
|
||||
Hello World
|
||||
</h3>
|
||||
</h2>
|
||||
<p>
|
||||
Following C/C++ tradition, let's start with the "hello, world". A
|
||||
C++ Function:
|
||||
@@ -136,8 +136,8 @@
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
<span class="emphasis"><em><span class="bold"><strong>Next stop... Building your Hello World
|
||||
module from start to finish...</strong></span></em></span>
|
||||
<span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World
|
||||
module from start to finish...</b></span></em></span>
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: March 15, 2008 at 13:46:47 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: November 07, 2007 at 03:34:24 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
Python/C API at all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png" alt="smiley"></span>
|
||||
</p>
|
||||
<a name="embedding.building_embedded_programs"></a><h2>
|
||||
<a name="id471329"></a>
|
||||
<a name="id471171"></a>
|
||||
Building embedded programs
|
||||
</h2>
|
||||
<p>
|
||||
@@ -82,7 +82,7 @@ exe embedded_program # name of the executable
|
||||
<find-library>$(PYTHON_EMBEDDED_LIBRARY) ;
|
||||
</pre>
|
||||
<a name="embedding.getting_started"></a><h2>
|
||||
<a name="id471434"></a>
|
||||
<a name="id471276"></a>
|
||||
Getting started
|
||||
</h2>
|
||||
<p>
|
||||
@@ -139,7 +139,7 @@ exe embedded_program # name of the executable
|
||||
automate the process.
|
||||
</p>
|
||||
<a name="using_the_interpreter.running_python_code"></a><h2>
|
||||
<a name="id471597"></a>
|
||||
<a name="id471439"></a>
|
||||
Running Python code
|
||||
</h2>
|
||||
<p>
|
||||
@@ -190,7 +190,7 @@ exe embedded_program # name of the executable
|
||||
a phrase that is well-known in programming circles.
|
||||
</p>
|
||||
<a name="using_the_interpreter.manipulating_python_objects"></a><h2>
|
||||
<a name="id472185"></a>
|
||||
<a name="id472027"></a>
|
||||
Manipulating Python objects
|
||||
</h2>
|
||||
<p>
|
||||
@@ -217,7 +217,7 @@ exe embedded_program # name of the executable
|
||||
<span class="keyword">int</span> <span class="identifier">five_squared</span> <span class="special">=</span> <span class="identifier">extract</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">result</span><span class="special">);</span>
|
||||
</pre>
|
||||
<a name="using_the_interpreter.exception_handling"></a><h2>
|
||||
<a name="id472557"></a>
|
||||
<a name="id472399"></a>
|
||||
Exception handling
|
||||
</h2>
|
||||
<p>
|
||||
|
||||
@@ -533,7 +533,7 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="python.class_operators_special_functions"></a>Class Operators/Special Functions</h3></div></div></div>
|
||||
<a name="class_operators_special_functions.python_operators"></a><h2>
|
||||
<a name="id461481"></a>
|
||||
<a name="id461460"></a>
|
||||
Python Operators
|
||||
</h2>
|
||||
<p>
|
||||
@@ -582,7 +582,7 @@
|
||||
expressions".
|
||||
</p>
|
||||
<a name="class_operators_special_functions.special_methods"></a><h2>
|
||||
<a name="id462238"></a>
|
||||
<a name="id462216"></a>
|
||||
Special Methods
|
||||
</h2>
|
||||
<p>
|
||||
|
||||
@@ -212,7 +212,7 @@ Namespaces are one honking great idea -- let's do more of those!
|
||||
<li><span class="bold"><b>BOOM!</b></span></li>
|
||||
</ol></div>
|
||||
<a name="call_policies.call_policies"></a><h2>
|
||||
<a name="id464235"></a>
|
||||
<a name="id464076"></a>
|
||||
Call Policies
|
||||
</h2>
|
||||
<p>
|
||||
@@ -415,7 +415,7 @@ Namespaces are one honking great idea -- let's do more of those!
|
||||
</li>
|
||||
</ul></div>
|
||||
<a name="default_arguments.boost_python_function_overloads"></a><h2>
|
||||
<a name="id466276"></a>
|
||||
<a name="id466117"></a>
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS
|
||||
</h2>
|
||||
<p>
|
||||
@@ -445,7 +445,7 @@ Namespaces are one honking great idea -- let's do more of those!
|
||||
<span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">,</span> <span class="identifier">foo_overloads</span><span class="special">());</span>
|
||||
</pre>
|
||||
<a name="default_arguments.boost_python_member_function_overloads"></a><h2>
|
||||
<a name="id466594"></a>
|
||||
<a name="id466436"></a>
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
|
||||
</h2>
|
||||
<p>
|
||||
@@ -491,7 +491,7 @@ Namespaces are one honking great idea -- let's do more of those!
|
||||
reference</a> for details.
|
||||
</p>
|
||||
<a name="default_arguments.init_and_optional"></a><h2>
|
||||
<a name="id466958"></a>
|
||||
<a name="id466799"></a>
|
||||
init and optional
|
||||
</h2>
|
||||
<p>
|
||||
@@ -565,7 +565,7 @@ Namespaces are one honking great idea -- let's do more of those!
|
||||
(0) arguments and a maximum of 3 arguments.
|
||||
</p>
|
||||
<a name="auto_overloading.manual_wrapping"></a><h2>
|
||||
<a name="id467739"></a>
|
||||
<a name="id467581"></a>
|
||||
Manual Wrapping
|
||||
</h2>
|
||||
<p>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="python.hello"></a> Building Hello World</h2></div></div></div>
|
||||
<a name="hello.from_start_to_finish"></a><h2>
|
||||
<a name="id386189"></a>
|
||||
<a name="id387672"></a>
|
||||
From Start To Finish
|
||||
</h2>
|
||||
<p>
|
||||
@@ -92,7 +92,7 @@
|
||||
platforms. The complete list of Bjam executables can be found <a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>.
|
||||
</p>
|
||||
<a name="hello.let_s_jam_"></a><h2>
|
||||
<a name="id386347"></a>
|
||||
<a name="id386265"></a>
|
||||
Let's Jam!
|
||||
</h2>
|
||||
<p>
|
||||
@@ -108,7 +108,7 @@
|
||||
you going.
|
||||
</p>
|
||||
<a name="hello.running_bjam"></a><h2>
|
||||
<a name="id386404"></a>
|
||||
<a name="id386322"></a>
|
||||
Running bjam
|
||||
</h2>
|
||||
<p>
|
||||
@@ -180,16 +180,6 @@ bjam
|
||||
Or something similar. If all is well, you should now have built the DLLs and
|
||||
run the Python program.
|
||||
</p>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td colspan="2" align="left" valign="top"><p>
|
||||
Starting from Boost 1.35, bjam erases the generated executables (e.g. pyd
|
||||
file). To keep bjam from doing that, pass --preserve-test-targets to bjam.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<div class="blockquote"><blockquote class="blockquote">
|
||||
<p>
|
||||
</p>
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
</span><span class="identifier">d</span><span class="special">[</span><span class="char">'whatever'</span><span class="special">]</span> <span class="special">=</span> <span class="number">3</span><span class="special">;</span> <span class="comment">// modifies the copy
|
||||
</span></pre>
|
||||
<a name="derived_object_types.class__lt_t_gt__as_objects"></a><h2>
|
||||
<a name="id469744"></a>
|
||||
<a name="id469586"></a>
|
||||
class_<T> as objects
|
||||
</h2>
|
||||
<p>
|
||||
|
||||
@@ -186,6 +186,10 @@ And so on... Finally:
|
||||
Or something similar. If all is well, you should now have built the DLLs and
|
||||
run the Python program.
|
||||
|
||||
[note Starting from Boost 1.35, bjam erases the generated executables
|
||||
(e.g. pyd file) after the test has concluded to conserve disk space.
|
||||
To keep bjam from doing that, pass --preserve-test-targets to bjam.]
|
||||
|
||||
[:[*There you go... Have fun!]]
|
||||
|
||||
[endsect]
|
||||
@@ -1381,9 +1385,9 @@ interpreter. This may be fixed in a future version of boost.python.]
|
||||
[section Using the interpreter]
|
||||
|
||||
As you probably already know, objects in Python are reference-counted.
|
||||
Naturally, the [^PyObject]s of the Python/C API are also reference-counted.
|
||||
Naturally, the [^PyObject]s of the Python\/C API are also reference-counted.
|
||||
There is a difference however. While the reference-counting is fully
|
||||
automatic in Python, the Python/C API requires you to do it
|
||||
automatic in Python, the Python\/C API requires you to do it
|
||||
[@http://www.python.org/doc/current/api/refcounts.html by hand]. This is
|
||||
messy and especially hard to get right in the presence of C++ exceptions.
|
||||
Fortunately Boost.Python provides the [@../../../v2/handle.html handle] and
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
<a href="doc/html/index.html">link</a> <hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See
|
||||
accompanying file <a href="../../../LICENSE_1_0.txt">
|
||||
accompanying file <a href="../../../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Dereferenceable Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Extractor Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href=../../../../boost.css>
|
||||
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
|
||||
<title>Boost.Python - Holder Concept</title>
|
||||
</head>
|
||||
<body link="#0000ff" vlink="#800080">
|
||||
|
||||
@@ -74,6 +74,32 @@
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#const_objattribute_policies-spec">Class
|
||||
<code>const_objattribute_policies</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#const_objattribute_policies-spec-synopsis">Class
|
||||
<code>const_objattribute_policies</code> synopsis</a></dt>
|
||||
|
||||
<dt><a href="#const_objattribute_policies-spec-statics">Class
|
||||
<code>const_objattribute_policies</code> static functions</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#objattribute_policies-spec">Class
|
||||
<code>objattribute_policies</code></a></dt>
|
||||
|
||||
<dd>
|
||||
<dl class="page-index">
|
||||
<dt><a href="#objattribute_policies-spec-synopsis">Class
|
||||
<code>objattribute_policies</code> synopsis</a></dt>
|
||||
|
||||
<dt><a href="#objattribute_policies-spec-statics">Class
|
||||
<code>objattribute_policies</code> static functions</a></dt>
|
||||
</dl>
|
||||
</dd>
|
||||
|
||||
<dt><a href="#const_item_policies-spec">Class
|
||||
<code>const_item_policies</code></a></dt>
|
||||
|
||||
@@ -328,6 +354,102 @@ static void del(object const&target, char const* key);
|
||||
<!-- end -->
|
||||
<!-- begin -->
|
||||
|
||||
<h3><a name="const_objattribute_policies-spec"></a>Class
|
||||
<code>const_objattribute_policies</code></h3>
|
||||
|
||||
<p>The policies which are used for proxies representing an attribute
|
||||
access to a <code>const object</code> when the attribute name is
|
||||
given as a <code>const object</code>.</p>
|
||||
|
||||
<h4><a name="const_objattribute_policies-spec-synopsis"></a>Class
|
||||
<code>const_objattribute_policies</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python { namespace api
|
||||
{
|
||||
struct const_objattribute_policies
|
||||
{
|
||||
typedef object const& key_type;
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
}}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="const_objattribute_policies-spec-statics"></a>Class
|
||||
<code>const_objattribute_policies</code> static functions</h4>
|
||||
<pre>
|
||||
static object get(object const& target, object const& key);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> accesses the attribute of <code>target</code> named
|
||||
by <code>key</code>.</dt>
|
||||
|
||||
<dt><b>Returns:</b> An <code>object</code> managing the result of the
|
||||
attribute access.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
|
||||
<h3><a name="objattribute_policies-spec"></a>Class
|
||||
<code>objattribute_policies</code></h3>
|
||||
|
||||
<p>The policies which are used for proxies representing an attribute
|
||||
access to a mutable <code>object</code> when the attribute name is
|
||||
given as a <code>const object</code>.</p>
|
||||
|
||||
<h4><a name="objattribute_policies-spec-synopsis"></a>Class
|
||||
<code>objattribute_policies</code> synopsis</h4>
|
||||
<pre>
|
||||
namespace boost { namespace python { namespace api
|
||||
{
|
||||
struct objattribute_policies : const_objattribute_policies
|
||||
{
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
static void del(object const&target, object const& key);
|
||||
};
|
||||
}}}
|
||||
</pre>
|
||||
|
||||
<h4><a name="objattribute_policies-spec-statics"></a>Class
|
||||
<code>objattribute_policies</code> static functions</h4>
|
||||
<pre>
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> sets the attribute of <code>target</code> named by
|
||||
<code>key</code> to <code>value</code>.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
static void del(object const&target, object const& key);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> <code>key</code> is an <code>object</code>
|
||||
holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> deletes the attribute of <code>target</code> named
|
||||
by <code>key</code>.</dt>
|
||||
|
||||
<dt><b>Throws:</b> <code><a href=
|
||||
"errors.html#error_already_set-spec">error_already_set</a></code> if a
|
||||
Python exception is raised.</dt>
|
||||
</dl>
|
||||
<!-- end -->
|
||||
<!-- begin -->
|
||||
|
||||
<h3><a name="const_item_policies-spec"></a>Class
|
||||
<code>const_item_policies</code></h3>
|
||||
|
||||
@@ -533,6 +655,11 @@ namespace boost { namespace python { namespace api
|
||||
template <class A0, class A1,...class An>
|
||||
object operator()(A0 const&, A1 const&,...An const&) const;
|
||||
|
||||
detail::args_proxy operator* () const;
|
||||
object operator()(detail::args_proxy const &args) const;
|
||||
object operator()(detail::args_proxy const &args,
|
||||
detail::kwds_proxy const &kwds) const;
|
||||
|
||||
// truth value testing
|
||||
//
|
||||
typedef unspecified bool_type;
|
||||
@@ -542,6 +669,8 @@ namespace boost { namespace python { namespace api
|
||||
//
|
||||
proxy<const_object_attribute> attr(char const*) const;
|
||||
proxy<object_attribute> attr(char const*);
|
||||
proxy<const_object_objattribute> attr(object const&) const;
|
||||
proxy<object_objattribute> attr(object const&);
|
||||
|
||||
// item access
|
||||
//
|
||||
@@ -580,6 +709,25 @@ object operator()(A0 const& a1, A1 const& a2,...An const& aN) const;
|
||||
call<object>(object(*static_cast<U*>(this)).ptr(), a1,
|
||||
a2,...aN)</dt>
|
||||
</dl>
|
||||
|
||||
<pre>
|
||||
object operator()(detail::args_proxy const &args) const;
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Effects:</b>
|
||||
call object with arguments given by the tuple <varname>args</varname></dt>
|
||||
</dl>
|
||||
<pre>
|
||||
object operator()(detail::args_proxy const &args,
|
||||
detail::kwds_proxy const &kwds) const;
|
||||
</pre>
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Effects:</b>
|
||||
call object with arguments given by the tuple <varname>args</varname>, and named
|
||||
arguments given by the dictionary <varname>kwds</varname></dt>
|
||||
</dl>
|
||||
|
||||
|
||||
<pre>
|
||||
operator bool_type() const;
|
||||
</pre>
|
||||
@@ -608,6 +756,21 @@ proxy<object_attribute> attr(char const* name);
|
||||
<code>name</code> as its key.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
proxy<const_object_objattribute> attr(const object& name) const;
|
||||
proxy<object_objattribute> attr(const object& name);
|
||||
</pre>
|
||||
|
||||
<dl class="function-semantics">
|
||||
<dt><b>Requires:</b> name is a <code>object</code> holding a string.</dt>
|
||||
|
||||
<dt><b>Effects:</b> accesses the named attribute of
|
||||
<code>*this</code>.</dt>
|
||||
|
||||
<dt><b>Returns:</b> a proxy object which binds
|
||||
<code>object(*static_cast<U*>(this))</code> as its target, and
|
||||
<code>name</code> as its key.</dt>
|
||||
</dl>
|
||||
<pre>
|
||||
template <class T>
|
||||
proxy<const_object_item> operator[](T const& key) const;
|
||||
template <class T>
|
||||
@@ -938,11 +1101,11 @@ object sum_items(object seq)
|
||||
</pre>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
||||
13 January, 2006
|
||||
27 May, 2008
|
||||
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
|
||||
</p>
|
||||
|
||||
<p><i>© Copyright <a href=
|
||||
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2006.</i></p>
|
||||
"http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> 2008.</i></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,112 +1,93 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN"
|
||||
"http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
|
||||
<title>Boost.Python Pickle Support</title>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Boost.Python Pickle Support</title>
|
||||
</head>
|
||||
|
||||
<div>
|
||||
<body>
|
||||
<div>
|
||||
<img src="../../../../boost.png" alt="boost.png (6897 bytes)" align=
|
||||
"center" width="277" height="86" />
|
||||
<hr />
|
||||
|
||||
<img src="../../../../boost.png"
|
||||
alt="boost.png (6897 bytes)"
|
||||
align="center"
|
||||
width="277" height="86">
|
||||
<h1>Boost.Python Pickle Support</h1>Pickle is a Python module for object
|
||||
serialization, also known as persistence, marshalling, or flattening.
|
||||
|
||||
<hr>
|
||||
<h1>Boost.Python Pickle Support</h1>
|
||||
<p>It is often necessary to save and restore the contents of an object to
|
||||
a file. One approach to this problem is to write a pair of functions that
|
||||
read and write data from a file in a special format. A powerful
|
||||
alternative approach is to use Python's pickle module. Exploiting
|
||||
Python's ability for introspection, the pickle module recursively
|
||||
converts nearly arbitrary Python objects into a stream of bytes that can
|
||||
be written to a file.</p>
|
||||
|
||||
Pickle is a Python module for object serialization, also known
|
||||
as persistence, marshalling, or flattening.
|
||||
<p>The Boost Python Library supports the pickle module through the
|
||||
interface as described in detail in the <a href=
|
||||
"http://www.python.org/doc/current/lib/module-pickle.html">Python Library
|
||||
Reference for pickle.</a> This interface involves the special methods
|
||||
<tt>__getinitargs__</tt>, <tt>__getstate__</tt> and <tt>__setstate__</tt>
|
||||
as described in the following. Note that Boost.Python is also fully
|
||||
compatible with Python's cPickle module.</p>
|
||||
<hr />
|
||||
|
||||
<p>
|
||||
It is often necessary to save and restore the contents of an object to
|
||||
a file. One approach to this problem is to write a pair of functions
|
||||
that read and write data from a file in a special format. A powerful
|
||||
alternative approach is to use Python's pickle module. Exploiting
|
||||
Python's ability for introspection, the pickle module recursively
|
||||
converts nearly arbitrary Python objects into a stream of bytes that
|
||||
can be written to a file.
|
||||
<h2>The Boost.Python Pickle Interface</h2>At the user level, the
|
||||
Boost.Python pickle interface involves three special methods:
|
||||
|
||||
<p>
|
||||
The Boost Python Library supports the pickle module
|
||||
through the interface as described in detail in the
|
||||
<a href="http://www.python.org/doc/current/lib/module-pickle.html"
|
||||
>Python Library Reference for pickle.</a> This interface
|
||||
involves the special methods <tt>__getinitargs__</tt>,
|
||||
<tt>__getstate__</tt> and <tt>__setstate__</tt> as described
|
||||
in the following. Note that Boost.Python is also fully compatible
|
||||
with Python's cPickle module.
|
||||
<dl>
|
||||
<dt><strong><tt>__getinitargs__</tt></strong></dt>
|
||||
|
||||
<hr>
|
||||
<h2>The Boost.Python Pickle Interface</h2>
|
||||
<dd>
|
||||
When an instance of a Boost.Python extension class is pickled, the
|
||||
pickler tests if the instance has a <tt>__getinitargs__</tt> method.
|
||||
This method must return a Python tuple (it is most convenient to use
|
||||
a boost::python::tuple). When the instance is restored by the
|
||||
unpickler, the contents of this tuple are used as the arguments for
|
||||
the class constructor.
|
||||
|
||||
At the user level, the Boost.Python pickle interface involves three special
|
||||
methods:
|
||||
<p>If <tt>__getinitargs__</tt> is not defined, <tt>pickle.load</tt>
|
||||
will call the constructor (<tt>__init__</tt>) without arguments;
|
||||
i.e., the object must be default-constructible.</p>
|
||||
</dd>
|
||||
|
||||
<dl>
|
||||
<dt>
|
||||
<strong><tt>__getinitargs__</tt></strong>
|
||||
<dd>
|
||||
When an instance of a Boost.Python extension class is pickled, the
|
||||
pickler tests if the instance has a <tt>__getinitargs__</tt> method.
|
||||
This method must return a Python tuple (it is most convenient to use
|
||||
a boost::python::tuple). When the instance is restored by the
|
||||
unpickler, the contents of this tuple are used as the arguments for
|
||||
the class constructor.
|
||||
<dt><strong><tt>__getstate__</tt></strong></dt>
|
||||
|
||||
<p>
|
||||
If <tt>__getinitargs__</tt> is not defined, <tt>pickle.load</tt>
|
||||
will call the constructor (<tt>__init__</tt>) without arguments;
|
||||
i.e., the object must be default-constructible.
|
||||
<dd>When an instance of a Boost.Python extension class is pickled, the
|
||||
pickler tests if the instance has a <tt>__getstate__</tt> method. This
|
||||
method should return a Python object representing the state of the
|
||||
instance.</dd>
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<strong><tt>__getstate__</tt></strong>
|
||||
<dt><strong><tt>__setstate__</tt></strong></dt>
|
||||
|
||||
<dd>
|
||||
When an instance of a Boost.Python extension class is pickled, the
|
||||
pickler tests if the instance has a <tt>__getstate__</tt> method.
|
||||
This method should return a Python object representing the state of
|
||||
the instance.
|
||||
<dd>When an instance of a Boost.Python extension class is restored by
|
||||
the unpickler (<tt>pickle.load</tt>), it is first constructed using the
|
||||
result of <tt>__getinitargs__</tt> as arguments (see above).
|
||||
Subsequently the unpickler tests if the new instance has a
|
||||
<tt>__setstate__</tt> method. If so, this method is called with the
|
||||
result of <tt>__getstate__</tt> (a Python object) as the argument.</dd>
|
||||
</dl>The three special methods described above may be <tt>.def()</tt>'ed
|
||||
individually by the user. However, Boost.Python provides an easy to use
|
||||
high-level interface via the
|
||||
<strong><tt>boost::python::pickle_suite</tt></strong> class that also
|
||||
enforces consistency: <tt>__getstate__</tt> and <tt>__setstate__</tt>
|
||||
must be defined as pairs. Use of this interface is demonstrated by the
|
||||
following examples.
|
||||
<hr />
|
||||
|
||||
<p>
|
||||
<dt>
|
||||
<strong><tt>__setstate__</tt></strong>
|
||||
<h2>Examples</h2>There are three files in <tt>boost/libs/python/test</tt>
|
||||
that show how to provide pickle support.
|
||||
<hr />
|
||||
|
||||
<dd>
|
||||
When an instance of a Boost.Python extension class is restored by the
|
||||
unpickler (<tt>pickle.load</tt>), it is first constructed using the
|
||||
result of <tt>__getinitargs__</tt> as arguments (see above). Subsequently
|
||||
the unpickler tests if the new instance has a <tt>__setstate__</tt>
|
||||
method. If so, this method is called with the result of
|
||||
<tt>__getstate__</tt> (a Python object) as the argument.
|
||||
<h3><a href="../../test/pickle1.cpp"><tt>pickle1.cpp</tt></a></h3>The C++
|
||||
class in this example can be fully restored by passing the appropriate
|
||||
argument to the constructor. Therefore it is sufficient to define the
|
||||
pickle interface method <tt>__getinitargs__</tt>. This is done in the
|
||||
following way:
|
||||
|
||||
</dl>
|
||||
|
||||
The three special methods described above may be <tt>.def()</tt>'ed
|
||||
individually by the user. However, Boost.Python provides an easy to use
|
||||
high-level interface via the
|
||||
<strong><tt>boost::python::pickle_suite</tt></strong> class that also
|
||||
enforces consistency: <tt>__getstate__</tt> and <tt>__setstate__</tt>
|
||||
must be defined as pairs. Use of this interface is demonstrated by the
|
||||
following examples.
|
||||
|
||||
<hr>
|
||||
<h2>Examples</h2>
|
||||
|
||||
There are three files in
|
||||
<tt>boost/libs/python/test</tt> that show how to
|
||||
provide pickle support.
|
||||
|
||||
<hr>
|
||||
<h3><a href="../../test/pickle1.cpp"><tt>pickle1.cpp</tt></a></h3>
|
||||
|
||||
The C++ class in this example can be fully restored by passing the
|
||||
appropriate argument to the constructor. Therefore it is sufficient
|
||||
to define the pickle interface method <tt>__getinitargs__</tt>.
|
||||
This is done in the following way:
|
||||
|
||||
<ul>
|
||||
<li>1. Definition of the C++ pickle function:
|
||||
<pre>
|
||||
<ul>
|
||||
<li>1. Definition of the C++ pickle function:
|
||||
<pre>
|
||||
struct world_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static
|
||||
@@ -117,26 +98,28 @@ provide pickle support.
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
<li>2. Establishing the Python binding:
|
||||
<pre>
|
||||
</li>
|
||||
|
||||
<li>2. Establishing the Python binding:
|
||||
<pre>
|
||||
class_<world>("world", args<const std::string&>())
|
||||
// ...
|
||||
.def_pickle(world_pickle_suite())
|
||||
// ...
|
||||
</pre>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<hr />
|
||||
|
||||
<hr>
|
||||
<h3><a href="../../test/pickle2.cpp"><tt>pickle2.cpp</tt></a></h3>
|
||||
<h3><a href="../../test/pickle2.cpp"><tt>pickle2.cpp</tt></a></h3>The C++
|
||||
class in this example contains member data that cannot be restored by any
|
||||
of the constructors. Therefore it is necessary to provide the
|
||||
<tt>__getstate__</tt>/<tt>__setstate__</tt> pair of pickle interface
|
||||
methods:
|
||||
|
||||
The C++ class in this example contains member data that cannot be
|
||||
restored by any of the constructors. Therefore it is necessary to
|
||||
provide the <tt>__getstate__</tt>/<tt>__setstate__</tt> pair of
|
||||
pickle interface methods:
|
||||
|
||||
<ul>
|
||||
<li>1. Definition of the C++ pickle functions:
|
||||
<pre>
|
||||
<ul>
|
||||
<li>1. Definition of the C++ pickle functions:
|
||||
<pre>
|
||||
struct world_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
static
|
||||
@@ -161,92 +144,76 @@ provide pickle support.
|
||||
}
|
||||
};
|
||||
</pre>
|
||||
<li>2. Establishing the Python bindings for the entire suite:
|
||||
<pre>
|
||||
</li>
|
||||
|
||||
<li>2. Establishing the Python bindings for the entire suite:
|
||||
<pre>
|
||||
class_<world>("world", args<const std::string&>())
|
||||
// ...
|
||||
.def_pickle(world_pickle_suite())
|
||||
// ...
|
||||
</pre>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
For simplicity, the <tt>__dict__</tt> is not included in the result
|
||||
of <tt>__getstate__</tt>. This is not generally recommended, but a
|
||||
valid approach if it is anticipated that the object's
|
||||
<tt>__dict__</tt> will always be empty. Note that the safety guard
|
||||
described below will catch the cases where this assumption is violated.
|
||||
<p>For simplicity, the <tt>__dict__</tt> is not included in the result of
|
||||
<tt>__getstate__</tt>. This is not generally recommended, but a valid
|
||||
approach if it is anticipated that the object's <tt>__dict__</tt> will
|
||||
always be empty. Note that the safety guard described below will catch
|
||||
the cases where this assumption is violated.</p>
|
||||
<hr />
|
||||
|
||||
<hr>
|
||||
<h3><a href="../../test/pickle3.cpp"><tt>pickle3.cpp</tt></a></h3>
|
||||
<h3><a href="../../test/pickle3.cpp"><tt>pickle3.cpp</tt></a></h3>This
|
||||
example is similar to <a href=
|
||||
"../../test/pickle2.cpp"><tt>pickle2.cpp</tt></a>. However, the object's
|
||||
<tt>__dict__</tt> is included in the result of <tt>__getstate__</tt>.
|
||||
This requires a little more code but is unavoidable if the object's
|
||||
<tt>__dict__</tt> is not always empty.
|
||||
<hr />
|
||||
|
||||
This example is similar to <a
|
||||
href="../../test/pickle2.cpp"><tt>pickle2.cpp</tt></a>. However, the
|
||||
object's <tt>__dict__</tt> is included in the result of
|
||||
<tt>__getstate__</tt>. This requires a little more code but is
|
||||
unavoidable if the object's <tt>__dict__</tt> is not always empty.
|
||||
<h2>Pitfall and Safety Guard</h2>The pickle protocol described above has
|
||||
an important pitfall that the end user of a Boost.Python extension module
|
||||
might not be aware of:
|
||||
|
||||
<hr>
|
||||
<h2>Pitfall and Safety Guard</h2>
|
||||
<p><strong><tt>__getstate__</tt> is defined and the instance's
|
||||
<tt>__dict__</tt> is not empty.</strong></p>
|
||||
|
||||
The pickle protocol described above has an important pitfall that the
|
||||
end user of a Boost.Python extension module might not be aware of:
|
||||
<p>
|
||||
<strong>
|
||||
<tt>__getstate__</tt> is defined and the instance's <tt>__dict__</tt>
|
||||
is not empty.
|
||||
</strong>
|
||||
<p>
|
||||
<p>The author of a Boost.Python extension class might provide a
|
||||
<tt>__getstate__</tt> method without considering the possibilities
|
||||
that:</p>
|
||||
|
||||
The author of a Boost.Python extension class might provide a
|
||||
<tt>__getstate__</tt> method without considering the possibilities
|
||||
that:
|
||||
<ul>
|
||||
<li>his class is used in Python as a base class. Most likely the
|
||||
<tt>__dict__</tt> of instances of the derived class needs to be pickled
|
||||
in order to restore the instances correctly.</li>
|
||||
|
||||
<p>
|
||||
<ul>
|
||||
<li>
|
||||
his class is used in Python as a base class. Most likely the
|
||||
<tt>__dict__</tt> of instances of the derived class needs to be
|
||||
pickled in order to restore the instances correctly.
|
||||
<li>the user adds items to the instance's <tt>__dict__</tt> directly.
|
||||
Again, the <tt>__dict__</tt> of the instance then needs to be
|
||||
pickled.</li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<li>
|
||||
the user adds items to the instance's <tt>__dict__</tt> directly.
|
||||
Again, the <tt>__dict__</tt> of the instance then needs to be
|
||||
pickled.
|
||||
|
||||
</ul>
|
||||
<p>
|
||||
|
||||
To alert the user to this highly unobvious problem, a safety guard is
|
||||
provided. If <tt>__getstate__</tt> is defined and the instance's
|
||||
<tt>__dict__</tt> is not empty, Boost.Python tests if the class has
|
||||
an attribute <tt>__getstate_manages_dict__</tt>. An exception is
|
||||
raised if this attribute is not defined:
|
||||
|
||||
<pre>
|
||||
<p>To alert the user to this highly unobvious problem, a safety guard is
|
||||
provided. If <tt>__getstate__</tt> is defined and the instance's
|
||||
<tt>__dict__</tt> is not empty, Boost.Python tests if the class has an
|
||||
attribute <tt>__getstate_manages_dict__</tt>. An exception is raised if
|
||||
this attribute is not defined:</p>
|
||||
<pre>
|
||||
RuntimeError: Incomplete pickle support (__getstate_manages_dict__ not set)
|
||||
</pre>
|
||||
|
||||
To resolve this problem, it should first be established that the
|
||||
<tt>__getstate__</tt> and <tt>__setstate__</tt> methods manage the
|
||||
instances's <tt>__dict__</tt> correctly. Note that this can be done
|
||||
either at the C++ or the Python level. Finally, the safety guard
|
||||
should intentionally be overridden. E.g. in C++ (from
|
||||
<a href="../../test/pickle3.cpp"><tt>pickle3.cpp</tt></a>):
|
||||
|
||||
<pre>
|
||||
</pre>To resolve this problem, it should first be established that the <tt>
|
||||
__getstate__</tt> and <tt>__setstate__</tt> methods manage the
|
||||
instances's <tt>__dict__</tt> correctly. Note that this can be done
|
||||
either at the C++ or the Python level. Finally, the safety guard should
|
||||
intentionally be overridden. E.g. in C++ (from <a href=
|
||||
"../../test/pickle3.cpp"><tt>pickle3.cpp</tt></a>):
|
||||
<pre>
|
||||
struct world_pickle_suite : boost::python::pickle_suite
|
||||
{
|
||||
// ...
|
||||
|
||||
static bool getstate_manages_dict() { return true; }
|
||||
};
|
||||
</pre>
|
||||
|
||||
Alternatively in Python:
|
||||
|
||||
<pre>
|
||||
</pre>Alternatively in Python:
|
||||
<pre>
|
||||
import your_bpl_module
|
||||
class your_class(your_bpl_module.your_class):
|
||||
__getstate_manages_dict__ = 1
|
||||
@@ -255,54 +222,41 @@ is not empty.
|
||||
def __setstate__(self, state):
|
||||
# your code here
|
||||
</pre>
|
||||
<hr />
|
||||
|
||||
<hr>
|
||||
<h2>Practical Advice</h2>
|
||||
<h2>Practical Advice</h2>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
In Boost.Python extension modules with many extension classes,
|
||||
providing complete pickle support for all classes would be a
|
||||
significant overhead. In general complete pickle support should
|
||||
only be implemented for extension classes that will eventually
|
||||
be pickled.
|
||||
<ul>
|
||||
<li>In Boost.Python extension modules with many extension classes,
|
||||
providing complete pickle support for all classes would be a
|
||||
significant overhead. In general complete pickle support should only be
|
||||
implemented for extension classes that will eventually be pickled.</li>
|
||||
|
||||
<p>
|
||||
<li>
|
||||
Avoid using <tt>__getstate__</tt> if the instance can also be
|
||||
reconstructed by way of <tt>__getinitargs__</tt>. This automatically
|
||||
avoids the pitfall described above.
|
||||
<li>Avoid using <tt>__getstate__</tt> if the instance can also be
|
||||
reconstructed by way of <tt>__getinitargs__</tt>. This automatically
|
||||
avoids the pitfall described above.</li>
|
||||
|
||||
<p>
|
||||
<li>
|
||||
If <tt>__getstate__</tt> is required, include the instance's
|
||||
<tt>__dict__</tt> in the Python object that is returned.
|
||||
<li>If <tt>__getstate__</tt> is required, include the instance's
|
||||
<tt>__dict__</tt> in the Python object that is returned.</li>
|
||||
</ul>
|
||||
<hr />
|
||||
|
||||
</ul>
|
||||
<h2>Light-weight alternative: pickle support implemented in Python</h2>
|
||||
|
||||
<hr>
|
||||
<h2>Light-weight alternative: pickle support implemented in Python</h2>
|
||||
|
||||
<h3><a href="../../test/pickle4.cpp"><tt>pickle4.cpp</tt></a></h3>
|
||||
|
||||
The <tt>pickle4.cpp</tt> example demonstrates an alternative technique
|
||||
for implementing pickle support. First we direct Boost.Python via
|
||||
the <tt>class_::enable_pickling()</tt> member function to define only
|
||||
the basic attributes required for pickling:
|
||||
|
||||
<pre>
|
||||
<h3><a href="../../test/pickle4.cpp"><tt>pickle4.cpp</tt></a></h3>The
|
||||
<tt>pickle4.cpp</tt> example demonstrates an alternative technique for
|
||||
implementing pickle support. First we direct Boost.Python via the
|
||||
<tt>class_::enable_pickling()</tt> member function to define only the
|
||||
basic attributes required for pickling:
|
||||
<pre>
|
||||
class_<world>("world", args<const std::string&>())
|
||||
// ...
|
||||
.enable_pickling()
|
||||
// ...
|
||||
</pre>
|
||||
|
||||
This enables the standard Python pickle interface as described
|
||||
in the Python documentation. By "injecting" a
|
||||
<tt>__getinitargs__</tt> method into the definition of the wrapped
|
||||
class we make all instances pickleable:
|
||||
|
||||
<pre>
|
||||
</pre>This enables the standard Python pickle interface as described in the
|
||||
Python documentation. By "injecting" a <tt>__getinitargs__</tt> method into
|
||||
the definition of the wrapped class we make all instances pickleable:
|
||||
<pre>
|
||||
# import the wrapped world class
|
||||
from pickle4_ext import world
|
||||
|
||||
@@ -312,18 +266,15 @@ class we make all instances pickleable:
|
||||
|
||||
# now inject __getinitargs__ (Python is a dynamic language!)
|
||||
world.__getinitargs__ = world_getinitargs
|
||||
</pre>
|
||||
</pre>See also the <a href=
|
||||
"../tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python">
|
||||
tutorial section</a> on injecting additional methods from Python.
|
||||
<hr />
|
||||
© Copyright Ralf W. Grosse-Kunstleve 2001-2004. Distributed under the
|
||||
Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
See also the
|
||||
<a href="../tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python"
|
||||
>tutorial section</a> on injecting additional methods from Python.
|
||||
|
||||
<hr>
|
||||
|
||||
© Copyright Ralf W. Grosse-Kunstleve 2001-2004. Distributed under
|
||||
the Boost Software License, Version 1.0. (See accompanying file
|
||||
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
<p>
|
||||
Updated: Feb 2004.
|
||||
</div>
|
||||
<p>Updated: Feb 2004.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -117,9 +117,9 @@ struct rvalue_from_python_data : rvalue_from_python_storage<T>
|
||||
// Implementataions
|
||||
//
|
||||
template <class T>
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(rvalue_from_python_stage1_data const& stage1)
|
||||
inline rvalue_from_python_data<T>::rvalue_from_python_data(rvalue_from_python_stage1_data const& _stage1)
|
||||
{
|
||||
this->stage1 = stage1;
|
||||
this->stage1 = _stage1;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -265,7 +265,8 @@ inline object make_getter(D const& d, Policies const& policies)
|
||||
template <class D>
|
||||
inline object make_getter(D& x)
|
||||
{
|
||||
detail::not_specified policy;
|
||||
detail::not_specified policy
|
||||
= detail::not_specified(); // suppress a SunPro warning
|
||||
return detail::make_getter(x, policy, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
|
||||
@@ -273,7 +274,8 @@ inline object make_getter(D& x)
|
||||
template <class D>
|
||||
inline object make_getter(D const& d)
|
||||
{
|
||||
detail::not_specified policy;
|
||||
detail::not_specified policy
|
||||
= detail::not_specified(); // Suppress a SunPro warning
|
||||
return detail::make_getter(d, policy, is_member_pointer<D>(), 0L);
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -14,6 +14,16 @@
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
|
||||
# if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) /*
|
||||
> warning C4180: qualifier applied to function type has no meaning; ignored
|
||||
Peter Dimov wrote:
|
||||
This warning is caused by an overload resolution bug in VC8 that cannot be
|
||||
worked around and will probably not be fixed by MS in the VC8 line. The
|
||||
problematic overload is only instantiated and never called, and the code
|
||||
works correctly. */
|
||||
# pragma warning(disable: 4180)
|
||||
# endif
|
||||
|
||||
# include <boost/bind.hpp>
|
||||
# include <boost/bind/protect.hpp>
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ struct class_metadata
|
||||
//
|
||||
// Support for converting smart pointers to python
|
||||
//
|
||||
inline static void maybe_register_pointer_to_python(void*,void*,void*) {}
|
||||
inline static void maybe_register_pointer_to_python(...) {}
|
||||
|
||||
#ifndef BOOST_PYTHON_NO_PY_SYGNATURES
|
||||
inline static void maybe_register_pointer_to_python(void*,void*,mpl::true_*)
|
||||
|
||||
@@ -127,7 +127,14 @@ void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
|
||||
)
|
||||
return &this->m_p;
|
||||
|
||||
Value* p = get_pointer(this->m_p);
|
||||
Value* p
|
||||
# if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
|
||||
= static_cast<Value*>( get_pointer(this->m_p) )
|
||||
# else
|
||||
= get_pointer(this->m_p)
|
||||
# endif
|
||||
;
|
||||
|
||||
if (p == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ struct const_attribute_policies
|
||||
{
|
||||
typedef char const* key_type;
|
||||
static object get(object const& target, char const* key);
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
|
||||
struct attribute_policies : const_attribute_policies
|
||||
@@ -25,6 +26,18 @@ struct attribute_policies : const_attribute_policies
|
||||
static void del(object const&target, char const* key);
|
||||
};
|
||||
|
||||
struct const_objattribute_policies
|
||||
{
|
||||
typedef object const key_type;
|
||||
static object get(object const& target, object const& key);
|
||||
};
|
||||
|
||||
struct objattribute_policies : const_objattribute_policies
|
||||
{
|
||||
static object const& set(object const& target, object const& key, object const& value);
|
||||
static void del(object const&target, object const& key);
|
||||
};
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
@@ -42,11 +55,30 @@ inline const_object_attribute object_operators<U>::attr(char const* name) const
|
||||
return const_object_attribute(x, name);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline object_objattribute object_operators<U>::attr(object const& name)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_objattribute(x, name);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
inline const_object_objattribute object_operators<U>::attr(object const& name) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_objattribute(x, name);
|
||||
}
|
||||
|
||||
inline object const_attribute_policies::get(object const& target, char const* key)
|
||||
{
|
||||
return python::getattr(target, key);
|
||||
}
|
||||
|
||||
inline object const_objattribute_policies::get(object const& target, object const& key)
|
||||
{
|
||||
return python::getattr(target, key);
|
||||
}
|
||||
|
||||
inline object const& attribute_policies::set(
|
||||
object const& target
|
||||
, char const* key
|
||||
@@ -56,6 +88,15 @@ inline object const& attribute_policies::set(
|
||||
return value;
|
||||
}
|
||||
|
||||
inline object const& objattribute_policies::set(
|
||||
object const& target
|
||||
, object const& key
|
||||
, object const& value)
|
||||
{
|
||||
python::setattr(target, key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline void attribute_policies::del(
|
||||
object const& target
|
||||
, char const* key)
|
||||
@@ -63,6 +104,13 @@ inline void attribute_policies::del(
|
||||
python::delattr(target, key);
|
||||
}
|
||||
|
||||
inline void objattribute_policies::del(
|
||||
object const& target
|
||||
, object const& key)
|
||||
{
|
||||
python::delattr(target, key);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::api
|
||||
|
||||
#endif // OBJECT_ATTRIBUTES_DWA2002615_HPP
|
||||
|
||||
@@ -42,6 +42,12 @@
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class kwds_proxy;
|
||||
class args_proxy;
|
||||
}
|
||||
|
||||
namespace converter
|
||||
{
|
||||
template <class T> struct arg_to_python;
|
||||
@@ -59,6 +65,8 @@ namespace api
|
||||
|
||||
struct const_attribute_policies;
|
||||
struct attribute_policies;
|
||||
struct const_objattribute_policies;
|
||||
struct objattribute_policies;
|
||||
struct const_item_policies;
|
||||
struct item_policies;
|
||||
struct const_slice_policies;
|
||||
@@ -67,6 +75,8 @@ namespace api
|
||||
|
||||
typedef proxy<const_attribute_policies> const_object_attribute;
|
||||
typedef proxy<attribute_policies> object_attribute;
|
||||
typedef proxy<const_objattribute_policies> const_object_objattribute;
|
||||
typedef proxy<objattribute_policies> object_objattribute;
|
||||
typedef proxy<const_item_policies> const_object_item;
|
||||
typedef proxy<item_policies> object_item;
|
||||
typedef proxy<const_slice_policies> const_object_slice;
|
||||
@@ -98,6 +108,11 @@ namespace api
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/object_call.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
detail::args_proxy operator* () const;
|
||||
object operator()(detail::args_proxy const &args) const;
|
||||
object operator()(detail::args_proxy const &args,
|
||||
detail::kwds_proxy const &kwds) const;
|
||||
|
||||
// truth value testing
|
||||
//
|
||||
@@ -108,6 +123,8 @@ namespace api
|
||||
//
|
||||
const_object_attribute attr(char const*) const;
|
||||
object_attribute attr(char const*);
|
||||
const_object_objattribute attr(object const&) const;
|
||||
object_objattribute attr(object const&);
|
||||
|
||||
// item access
|
||||
//
|
||||
@@ -213,11 +230,11 @@ namespace api
|
||||
inline object_base(object_base const&);
|
||||
inline object_base(PyObject* ptr);
|
||||
|
||||
object_base& operator=(object_base const& rhs);
|
||||
~object_base();
|
||||
inline object_base& operator=(object_base const& rhs);
|
||||
inline ~object_base();
|
||||
|
||||
// Underlying object access -- returns a borrowed reference
|
||||
PyObject* ptr() const;
|
||||
inline PyObject* ptr() const;
|
||||
|
||||
private:
|
||||
PyObject* m_ptr;
|
||||
@@ -387,7 +404,7 @@ namespace api
|
||||
static PyObject*
|
||||
get(T const& x, U)
|
||||
{
|
||||
return python::incref(get_managed_object(x, tag));
|
||||
return python::incref(get_managed_object(x, boost::python::tag));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -410,6 +427,62 @@ template <class T> struct extract;
|
||||
// implementation
|
||||
//
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class call_proxy
|
||||
{
|
||||
public:
|
||||
call_proxy(object target) : m_target(target) {}
|
||||
operator object() const { return m_target;}
|
||||
|
||||
private:
|
||||
object m_target;
|
||||
};
|
||||
|
||||
class kwds_proxy : public call_proxy
|
||||
{
|
||||
public:
|
||||
kwds_proxy(object o = object()) : call_proxy(o) {}
|
||||
};
|
||||
class args_proxy : public call_proxy
|
||||
{
|
||||
public:
|
||||
args_proxy(object o) : call_proxy(o) {}
|
||||
kwds_proxy operator* () const { return kwds_proxy(*this);}
|
||||
};
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
detail::args_proxy api::object_operators<U>::operator* () const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return boost::python::detail::args_proxy(x);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
object api::object_operators<U>::operator()(detail::args_proxy const &args) const
|
||||
{
|
||||
U const& self = *static_cast<U const*>(this);
|
||||
PyObject *result = PyObject_Call(get_managed_object(self, boost::python::tag),
|
||||
args.operator object().ptr(),
|
||||
0);
|
||||
return object(boost::python::detail::new_reference(result));
|
||||
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
object api::object_operators<U>::operator()(detail::args_proxy const &args,
|
||||
detail::kwds_proxy const &kwds) const
|
||||
{
|
||||
U const& self = *static_cast<U const*>(this);
|
||||
PyObject *result = PyObject_Call(get_managed_object(self, boost::python::tag),
|
||||
args.operator object().ptr(),
|
||||
kwds.operator object().ptr());
|
||||
return object(boost::python::detail::new_reference(result));
|
||||
|
||||
}
|
||||
|
||||
inline object::object()
|
||||
: object_base(python::incref(Py_None))
|
||||
{}
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
# include <boost/python/object_protocol_core.hpp>
|
||||
# include <boost/python/object_core.hpp>
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace api {
|
||||
|
||||
# if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
|
||||
# if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
|
||||
// attempt to use SFINAE to prevent functions accepting T const& from
|
||||
// coming up as ambiguous with the one taking a char const* when a
|
||||
// string literal is passed
|
||||
@@ -22,45 +24,45 @@ namespace boost { namespace python { namespace api {
|
||||
# endif
|
||||
|
||||
template <class Target, class Key>
|
||||
object getattr(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
object getattr(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
return getattr(object(target), object(key));
|
||||
}
|
||||
|
||||
template <class Target, class Key, class Default>
|
||||
object getattr(Target const& target, Key const& key, Default const& default_ BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
object getattr(Target const& target, Key const& key, Default const& default_ BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
return getattr(object(target), object(key), object(default_));
|
||||
}
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
void setattr(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
void setattr(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
setattr(target, object(key), object(value));
|
||||
}
|
||||
|
||||
template <class Key>
|
||||
void delattr(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
void delattr(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
delattr(target, object(key));
|
||||
}
|
||||
|
||||
template <class Target, class Key>
|
||||
object getitem(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
object getitem(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
return getitem(object(target), object(key));
|
||||
}
|
||||
|
||||
|
||||
template <class Key, class Value>
|
||||
void setitem(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
void setitem(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
setitem(target, object(key), object(value));
|
||||
}
|
||||
|
||||
template <class Key>
|
||||
void delitem(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(key))
|
||||
void delitem(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
|
||||
{
|
||||
delitem(target, object(key));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,12 @@ struct slice_policies : const_slice_policies
|
||||
static void del(object const& target, key_type const& key);
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
inline slice_policies::key_type slice_key(T x, U y)
|
||||
{
|
||||
return slice_policies::key_type(handle<>(x), handle<>(y));
|
||||
}
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
@@ -35,7 +41,7 @@ object_slice
|
||||
object_operators<U>::slice(object_cref start, object_cref finish)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
|
||||
return object_slice(x, api::slice_key(borrowed(start.ptr()), borrowed(finish.ptr())));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -43,7 +49,7 @@ const_object_slice
|
||||
object_operators<U>::slice(object_cref start, object_cref finish) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
|
||||
return const_object_slice(x, api::slice_key(borrowed(start.ptr()), borrowed(finish.ptr())));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -51,7 +57,7 @@ object_slice
|
||||
object_operators<U>::slice(slice_nil, object_cref finish)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
||||
return object_slice(x, api::slice_key(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -59,7 +65,7 @@ const_object_slice
|
||||
object_operators<U>::slice(slice_nil, object_cref finish) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
||||
return const_object_slice(x, api::slice_key(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -67,7 +73,7 @@ object_slice
|
||||
object_operators<U>::slice(slice_nil, slice_nil)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
return object_slice(x, api::slice_key(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -75,7 +81,7 @@ const_object_slice
|
||||
object_operators<U>::slice(slice_nil, slice_nil) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
return const_object_slice(x, api::slice_key(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -83,7 +89,7 @@ object_slice
|
||||
object_operators<U>::slice(object_cref start, slice_nil)
|
||||
{
|
||||
object_cref2 x = *static_cast<U*>(this);
|
||||
return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
||||
return object_slice(x, api::slice_key(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -91,7 +97,7 @@ const_object_slice
|
||||
object_operators<U>::slice(object_cref start, slice_nil) const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
||||
return const_object_slice(x, api::slice_key(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
||||
}
|
||||
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
template <class U>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Based on boost/ref.hpp, thus:
|
||||
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
||||
// Copyright (C) 2001 Peter Dimov
|
||||
|
||||
# if _MSC_VER+0 >= 1020
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
#ifndef PY_CONTAINER_UTILS_JDG20038_HPP
|
||||
# define PY_CONTAINER_UTILS_JDG20038_HPP
|
||||
|
||||
# include <utility>
|
||||
# include <boost/foreach.hpp>
|
||||
# include <boost/python/object.hpp>
|
||||
# include <boost/python/handle.hpp>
|
||||
# include <boost/python/extract.hpp>
|
||||
# include <boost/python/stl_iterator.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace container_utils {
|
||||
|
||||
@@ -19,11 +22,13 @@ namespace boost { namespace python { namespace container_utils {
|
||||
{
|
||||
typedef typename Container::value_type data_type;
|
||||
|
||||
// l must be a list or some container
|
||||
|
||||
for (int i = 0; i < l.attr("__len__")(); i++)
|
||||
// l must be iterable
|
||||
BOOST_FOREACH(object elem,
|
||||
std::make_pair(
|
||||
boost::python::stl_input_iterator<object>(l),
|
||||
boost::python::stl_input_iterator<object>()
|
||||
))
|
||||
{
|
||||
object elem(l[i]);
|
||||
extract<data_type const&> x(elem);
|
||||
// try if elem is an exact data_type type
|
||||
if (x.check())
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# include <boost/operators.hpp>
|
||||
# include <typeinfo>
|
||||
# include <cstring>
|
||||
# include <ostream>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
@@ -68,8 +68,9 @@ struct with_custodian_and_ward : BasePolicy_
|
||||
|
||||
bool result = BasePolicy_::precall(args_);
|
||||
|
||||
if (!result)
|
||||
if (!result) {
|
||||
Py_DECREF(life_support);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace
|
||||
detail::new_reference dict_base::call(object const& arg_)
|
||||
{
|
||||
return (detail::new_reference)PyObject_CallFunction(
|
||||
(PyObject*)&PyDict_Type, "(O)",
|
||||
(PyObject*)&PyDict_Type, const_cast<char*>("(O)"),
|
||||
arg_.ptr());
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ BOOST_PYTHON_DECL bool handle_exception_impl(function0<void> f)
|
||||
{
|
||||
PyErr_SetString(PyExc_IndexError, x.what());
|
||||
}
|
||||
catch(const std::invalid_argument& x)
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, x.what());
|
||||
}
|
||||
catch(const std::exception& x)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, x.what());
|
||||
|
||||
@@ -39,7 +39,7 @@ object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
|
||||
// should be 'char const *' but older python versions don't use 'const' yet.
|
||||
char *f = python::extract<char *>(filename);
|
||||
// Let python open the file to avoid potential binary incompatibilities.
|
||||
PyObject *pyfile = PyFile_FromString(f, "r");
|
||||
PyObject *pyfile = PyFile_FromString(f, const_cast<char*>("r"));
|
||||
if (!pyfile) throw std::invalid_argument(std::string(f) + " : no such file");
|
||||
python::handle<> file(pyfile);
|
||||
PyObject* result = PyRun_File(PyFile_AsFile(file.get()),
|
||||
|
||||
@@ -13,7 +13,7 @@ detail::new_non_null_reference list_base::call(object const& arg_)
|
||||
return (detail::new_non_null_reference)
|
||||
(expect_non_null)(
|
||||
PyObject_CallFunction(
|
||||
(PyObject*)&PyList_Type, "(O)",
|
||||
(PyObject*)&PyList_Type, const_cast<char*>("(O)"),
|
||||
arg_.ptr()));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,21 +9,21 @@ namespace boost { namespace python { namespace detail {
|
||||
new_non_null_reference long_base::call(object const& arg_)
|
||||
{
|
||||
return (detail::new_non_null_reference)PyObject_CallFunction(
|
||||
(PyObject*)&PyLong_Type, "(O)",
|
||||
(PyObject*)&PyLong_Type, const_cast<char*>("(O)"),
|
||||
arg_.ptr());
|
||||
}
|
||||
|
||||
new_non_null_reference long_base::call(object const& arg_, object const& base)
|
||||
{
|
||||
return (detail::new_non_null_reference)PyObject_CallFunction(
|
||||
(PyObject*)&PyLong_Type, "(OO)",
|
||||
(PyObject*)&PyLong_Type, const_cast<char*>("(OO)"),
|
||||
arg_.ptr(), base.ptr());
|
||||
}
|
||||
|
||||
long_base::long_base()
|
||||
: object(
|
||||
detail::new_reference(
|
||||
PyObject_CallFunction((PyObject*)&PyLong_Type, "()"))
|
||||
PyObject_CallFunction((PyObject*)&PyLong_Type, const_cast<char*>("()")))
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ extern "C"
|
||||
{
|
||||
propertyobject *gs = (propertyobject *)self;
|
||||
|
||||
return PyObject_CallFunction(gs->prop_get, "()");
|
||||
return PyObject_CallFunction(gs->prop_get, const_cast<char*>("()"));
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -95,9 +95,9 @@ extern "C"
|
||||
return -1;
|
||||
}
|
||||
if (value == NULL)
|
||||
res = PyObject_CallFunction(func, "()");
|
||||
res = PyObject_CallFunction(func, const_cast<char*>("()"));
|
||||
else
|
||||
res = PyObject_CallFunction(func, "(O)", value);
|
||||
res = PyObject_CallFunction(func, const_cast<char*>("(O)"), value);
|
||||
if (res == NULL)
|
||||
return -1;
|
||||
Py_DECREF(res);
|
||||
@@ -108,7 +108,7 @@ extern "C"
|
||||
static PyTypeObject static_data_object = {
|
||||
PyObject_HEAD_INIT(0)//&PyType_Type)
|
||||
0,
|
||||
"Boost.Python.StaticProperty",
|
||||
const_cast<char*>("Boost.Python.StaticProperty"),
|
||||
PyType_Type.tp_basicsize,
|
||||
0,
|
||||
0, /* tp_dealloc */
|
||||
@@ -212,7 +212,7 @@ extern "C"
|
||||
static PyTypeObject class_metatype_object = {
|
||||
PyObject_HEAD_INIT(0)//&PyType_Type)
|
||||
0,
|
||||
"Boost.Python.class",
|
||||
const_cast<char*>("Boost.Python.class"),
|
||||
PyType_Type.tp_basicsize,
|
||||
0,
|
||||
0, /* tp_dealloc */
|
||||
@@ -316,7 +316,7 @@ namespace objects
|
||||
{
|
||||
// Attempt to find the __instance_size__ attribute. If not present, no problem.
|
||||
PyObject* d = type_->tp_dict;
|
||||
PyObject* instance_size_obj = PyObject_GetAttrString(d, "__instance_size__");
|
||||
PyObject* instance_size_obj = PyObject_GetAttrString(d, const_cast<char*>("__instance_size__"));
|
||||
|
||||
long instance_size = instance_size_obj ? PyInt_AsLong(instance_size_obj) : 0;
|
||||
|
||||
@@ -357,20 +357,20 @@ namespace objects
|
||||
|
||||
|
||||
static PyGetSetDef instance_getsets[] = {
|
||||
{"__dict__", instance_get_dict, instance_set_dict, NULL, 0},
|
||||
{const_cast<char*>("__dict__"), instance_get_dict, instance_set_dict, NULL, 0},
|
||||
{0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
static PyMemberDef instance_members[] = {
|
||||
{"__weakref__", T_OBJECT, offsetof(instance<>, weakrefs), 0, 0},
|
||||
{const_cast<char*>("__weakref__"), T_OBJECT, offsetof(instance<>, weakrefs), 0, 0},
|
||||
{0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static PyTypeObject class_type_object = {
|
||||
PyObject_HEAD_INIT(0) //&class_metatype_object)
|
||||
0,
|
||||
"Boost.Python.instance",
|
||||
const_cast<char*>("Boost.Python.instance"),
|
||||
offsetof(instance<>,storage), /* tp_basicsize */
|
||||
1, /* tp_itemsize */
|
||||
instance_dealloc, /* tp_dealloc */
|
||||
@@ -572,7 +572,7 @@ namespace objects
|
||||
{
|
||||
object property(
|
||||
(python::detail::new_reference)
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, "Osss", fget.ptr(), 0, 0, docstr));
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, const_cast<char*>("Osss"), fget.ptr(), 0, 0, docstr));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
@@ -582,7 +582,7 @@ namespace objects
|
||||
{
|
||||
object property(
|
||||
(python::detail::new_reference)
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, "OOss", fget.ptr(), fset.ptr(), 0, docstr));
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, const_cast<char*>("OOss"), fget.ptr(), fset.ptr(), 0, docstr));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
@@ -591,7 +591,7 @@ namespace objects
|
||||
{
|
||||
object property(
|
||||
(python::detail::new_reference)
|
||||
PyObject_CallFunction(static_data(), "O", fget.ptr()));
|
||||
PyObject_CallFunction(static_data(), const_cast<char*>("O"), fget.ptr()));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
@@ -600,7 +600,7 @@ namespace objects
|
||||
{
|
||||
object property(
|
||||
(python::detail::new_reference)
|
||||
PyObject_CallFunction(static_data(), "OO", fget.ptr(), fset.ptr()));
|
||||
PyObject_CallFunction(static_data(), const_cast<char*>("OO"), fget.ptr(), fset.ptr()));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
@@ -615,13 +615,13 @@ namespace objects
|
||||
{
|
||||
extern "C" PyObject* no_init(PyObject*, PyObject*)
|
||||
{
|
||||
::PyErr_SetString(::PyExc_RuntimeError, "This class cannot be instantiated from Python");
|
||||
::PyErr_SetString(::PyExc_RuntimeError, const_cast<char*>("This class cannot be instantiated from Python"));
|
||||
return NULL;
|
||||
}
|
||||
static ::PyMethodDef no_init_def = {
|
||||
"__init__", no_init, METH_VARARGS,
|
||||
"Raises an exception\n"
|
||||
"This class cannot be instantiated from Python\n"
|
||||
const_cast<char*>("__init__"), no_init, METH_VARARGS,
|
||||
const_cast<char*>("Raises an exception\n"
|
||||
"This class cannot be instantiated from Python\n")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ namespace objects
|
||||
|
||||
::PyErr_Format(
|
||||
PyExc_TypeError
|
||||
, "staticmethod expects callable object; got an object of type %s, which is not callable"
|
||||
, const_cast<char*>("staticmethod expects callable object; got an object of type %s, which is not callable")
|
||||
, callable->ob_type->tp_name
|
||||
);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ struct enum_object
|
||||
};
|
||||
|
||||
static PyMemberDef enum_members[] = {
|
||||
{"name", T_OBJECT_EX, offsetof(enum_object,name),READONLY, 0},
|
||||
{const_cast<char*>("name"), T_OBJECT_EX, offsetof(enum_object,name),READONLY, 0},
|
||||
{0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ extern "C"
|
||||
{
|
||||
static PyObject* enum_repr(PyObject* self_)
|
||||
{
|
||||
const char *mod = PyString_AsString(PyObject_GetAttrString( self_, "__module__"));
|
||||
const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast<char*>("__module__")));
|
||||
enum_object* self = downcast<enum_object>(self_);
|
||||
if (!self->name)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ extern "C"
|
||||
static PyTypeObject enum_type_object = {
|
||||
PyObject_HEAD_INIT(0) // &PyType_Type
|
||||
0,
|
||||
"Boost.Python.enum",
|
||||
const_cast<char*>("Boost.Python.enum"),
|
||||
sizeof(enum_object), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
0, /* tp_dealloc */
|
||||
|
||||
@@ -297,7 +297,7 @@ object function::signatures(bool show_return_type) const
|
||||
void function::argument_error(PyObject* args, PyObject* /*keywords*/) const
|
||||
{
|
||||
static handle<> exception(
|
||||
PyErr_NewException("Boost.Python.ArgumentError", PyExc_TypeError, 0));
|
||||
PyErr_NewException(const_cast<char*>("Boost.Python.ArgumentError"), PyExc_TypeError, 0));
|
||||
|
||||
object message = "Python argument types in\n %s.%s("
|
||||
% make_tuple(this->m_namespace, this->m_name);
|
||||
@@ -440,7 +440,7 @@ void function::add_to_namespace(
|
||||
else if (PyType_Check(ns))
|
||||
dict = ((PyTypeObject*)ns)->tp_dict;
|
||||
else
|
||||
dict = PyObject_GetAttrString(ns, "__dict__");
|
||||
dict = PyObject_GetAttrString(ns, const_cast<char*>("__dict__"));
|
||||
|
||||
if (dict == 0)
|
||||
throw_error_already_set();
|
||||
@@ -487,7 +487,7 @@ void function::add_to_namespace(
|
||||
new_func->m_name = name;
|
||||
|
||||
handle<> name_space_name(
|
||||
allow_null(::PyObject_GetAttrString(name_space.ptr(), "__name__")));
|
||||
allow_null(::PyObject_GetAttrString(name_space.ptr(), const_cast<char*>("__name__"))));
|
||||
|
||||
if (name_space_name)
|
||||
new_func->m_namespace = object(name_space_name);
|
||||
@@ -656,18 +656,18 @@ extern "C"
|
||||
}
|
||||
|
||||
static PyGetSetDef function_getsetlist[] = {
|
||||
{"__name__", (getter)function_get_name, 0, 0, 0 },
|
||||
{"func_name", (getter)function_get_name, 0, 0, 0 },
|
||||
{"__class__", (getter)function_get_class, 0, 0, 0 }, // see note above
|
||||
{"__doc__", (getter)function_get_doc, (setter)function_set_doc, 0, 0},
|
||||
{"func_doc", (getter)function_get_doc, (setter)function_set_doc, 0, 0},
|
||||
{const_cast<char*>("__name__"), (getter)function_get_name, 0, 0, 0 },
|
||||
{const_cast<char*>("func_name"), (getter)function_get_name, 0, 0, 0 },
|
||||
{const_cast<char*>("__class__"), (getter)function_get_class, 0, 0, 0 }, // see note above
|
||||
{const_cast<char*>("__doc__"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},
|
||||
{const_cast<char*>("func_doc"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},
|
||||
{NULL, 0, 0, 0, 0} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject function_type = {
|
||||
PyObject_HEAD_INIT(0)
|
||||
0,
|
||||
"Boost.Python.function",
|
||||
const_cast<char*>("Boost.Python.function"),
|
||||
sizeof(function),
|
||||
0,
|
||||
(destructor)function_dealloc, /* tp_dealloc */
|
||||
@@ -753,7 +753,8 @@ namespace detail
|
||||
}
|
||||
void BOOST_PYTHON_DECL pure_virtual_called()
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Pure virtual function called");
|
||||
PyErr_SetString(
|
||||
PyExc_RuntimeError, const_cast<char*>("Pure virtual function called"));
|
||||
throw_error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ extern "C"
|
||||
PyTypeObject life_support_type = {
|
||||
PyObject_HEAD_INIT(0)//(&PyType_Type)
|
||||
0,
|
||||
"Boost.Python.life_support",
|
||||
const_cast<char*>("Boost.Python.life_support"),
|
||||
sizeof(life_support),
|
||||
0,
|
||||
life_support_dealloc, /* tp_dealloc */
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Credits:
|
||||
// Andreas Kl\:ockner for fixing increment() to handle
|
||||
// error conditions.
|
||||
|
||||
#include <boost/python/object.hpp>
|
||||
#include <boost/python/handle.hpp>
|
||||
@@ -27,6 +31,8 @@ void stl_input_iterator_impl::increment()
|
||||
{
|
||||
this->ob_ = boost::python::handle<>(
|
||||
boost::python::allow_null(PyIter_Next(this->it_.ptr())));
|
||||
if (PyErr_Occurred())
|
||||
throw boost::python::error_already_set();
|
||||
}
|
||||
|
||||
bool stl_input_iterator_impl::equal(stl_input_iterator_impl const &that) const
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace boost { namespace python { namespace detail {
|
||||
detail::new_reference str_base::call(object const& arg_)
|
||||
{
|
||||
return (detail::new_reference)PyObject_CallFunction(
|
||||
(PyObject*)&PyString_Type, "(O)",
|
||||
(PyObject*)&PyString_Type, const_cast<char*>("(O)"),
|
||||
arg_.ptr());
|
||||
}
|
||||
|
||||
@@ -68,8 +68,9 @@ str str_base:: name ( BOOST_PP_ENUM_PARAMS(arity, object_cref x) ) const
|
||||
return str(new_reference( \
|
||||
expect_non_null( \
|
||||
PyObject_CallMethod( \
|
||||
this->ptr(), #name, \
|
||||
"(" BOOST_PP_REPEAT(arity, BOOST_PYTHON_FORMAT_OBJECT, _) ")" \
|
||||
this->ptr(), const_cast<char*>( #name ), \
|
||||
const_cast<char*>( \
|
||||
"(" BOOST_PP_REPEAT(arity, BOOST_PYTHON_FORMAT_OBJECT, _) ")") \
|
||||
BOOST_PP_REPEAT_1(arity, BOOST_PYTHON_OBJECT_PTR, _))))); \
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace boost { namespace python { namespace detail {
|
||||
detail::new_reference tuple_base::call(object const& arg_)
|
||||
{
|
||||
return (detail::new_reference)PyObject_CallFunction(
|
||||
(PyObject*)&PyTuple_Type, "(O)",
|
||||
(PyObject*)&PyTuple_Type, const_cast<char*>("(O)"),
|
||||
arg_.ptr());
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ test-suite python
|
||||
:
|
||||
|
||||
[
|
||||
run exec.cpp ../build//boost_python/<link>static $(PY)
|
||||
run exec.cpp /boost/python//boost_python/<link>static $(PY)
|
||||
: # program args
|
||||
: exec.py # input files
|
||||
: # requirements
|
||||
@@ -171,7 +171,8 @@ bpl-test crossmod_opaque
|
||||
/boost/python//boost_python ]
|
||||
[ bpl-test
|
||||
map_indexing_suite : map_indexing_suite.py map_indexing_suite_ext ]
|
||||
[ py-run import_.cpp : import_.py ]
|
||||
|
||||
[ run import_.cpp /boost/python//boost_python $(PY) : : import_.py ]
|
||||
|
||||
# if $(TEST_BIENSTMAN_NON_BUGS)
|
||||
# {
|
||||
|
||||
@@ -25,8 +25,8 @@ class B {
|
||||
B() {
|
||||
a = A::A_ptr(new A());
|
||||
}
|
||||
void set(A::A_ptr a) {
|
||||
this->a = a;
|
||||
void set(A::A_ptr _a) {
|
||||
this->a = _a;
|
||||
}
|
||||
A::A_ptr get() {
|
||||
return a;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ struct X
|
||||
X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
|
||||
virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
|
||||
|
||||
void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; }
|
||||
void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; }
|
||||
int value() const { BOOST_ASSERT(magic == 7654321); return x; }
|
||||
static int count() { return counter; }
|
||||
private:
|
||||
|
||||
@@ -34,7 +34,7 @@ struct X
|
||||
X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
|
||||
~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
|
||||
|
||||
void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; }
|
||||
void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; }
|
||||
int value() const { BOOST_ASSERT(magic == 7654321); return x; }
|
||||
static int count() { return counter; }
|
||||
private:
|
||||
|
||||
@@ -19,10 +19,10 @@ struct complicated
|
||||
int n;
|
||||
};
|
||||
|
||||
inline complicated::complicated(simple const&s, int n)
|
||||
: s(s.s), n(n)
|
||||
inline complicated::complicated(simple const&s, int _n)
|
||||
: s(s.s), n(_n)
|
||||
{
|
||||
std::cout << "constructing complicated: " << this->s << ", " << n << std::endl;
|
||||
std::cout << "constructing complicated: " << this->s << ", " << _n << std::endl;
|
||||
}
|
||||
|
||||
inline complicated::~complicated()
|
||||
|
||||
@@ -59,7 +59,7 @@ void eval_test()
|
||||
void exec_test()
|
||||
{
|
||||
// Register the module with the interpreter
|
||||
if (PyImport_AppendInittab("embedded_hello", initembedded_hello) == -1)
|
||||
if (PyImport_AppendInittab(const_cast<char*>("embedded_hello"), initembedded_hello) == -1)
|
||||
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
|
||||
"builtin modules");
|
||||
// Retrieve the main module
|
||||
|
||||
@@ -34,7 +34,7 @@ struct NoddyObject : PyObject
|
||||
PyTypeObject NoddyType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"Noddy",
|
||||
const_cast<char*>("Noddy"),
|
||||
sizeof(NoddyObject),
|
||||
0,
|
||||
dealloc, /* tp_dealloc */
|
||||
@@ -106,7 +106,7 @@ struct extract_simple_object
|
||||
PyTypeObject SimpleType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"Simple",
|
||||
const_cast<char*>("Simple"),
|
||||
sizeof(SimpleObject),
|
||||
0,
|
||||
dealloc, /* tp_dealloc */
|
||||
@@ -159,7 +159,7 @@ PyTypeObject SimpleType = {
|
||||
PyObject* new_simple()
|
||||
{
|
||||
SimpleObject* simple = PyObject_New(SimpleObject, &SimpleType);
|
||||
simple->x.s = "hello, world";
|
||||
simple->x.s = const_cast<char*>("hello, world");
|
||||
return (PyObject*)simple;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
# endif
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# include <eh.h> // for _set_se_translator()
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4297)
|
||||
# pragma warning(disable:4535)
|
||||
|
||||
@@ -10,19 +10,16 @@
|
||||
#include <boost/python/str.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
namespace py = boost::python;
|
||||
|
||||
// See if we can invoke array() from C++
|
||||
numeric::array new_array()
|
||||
{
|
||||
return numeric::array(
|
||||
make_tuple(
|
||||
make_tuple(1,2,3)
|
||||
, make_tuple(4,5,6)
|
||||
, make_tuple(7,8,9)
|
||||
py::make_tuple(
|
||||
py::make_tuple(1,2,3)
|
||||
, py::make_tuple(4,5,6)
|
||||
, py::make_tuple(7,8,9)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -51,7 +48,7 @@ namespace
|
||||
str format("exception type: %sn");
|
||||
format += "exception value: %sn";
|
||||
format += "traceback:n%s" ;
|
||||
object ret = format % boost::python::make_tuple(ty, v, tr);
|
||||
object ret = format % py::make_tuple(ty, v, tr);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +68,7 @@ namespace
|
||||
// inherits that behavior from object.
|
||||
void exercise(numeric::array& y, object check)
|
||||
{
|
||||
y[make_tuple(2,1)] = 3;
|
||||
y[py::make_tuple(2,1)] = 3;
|
||||
CHECK(y);
|
||||
CHECK(y.astype('D'));
|
||||
CHECK(y.copy());
|
||||
@@ -116,12 +113,12 @@ void exercise_numarray(numeric::array& y, object check)
|
||||
CHECK(y);
|
||||
CHECK(y.type());
|
||||
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4)));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8"));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false));
|
||||
CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false, object()));
|
||||
CHECK (y.factory(make_tuple(1.2, 3.4), "f8", true, false, object(), make_tuple(1,2,1)));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4)));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8"));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false));
|
||||
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object()));
|
||||
CHECK (y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object(), py::make_tuple(1,2,1)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -38,26 +38,61 @@ object obj_getattr(object x, char const* name)
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_objgetattr(object x, object const& name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_const_getattr(object const& x, char const* name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
object obj_const_objgetattr(object const& x, object const& name)
|
||||
{
|
||||
return x.attr(name);
|
||||
}
|
||||
|
||||
void obj_setattr(object x, char const* name, object value)
|
||||
{
|
||||
x.attr(name) = value;
|
||||
}
|
||||
|
||||
void obj_objsetattr(object x, object const& name, object value)
|
||||
{
|
||||
x.attr(name) = value;
|
||||
}
|
||||
|
||||
void obj_setattr42(object x, char const* name)
|
||||
{
|
||||
x.attr(name) = 42;
|
||||
}
|
||||
|
||||
void obj_objsetattr42(object x, object const& name)
|
||||
{
|
||||
x.attr(name) = 42;
|
||||
}
|
||||
|
||||
void obj_moveattr(object& x, char const* src, char const* dst)
|
||||
{
|
||||
x.attr(dst) = x.attr(src);
|
||||
}
|
||||
|
||||
void obj_objmoveattr(object& x, object const& src, object const& dst)
|
||||
{
|
||||
x.attr(dst) = x.attr(src);
|
||||
}
|
||||
|
||||
void obj_delattr(object x, char const* name)
|
||||
{
|
||||
x.attr(name).del();
|
||||
}
|
||||
|
||||
void obj_objdelattr(object x, object const& name)
|
||||
{
|
||||
x.attr(name).del();
|
||||
}
|
||||
|
||||
object obj_getitem(object x, object key)
|
||||
{
|
||||
return x[key];
|
||||
@@ -108,11 +143,21 @@ bool test_attr(object y, char* name)
|
||||
return y.attr(name);
|
||||
}
|
||||
|
||||
bool test_objattr(object y, object& name)
|
||||
{
|
||||
return y.attr(name);
|
||||
}
|
||||
|
||||
bool test_not_attr(object y, char* name)
|
||||
{
|
||||
return !y.attr(name);
|
||||
}
|
||||
|
||||
bool test_not_objattr(object y, object& name)
|
||||
{
|
||||
return !y.attr(name);
|
||||
}
|
||||
|
||||
bool test_item(object y, object key)
|
||||
{
|
||||
return y[key];
|
||||
@@ -142,6 +187,11 @@ bool check_string_slice()
|
||||
return s.slice(2,-1).slice(1,-1) == "lo, wor";
|
||||
}
|
||||
|
||||
object test_call(object c, object args, object kwds)
|
||||
{
|
||||
return c(*args, **kwds);
|
||||
}
|
||||
|
||||
bool check_binary_operators()
|
||||
{
|
||||
int y;
|
||||
@@ -301,11 +351,17 @@ BOOST_PYTHON_MODULE(object_ext)
|
||||
def("number", number);
|
||||
|
||||
def("obj_getattr", obj_getattr);
|
||||
def("obj_objgetattr", obj_objgetattr);
|
||||
def("obj_const_getattr", obj_const_getattr);
|
||||
def("obj_const_objgetattr", obj_const_objgetattr);
|
||||
def("obj_setattr", obj_setattr);
|
||||
def("obj_objsetattr", obj_objsetattr);
|
||||
def("obj_setattr42", obj_setattr42);
|
||||
def("obj_objsetattr42", obj_objsetattr42);
|
||||
def("obj_moveattr", obj_moveattr);
|
||||
|
||||
def("obj_objmoveattr", obj_objmoveattr);
|
||||
def("obj_delattr", obj_delattr);
|
||||
def("obj_objdelattr", obj_objdelattr);
|
||||
|
||||
def("obj_getitem", obj_getitem);
|
||||
def("obj_getitem3", obj_getitem);
|
||||
@@ -319,11 +375,14 @@ BOOST_PYTHON_MODULE(object_ext)
|
||||
def("test_not", test_not);
|
||||
|
||||
def("test_attr", test_attr);
|
||||
def("test_objattr", test_objattr);
|
||||
def("test_not_attr", test_not_attr);
|
||||
def("test_not_objattr", test_not_objattr);
|
||||
|
||||
def("test_item", test_item);
|
||||
def("test_not_item", test_not_item);
|
||||
|
||||
def("test_call", test_call);
|
||||
def("check_binary_operators", check_binary_operators);
|
||||
def("check_inplace", check_inplace);
|
||||
def("check_string_slice", check_string_slice);
|
||||
|
||||
@@ -34,29 +34,68 @@
|
||||
>>> try: obj_getattr(x, 'foo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> try: obj_objgetattr(x, 'objfoo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
|
||||
>>> obj_setattr(x, 'foo', 1)
|
||||
>>> x.foo
|
||||
1
|
||||
>>> obj_objsetattr(x, 'objfoo', 1)
|
||||
>>> try:obj_objsetattr(x, 1)
|
||||
... except TypeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> x.objfoo
|
||||
1
|
||||
>>> obj_getattr(x, 'foo')
|
||||
1
|
||||
>>> obj_objgetattr(x, 'objfoo')
|
||||
1
|
||||
>>> try:obj_objgetattr(x, 1)
|
||||
... except TypeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> obj_const_getattr(x, 'foo')
|
||||
1
|
||||
>>> obj_const_objgetattr(x, 'objfoo')
|
||||
1
|
||||
>>> obj_setattr42(x, 'foo')
|
||||
>>> x.foo
|
||||
42
|
||||
>>> obj_objsetattr42(x, 'objfoo')
|
||||
>>> x.objfoo
|
||||
42
|
||||
>>> obj_moveattr(x, 'foo', 'bar')
|
||||
>>> x.bar
|
||||
42
|
||||
>>> obj_objmoveattr(x, 'objfoo', 'objbar')
|
||||
>>> x.objbar
|
||||
42
|
||||
>>> test_attr(x, 'foo')
|
||||
1
|
||||
>>> test_objattr(x, 'objfoo')
|
||||
1
|
||||
>>> test_not_attr(x, 'foo')
|
||||
0
|
||||
>>> test_not_objattr(x, 'objfoo')
|
||||
0
|
||||
>>> x.foo = None
|
||||
>>> test_attr(x, 'foo')
|
||||
0
|
||||
>>> x.objfoo = None
|
||||
>>> test_objattr(x, 'objfoo')
|
||||
0
|
||||
>>> test_not_attr(x, 'foo')
|
||||
1
|
||||
>>> test_not_objattr(x, 'objfoo')
|
||||
1
|
||||
>>> obj_delattr(x, 'foo')
|
||||
>>> obj_objdelattr(x, 'objfoo')
|
||||
>>> try:obj_delattr(x, 'foo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
>>> try:obj_objdelattr(x, 'objfoo')
|
||||
... except AttributeError: pass
|
||||
... else: print 'expected an exception'
|
||||
|
||||
Items
|
||||
|
||||
@@ -95,7 +134,12 @@
|
||||
|
||||
Operators
|
||||
|
||||
|
||||
>>> def print_args(*args, **kwds):
|
||||
... print args, kwds
|
||||
>>> test_call(print_args, (0, 1, 2, 3), {'a':'A'})
|
||||
(0, 1, 2, 3) {'a': 'A'}
|
||||
|
||||
|
||||
>>> assert check_binary_operators()
|
||||
|
||||
>>> class X: pass
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace boost_python_test {
|
||||
private:
|
||||
std::string country;
|
||||
public:
|
||||
world(const std::string& country) {
|
||||
this->country = country;
|
||||
world(const std::string& _country) {
|
||||
this->country = _country;
|
||||
}
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
std::string get_country() const { return country; }
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace boost_python_test {
|
||||
class world
|
||||
{
|
||||
public:
|
||||
world(const std::string& country) : secret_number(0) {
|
||||
this->country = country;
|
||||
world(const std::string& _country) : secret_number(0) {
|
||||
this->country = _country;
|
||||
}
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
std::string get_country() const { return country; }
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/back_reference.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace boost_python_test {
|
||||
class world
|
||||
{
|
||||
public:
|
||||
world(const std::string& country) : secret_number(0) {
|
||||
this->country = country;
|
||||
world(const std::string& _country) : secret_number(0) {
|
||||
this->country = _country;
|
||||
}
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
std::string get_country() const { return country; }
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace boost_python_test {
|
||||
private:
|
||||
std::string country;
|
||||
public:
|
||||
world(const std::string& country) {
|
||||
this->country = country;
|
||||
world(const std::string& _country) {
|
||||
this->country = _country;
|
||||
}
|
||||
std::string greet() const { return "Hello from " + country + "!"; }
|
||||
std::string get_country() const { return country; }
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
|
||||
# define make_tuple boost::python::make_tuple
|
||||
#endif
|
||||
|
||||
@@ -100,7 +100,11 @@ bool accept_slice( slice) { return true; }
|
||||
|| BOOST_WORKAROUND( BOOST_INTEL_WIN, == 710)
|
||||
int check_slice_get_indicies(slice index);
|
||||
#endif
|
||||
int check_slice_get_indicies(const slice index)
|
||||
int check_slice_get_indicies(
|
||||
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
|
||||
const
|
||||
#endif
|
||||
slice index)
|
||||
{
|
||||
// A vector of integers from [-5, 5].
|
||||
std::vector<int> coll(11);
|
||||
|
||||
@@ -20,7 +20,7 @@ struct X
|
||||
X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
|
||||
virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
|
||||
|
||||
void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; }
|
||||
void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; }
|
||||
int value() const { BOOST_ASSERT(magic == 7654321); return x; }
|
||||
static int count() { return counter; }
|
||||
private:
|
||||
|
||||
@@ -12,6 +12,16 @@
|
||||
3
|
||||
4
|
||||
5
|
||||
>>> def generator():
|
||||
... yield 1
|
||||
... yield 2
|
||||
... raise RuntimeError, "oops"
|
||||
>>> try:
|
||||
... x.assign(iter(generator()))
|
||||
... print "NOT OK"
|
||||
... except RuntimeError:
|
||||
... print "OK"
|
||||
OK
|
||||
'''
|
||||
def run(args = None):
|
||||
import sys
|
||||
|
||||
@@ -13,7 +13,7 @@ struct test_class
|
||||
test_class(test_class const& rhs) : x(rhs.x), magic(7654321 + n) { ++counter; }
|
||||
virtual ~test_class() { BOOST_TEST(magic == 7654321 + n); magic = 6666666; x = 9999; --counter; }
|
||||
|
||||
void set(int x) { BOOST_TEST(magic == 7654321 + n); this->x = x; }
|
||||
void set(int _x) { BOOST_TEST(magic == 7654321 + n); this->x = _x; }
|
||||
int value() const { BOOST_TEST(magic == 7654321 + n); return x; }
|
||||
operator int() const { return x; }
|
||||
static int count() { return counter; }
|
||||
|
||||
@@ -65,7 +65,7 @@ struct B
|
||||
B() : x(0) {}
|
||||
B(A* x_) : x(x_) {}
|
||||
|
||||
inner const* adopt(A* x) { this->x = x; return &x->get_inner(); }
|
||||
inner const* adopt(A* _x) { this->x = _x; return &_x->get_inner(); }
|
||||
|
||||
std::string a_content()
|
||||
{
|
||||
|
||||
@@ -321,6 +321,19 @@ e
|
||||
>>> print_xvec(v)
|
||||
[ a b c d e f g h i j ]
|
||||
|
||||
#####################################################################
|
||||
# extend using a generator expression
|
||||
#####################################################################
|
||||
>>> v[:] = ['a','b','c','d','e'] # reset again
|
||||
>>> def generator():
|
||||
... addlist = ['f','g','h','i','j']
|
||||
... for i in addlist:
|
||||
... if i != 'g':
|
||||
... yield i
|
||||
>>> v.extend(generator())
|
||||
>>> print_xvec(v)
|
||||
[ a b c d e f h i j ]
|
||||
|
||||
#####################################################################
|
||||
# vector of strings
|
||||
#####################################################################
|
||||
|
||||
@@ -22,7 +22,7 @@ struct X
|
||||
X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
|
||||
virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
|
||||
|
||||
void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; }
|
||||
void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; }
|
||||
int value() const { BOOST_ASSERT(magic == 7654321); return x; }
|
||||
static int count() { return counter; }
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user