Skip to content

Commit 8910035

Browse files
author
Ralf W. Grosse-Kunstleve
committed
boost/python, libs/python: all changes from trunk merged into branches/release
[SVN r56806]
1 parent 46be733 commit 8910035

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+720
-245
lines changed

build/Jamfile.v2

Lines changed: 89 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os ;
66
import modules ;
7+
import feature ;
78

89
import python ;
910

@@ -22,73 +23,102 @@ if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
2223
}
2324
}
2425

26+
rule find-py3-version
27+
{
28+
local versions = [ feature.values python ] ;
29+
local py3ver ;
30+
for local v in $(versions)
31+
{
32+
if $(v) >= 3.0
33+
{
34+
py3ver = $(v) ;
35+
}
36+
}
37+
return $(py3ver) ;
38+
}
39+
40+
py3-version = [ find-py3-version ] ;
41+
2542
project boost/python
2643
: source-location ../src
2744
;
2845

2946
rule cond ( test ? : yes * : no * ) { if $(test) { return $(yes) ; } else { return $(no) ; } }
3047
rule unless ( test ? : yes * : no * ) { if ! $(test) { return $(yes) ; } else { return $(no) ; } }
3148

32-
lib boost_python
33-
: # sources
34-
numeric.cpp
35-
list.cpp
36-
long.cpp
37-
dict.cpp
38-
tuple.cpp
39-
str.cpp
40-
slice.cpp
49+
rule lib_boost_python ( is-py3 ? )
50+
{
4151

42-
converter/from_python.cpp
43-
converter/registry.cpp
44-
converter/type_id.cpp
45-
object/enum.cpp
46-
object/class.cpp
47-
object/function.cpp
48-
object/inheritance.cpp
49-
object/life_support.cpp
50-
object/pickle_support.cpp
51-
errors.cpp
52-
module.cpp
53-
converter/builtin_converters.cpp
54-
converter/arg_to_python_base.cpp
55-
object/iterator.cpp
56-
object/stl_iterator.cpp
57-
object_protocol.cpp
58-
object_operators.cpp
59-
wrapper.cpp
60-
import.cpp
61-
exec.cpp
62-
object/function_doc_signature.cpp
63-
: # requirements
64-
<link>static:<define>BOOST_PYTHON_STATIC_LIB
65-
<define>BOOST_PYTHON_SOURCE
66-
67-
# On Windows, all code using Python has to link to the Python
68-
# import library.
69-
#
70-
# On *nix we never link libboost_python to libpython. When
71-
# extending Python, all Python symbols are provided by the
72-
# Python interpreter executable. When embedding Python, the
73-
# client executable is expected to explicitly link to
74-
# /python//python (the target representing libpython) itself.
75-
#
76-
# python_for_extensions is a target defined by Boost.Build to
77-
# provide the Python include paths, and on Windows, the Python
78-
# import library, as usage requirements.
79-
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
80-
81-
# we prevent building when there is no python available
82-
# as it's not possible anyway, and to cause dependents to
83-
# fail to build
84-
[ unless [ python.configured ] : <build>no ]
52+
lib [ cond $(is-py3) : boost_python3 : boost_python ]
53+
: # sources
54+
numeric.cpp
55+
list.cpp
56+
long.cpp
57+
dict.cpp
58+
tuple.cpp
59+
str.cpp
60+
slice.cpp
8561

86-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
87-
: # default build
88-
<link>shared
89-
: # usage requirements
90-
<link>static:<define>BOOST_PYTHON_STATIC_LIB
91-
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
92-
;
62+
converter/from_python.cpp
63+
converter/registry.cpp
64+
converter/type_id.cpp
65+
object/enum.cpp
66+
object/class.cpp
67+
object/function.cpp
68+
object/inheritance.cpp
69+
object/life_support.cpp
70+
object/pickle_support.cpp
71+
errors.cpp
72+
module.cpp
73+
converter/builtin_converters.cpp
74+
converter/arg_to_python_base.cpp
75+
object/iterator.cpp
76+
object/stl_iterator.cpp
77+
object_protocol.cpp
78+
object_operators.cpp
79+
wrapper.cpp
80+
import.cpp
81+
exec.cpp
82+
object/function_doc_signature.cpp
83+
: # requirements
84+
<link>static:<define>BOOST_PYTHON_STATIC_LIB
85+
<define>BOOST_PYTHON_SOURCE
86+
87+
# On Windows, all code using Python has to link to the Python
88+
# import library.
89+
#
90+
# On *nix we never link libboost_python to libpython. When
91+
# extending Python, all Python symbols are provided by the
92+
# Python interpreter executable. When embedding Python, the
93+
# client executable is expected to explicitly link to
94+
# /python//python (the target representing libpython) itself.
95+
#
96+
# python_for_extensions is a target defined by Boost.Build to
97+
# provide the Python include paths, and on Windows, the Python
98+
# import library, as usage requirements.
99+
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
100+
101+
# we prevent building when there is no python available
102+
# as it's not possible anyway, and to cause dependents to
103+
# fail to build
104+
[ unless [ python.configured ] : <build>no ]
93105

106+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
107+
[ cond $(is-py3) : <python>$(py3-version) ]
108+
: # default build
109+
<link>shared
110+
: # usage requirements
111+
<link>static:<define>BOOST_PYTHON_STATIC_LIB
112+
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
113+
;
114+
115+
}
116+
117+
lib_boost_python ;
94118
boost-install boost_python ;
119+
120+
if $(py3-version)
121+
{
122+
lib_boost_python yes ;
123+
boost-install boost_python3 ;
124+
}

doc/news.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,43 @@ <h2 align="center">News/Change Log</h2>
3232
<hr>
3333

3434
<dl class="page-index">
35+
3536
<dt>Current SVN</dt>
37+
<dd>
38+
<ul>
39+
<li>Python 3 support:</li>
40+
<ul>
41+
<li>All the current Boost.Python test cases passed. Extension modules using
42+
Boost.Python expected to support Python 3 smoothly.</li>
43+
<li>Introduced <code>object.contains</code> where <code>x.contains(y)</code>
44+
is equivalent to Python code <code>y in x</code>.
45+
Now <code>dict.has_key</code> is just a wrapper of <code>object.contains</code>.
46+
</li>
47+
<li>When building against Python 3, <code>str.decode</code> will be removed.</li>
48+
<li>When building against Python 3, the original signature of <code>list.sort</code>, which is:
49+
<pre>void sort(object_cref cmpfunc);</pre>
50+
will change to:
51+
<pre>void sort(args_proxy const &args, kwds_proxy const &kwds);</pre>
52+
53+
This is because in Python 3 <code>list.sort</code> requires all its arguments be keyword arguments.
54+
So you should call it like this:
55+
<pre>x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true))));</pre>
56+
57+
</li>
58+
<li>According to <a href="http://www.python.org/dev/peps/pep-3123/">PEP 3123</a>,
59+
when building Boost.Python against Python older than 2.6, the following macros will
60+
be defined in Boost.Python header:
61+
<pre>
62+
# define Py_TYPE(o) (((PyObject*)(o))->ob_type)
63+
# define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt)
64+
# define Py_SIZE(o) (((PyVarObject*)(o))->ob_size)</pre>
65+
So extension writers can use these macro directly, to make code clean and compatible with Python 3.
66+
</li>
67+
</ul>
68+
</ul>
69+
</dd>
70+
71+
<dt>1.39.0 Release</dt>
3672

3773
<dd>
3874
<ul>

include/boost/python/converter/builtin_converters.hpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ namespace detail
9090
BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr)
9191

9292
// Specialize converters for signed and unsigned T to Python Int
93+
#if PY_VERSION_HEX >= 0x03000000
94+
95+
# define BOOST_PYTHON_TO_INT(T) \
96+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyLong_FromLong(x), &PyLong_Type) \
97+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, ::PyLong_FromUnsignedLong(x), &PyLong_Type)
98+
99+
#else
100+
93101
# define BOOST_PYTHON_TO_INT(T) \
94102
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyInt_FromLong(x), &PyInt_Type) \
95103
BOOST_PYTHON_TO_PYTHON_BY_VALUE( \
@@ -98,6 +106,7 @@ namespace detail
98106
(std::numeric_limits<long>::max)()) \
99107
? ::PyLong_FromUnsignedLong(x) \
100108
: ::PyInt_FromLong(x), &PyInt_Type)
109+
#endif
101110

102111
// Bool is not signed.
103112
#if PY_VERSION_HEX >= 0x02030000
@@ -116,17 +125,24 @@ BOOST_PYTHON_TO_INT(long)
116125
// using Python's macro instead of Boost's - we don't seem to get the
117126
// config right all the time.
118127
# ifdef HAVE_LONG_LONG
119-
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyInt_Type)
120-
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyInt_Type)
128+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyLong_Type)
129+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyLong_Type)
121130
# endif
122131

123132
# undef BOOST_TO_PYTHON_INT
124133

134+
#if PY_VERSION_HEX >= 0x03000000
135+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyUnicode_Type)
136+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyUnicode_Type)
137+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyUnicode_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
138+
#else
125139
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyString_Type)
126140
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyString_Type)
127141
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyString_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyString_Type)
142+
#endif
143+
128144
#if defined(Py_USING_UNICODE) && !defined(BOOST_NO_STD_WSTRING)
129-
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<ssize_t>(x.size())), &PyString_Type)
145+
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
130146
# endif
131147
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, ::PyFloat_FromDouble(x), &PyFloat_Type)
132148
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, ::PyFloat_FromDouble(x), &PyFloat_Type)

include/boost/python/converter/pyobject_traits.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ struct pyobject_traits<PyObject>
3434
// This is not an exhaustive list; should be expanded.
3535
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type);
3636
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List);
37+
#if PY_VERSION_HEX < 0x03000000
3738
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int);
39+
#endif
3840
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long);
3941
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict);
4042
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple);

include/boost/python/detail/operator_id.hpp

100755100644
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ enum operator_id
4747
op_ixor,
4848
op_ior,
4949
op_complex,
50+
#if PY_VERSION_HEX >= 0x03000000
51+
op_bool,
52+
#else
5053
op_nonzero,
54+
#endif
5155
op_repr
5256
};
5357

include/boost/python/detail/wrap_python.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ typedef int pid_t;
175175
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
176176
#endif
177177

178+
// Define Python 3 macros for Python 2.x
179+
#if PY_VERSION_HEX < 0x02060000
180+
181+
# define Py_TYPE(o) (((PyObject*)(o))->ob_type)
182+
# define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt)
183+
# define Py_SIZE(o) (((PyVarObject*)(o))->ob_size)
184+
185+
# define PyVarObject_HEAD_INIT(type, size) \
186+
PyObject_HEAD_INIT(type) size,
187+
188+
#endif
189+
190+
178191
#ifdef __MWERKS__
179192
# pragma warn_possunwant off
180193
#elif _MSC_VER

include/boost/python/enum.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ void* enum_<T>::convertible_from_python(PyObject* obj)
7979
template <class T>
8080
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
8181
{
82+
#if PY_VERSION_HEX >= 0x03000000
83+
T x = static_cast<T>(PyLong_AS_LONG(obj));
84+
#else
8285
T x = static_cast<T>(PyInt_AS_LONG(obj));
86+
#endif
8387
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
8488
new (storage) T(x);
8589
data->convertible = storage;

include/boost/python/exec.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ object
2020
BOOST_PYTHON_DECL
2121
eval(str string, object global = object(), object local = object());
2222

23+
// Execute an individual python statement from str.
24+
// global and local are the global and local scopes respectively,
25+
// used during execution.
26+
object
27+
BOOST_PYTHON_DECL
28+
exec_statement(str string, object global = object(), object local = object());
29+
2330
// Execute python source code from str.
2431
// global and local are the global and local scopes respectively,
2532
// used during execution.

include/boost/python/list.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace detail
1919
{
2020
void append(object_cref); // append object to end
2121

22-
long count(object_cref value) const; // return number of occurrences of value
22+
ssize_t count(object_cref value) const; // return number of occurrences of value
2323

2424
void extend(object_cref sequence); // extend list by appending sequence elements
2525

@@ -37,8 +37,12 @@ namespace detail
3737
void reverse(); // reverse *IN PLACE*
3838

3939
void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
40+
#if PY_VERSION_HEX >= 0x03000000
41+
void sort(args_proxy const &args,
42+
kwds_proxy const &kwds);
43+
#else
4044
void sort(object_cref cmpfunc);
41-
45+
#endif
4246

4347
protected:
4448
list_base(); // new list
@@ -113,13 +117,15 @@ class list : public detail::list_base
113117
base::remove(object(value));
114118
}
115119

120+
#if PY_VERSION_HEX <= 0x03000000
116121
void sort() { base::sort(); }
117-
122+
118123
template <class T>
119124
void sort(T const& value)
120125
{
121126
base::sort(object(value));
122127
}
128+
#endif
123129

124130
public: // implementation detail -- for internal use only
125131
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)

include/boost/python/lvalue_from_pytype.hpp

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct extract_member
6363
{
6464
static MemberType& execute(InstanceType& c)
6565
{
66-
(void)c.ob_type; // static assertion
66+
(void)Py_TYPE(&c); // static assertion
6767
return c.*member;
6868
}
6969
};
@@ -75,7 +75,7 @@ struct extract_identity
7575
{
7676
static InstanceType& execute(InstanceType& c)
7777
{
78-
(void)c.ob_type; // static assertion
78+
(void)Py_TYPE(&c); // static assertion
7979
return c;
8080
}
8181
};

0 commit comments

Comments
 (0)