2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00

Compare commits

...

45 Commits

Author SHA1 Message Date
Haoyu Bai
36cda0a8c8 documented Python 3 support in news
[SVN r55608]
2009-08-16 06:04:07 +00:00
Haoyu Bai
5c49d45f34 swap position of polymorphism2_auto_ptr and polymorphism to workaroud a boost.build behavior which can cause source code list rearranged thus cause test fail.
[SVN r55562]
2009-08-13 03:53:34 +00:00
Haoyu Bai
1210f54233 remove some unused comments
[SVN r55460]
2009-08-08 09:55:12 +00:00
Haoyu Bai
067d9da915 remove comment nolonger valid since there is no PyLong_AsSsize_t API in python 2.5
[SVN r55459]
2009-08-08 09:33:44 +00:00
Haoyu Bai
07abe23ae4 remove comment nolonger valid
[SVN r55458]
2009-08-08 09:28:38 +00:00
Haoyu Bai
f7c5139fe3 build two BPL targets: libboost_python and libboost_python3
[SVN r55456]
2009-08-08 07:58:44 +00:00
Haoyu Bai
fed453563a some debugging code for python.jam and add a dummy enum.py as dependent of polymorphism2_auto_ptr for testing
[SVN r55360]
2009-08-02 06:20:14 +00:00
Haoyu Bai
7bf964b1ce implemented list.sort with keyword argument support, by using args_proxy and kwds_proxy. Not a nice solution though...
[SVN r55078]
2009-07-22 05:38:59 +00:00
Haoyu Bai
e428495a96 fix upcast test case
[SVN r54869]
2009-07-10 17:42:02 +00:00
Haoyu Bai
5e68c24f10 fix map_indexing_suite test case
[SVN r54868]
2009-07-10 17:36:07 +00:00
Haoyu Bai
f1ee4a4b86 fix str.cpp for str test case
[SVN r54867]
2009-07-10 17:35:29 +00:00
Haoyu Bai
b4dbda873a fix pickle2 test case
[SVN r54866]
2009-07-10 17:34:36 +00:00
Haoyu Bai
db78e5242f fix iterator test case by normolize doctests spaces
[SVN r54864]
2009-07-10 16:51:16 +00:00
Haoyu Bai
3dff5215cd fix str test case
[SVN r54863]
2009-07-10 16:47:51 +00:00
Haoyu Bai
0536dad8ab remove decode() method in str wrapper for py3k
[SVN r54862]
2009-07-10 16:47:17 +00:00
Haoyu Bai
c6bb65197f fix tuple test case by indicate doctests to ignore spaces
[SVN r54838]
2009-07-09 17:50:11 +00:00
Haoyu Bai
a272bb801a fixed dict test case
[SVN r54837]
2009-07-09 17:47:47 +00:00
Haoyu Bai
3a75666f22 introduce object.contains(), a wrapper of Python 'in' operator. And reimplement dict.has_key by call object.contains(). Because dict.has_key is removed in py3k
[SVN r54836]
2009-07-09 17:45:26 +00:00
Haoyu Bai
ff0e58d30d fix long test case
[SVN r54834]
2009-07-09 16:52:14 +00:00
Haoyu Bai
c4c7fe6dc0 fix list sorting in py3k
[SVN r54675]
2009-07-05 16:48:15 +00:00
Haoyu Bai
ec4a1df1e0 correct previous commit so exec.py also can run in python 2 with empty global
[SVN r54652]
2009-07-04 17:37:05 +00:00
Haoyu Bai
5f7eaa4617 removed since keywords are not allowed to be assigned
[SVN r54651]
2009-07-04 16:55:11 +00:00
Haoyu Bai
3f536cc0c0 fix builtin_converters to remove 42L and u'...' appeared in doctest result
[SVN r54650]
2009-07-04 16:43:31 +00:00
Haoyu Bai
b934253848 fix builtin unsgined long from python convert bug
[SVN r54649]
2009-07-04 16:30:23 +00:00
Haoyu Bai
c219ae50c4 .ob_type -> Py_TYPE() usage change
[SVN r54646]
2009-07-04 16:18:56 +00:00
Haoyu Bai
28c7185654 fix the 'try' test case
[SVN r54645]
2009-07-04 16:18:24 +00:00
Haoyu Bai
7beda2e192 several fix for the exec test case to make it runs under py3k
[SVN r54644]
2009-07-04 16:00:06 +00:00
Haoyu Bai
1370f36d45 fix test dependence of polymorphism2_auto_ptr
[SVN r54643]
2009-07-04 15:01:32 +00:00
Haoyu Bai
06aca4c52d fix definition of opaque<Pointer>::type_object
[SVN r53754]
2009-06-08 16:35:18 +00:00
Haoyu Bai
15f4a59969 fix the static property initialization caused by Python internal change in property_init()
[SVN r53731]
2009-06-07 20:15:42 +00:00
Haoyu Bai
9b06248e81 change TrueDivide to FloorDivide to make the semantic conform with C/C++ '/' operator
[SVN r53721]
2009-06-07 14:32:57 +00:00
Haoyu Bai
4e0a826b50 fix __nonzero__ -> __bool__ change
[SVN r53718]
2009-06-07 14:06:17 +00:00
Haoyu Bai
58f1684885 change encoding annotation iso-latin-1 to latin-1
[SVN r53698]
2009-06-06 18:35:40 +00:00
Haoyu Bai
eea11df1ea clean other attempts for making unicode -> const char* conversion work, since now we have the right way in previous commit.
[SVN r53693]
2009-06-06 14:51:35 +00:00
Haoyu Bai
6fe34b46d4 implemented unicode -> const char* lvalue converter for py3k, by using _PyUnicode_AsString() C-API
[SVN r53692]
2009-06-06 14:43:48 +00:00
Haoyu Bai
e33ce235a8 implemented a arg_from_python converter that converts py3k unicode to const char*, not an ideal solution, just experimenting.
[SVN r53653]
2009-06-05 12:19:00 +00:00
Haoyu Bai
caf661cfeb fix for next() -> __next__() name change in py3k
[SVN r53322]
2009-05-27 19:43:52 +00:00
Haoyu Bai
86f44ed159 more minor fixes to get test cases passed
[SVN r53315]
2009-05-27 18:16:13 +00:00
Haoyu Bai
e73277e156 more fixes to get testcases work, includes module init and other minor fixes
[SVN r53285]
2009-05-26 17:05:53 +00:00
Haoyu Bai
92f07fc4d6 get builtin_converters.cpp compiled under Python 3
[SVN r53278]
2009-05-26 09:59:43 +00:00
Haoyu Bai
99737170f8 Fix more bugs due to typo.
[SVN r52134]
2009-04-02 17:04:26 +00:00
Haoyu Bai
ce3992ce52 Fix a typo which cause many tests crash.
[SVN r52133]
2009-04-02 16:40:48 +00:00
Haoyu Bai
60ed8e57c1 More BPL .cpps compiled. A part of Python 3 module initilization support done.
[SVN r52131]
2009-04-02 15:27:53 +00:00
Haoyu Bai
41bcac0369 preliminary work - 14 BPL .cpp files can be compiled with Python 3 now.
[SVN r52118]
2009-04-01 19:03:25 +00:00
Haoyu Bai
a0f61cdfd1 Redo py3k branching from trunk again
[SVN r52115]
2009-04-01 16:55:33 +00:00
156 changed files with 721 additions and 249 deletions

View File

@@ -4,6 +4,7 @@
import os ;
import modules ;
import feature ;
import python ;
@@ -22,6 +23,22 @@ if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] )
}
}
rule find-py3-version
{
local versions = [ feature.values python ] ;
local py3ver ;
for local v in $(versions)
{
if $(v) >= 3.0
{
py3ver = $(v) ;
}
}
return $(py3ver) ;
}
py3-version = [ find-py3-version ] ;
project boost/python
: source-location ../src
;
@@ -29,66 +46,79 @@ project boost/python
rule cond ( test ? : yes * : no * ) { if $(test) { return $(yes) ; } else { return $(no) ; } }
rule unless ( test ? : yes * : no * ) { if ! $(test) { return $(yes) ; } else { return $(no) ; } }
lib boost_python
: # sources
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
slice.cpp
rule lib_boost_python ( is-py3 ? )
{
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object/stl_iterator.cpp
object_protocol.cpp
object_operators.cpp
wrapper.cpp
import.cpp
exec.cpp
object/function_doc_signature.cpp
: # requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE
# On Windows, all code using Python has to link to the Python
# import library.
#
# On *nix we never link libboost_python to libpython. When
# extending Python, all Python symbols are provided by the
# Python interpreter executable. When embedding Python, the
# client executable is expected to explicitly link to
# /python//python (the target representing libpython) itself.
#
# python_for_extensions is a target defined by Boost.Build to
# provide the Python include paths, and on Windows, the Python
# import library, as usage requirements.
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
# we prevent building when there is no python available
# as it's not possible anyway, and to cause dependents to
# fail to build
[ unless [ python.configured ] : <build>no ]
lib [ cond $(is-py3) : boost_python3 : boost_python ]
: # sources
numeric.cpp
list.cpp
long.cpp
dict.cpp
tuple.cpp
str.cpp
slice.cpp
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
: # default build
<link>shared
: # usage requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
;
converter/from_python.cpp
converter/registry.cpp
converter/type_id.cpp
object/enum.cpp
object/class.cpp
object/function.cpp
object/inheritance.cpp
object/life_support.cpp
object/pickle_support.cpp
errors.cpp
module.cpp
converter/builtin_converters.cpp
converter/arg_to_python_base.cpp
object/iterator.cpp
object/stl_iterator.cpp
object_protocol.cpp
object_operators.cpp
wrapper.cpp
import.cpp
exec.cpp
object/function_doc_signature.cpp
: # requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<define>BOOST_PYTHON_SOURCE
# On Windows, all code using Python has to link to the Python
# import library.
#
# On *nix we never link libboost_python to libpython. When
# extending Python, all Python symbols are provided by the
# Python interpreter executable. When embedding Python, the
# client executable is expected to explicitly link to
# /python//python (the target representing libpython) itself.
#
# python_for_extensions is a target defined by Boost.Build to
# provide the Python include paths, and on Windows, the Python
# import library, as usage requirements.
[ cond [ python.configured ] : <library>/python//python_for_extensions ]
# we prevent building when there is no python available
# as it's not possible anyway, and to cause dependents to
# fail to build
[ unless [ python.configured ] : <build>no ]
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
[ cond $(is-py3) : <python>$(py3-version) ]
: # default build
<link>shared
: # usage requirements
<link>static:<define>BOOST_PYTHON_STATIC_LIB
<python-debugging>on:<define>BOOST_DEBUG_PYTHON
;
}
lib_boost_python ;
boost-install boost_python ;
if $(py3-version)
{
lib_boost_python yes ;
boost-install boost_python3 ;
}

0
doc/PyConDC_2003/bpl.html Executable file → Normal file
View File

0
doc/PyConDC_2003/bpl.pdf Executable file → Normal file
View File

0
doc/PyConDC_2003/python_cpp_mix.jpg Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

0
doc/PyConDC_2003/python_cpp_mix.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

0
doc/internals.html Executable file → Normal file
View File

0
doc/internals.rst Executable file → Normal file
View File

View File

@@ -32,7 +32,43 @@
<hr>
<dl class="page-index">
<dt>Current SVN</dt>
<dd>
<ul>
<li>Python 3 support:</li>
<ul>
<li>All the current Boost.Python test cases passed. Extension modules using
Boost.Python expected to support Python 3 smoothly.</li>
<li>Introduced <code>object.contains</code> where <code>x.contains(y)</code>
is equivalent to Python code <code>y in x</code>.
Now <code>dict.has_key</code> is just a wrapper of <code>object.contains</code>.
</li>
<li>When building against Python 3, <code>str.decode</code> will be removed.</li>
<li>When building against Python 3, the original signature of <code>list.sort</code>, which is:
<pre>void sort(object_cref cmpfunc);</pre>
will change to:
<pre>void sort(args_proxy const &args, kwds_proxy const &kwds);</pre>
This is because in Python 3 <code>list.sort</code> requires all its arguments be keyword arguments.
So you should call it like this:
<pre>x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true))));</pre>
</li>
<li>According to <a href="http://www.python.org/dev/peps/pep-3123/">PEP 3123</a>,
when building Boost.Python against Python older than 2.6, the following macros will
be defined in Boost.Python header:
<pre>
# define Py_TYPE(o) (((PyObject*)(o))->ob_type)
# define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt)
# define Py_SIZE(o) (((PyVarObject*)(o))->ob_size)</pre>
So extension writers can use these macro directly, to make code clean and compatible with Python 3.
</li>
</ul>
</ul>
</dd>
<dt>1.39.0 Release</dt>
<dd>
<ul>

0
doc/tutorial/doc/html/images/alert.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 603 B

After

Width:  |  Height:  |  Size: 603 B

0
doc/tutorial/doc/html/images/home.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 358 B

0
doc/tutorial/doc/html/images/next.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 336 B

After

Width:  |  Height:  |  Size: 336 B

0
doc/tutorial/doc/html/images/note.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 658 B

After

Width:  |  Height:  |  Size: 658 B

0
doc/tutorial/doc/html/images/prev.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 334 B

After

Width:  |  Height:  |  Size: 334 B

0
doc/tutorial/doc/html/images/tip.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 640 B

After

Width:  |  Height:  |  Size: 640 B

0
doc/tutorial/doc/html/images/up.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 370 B

After

Width:  |  Height:  |  Size: 370 B

0
doc/v2/instance_holder.html Executable file → Normal file
View File

0
doc/v2/lvalue_from_pytype.html Executable file → Normal file
View File

0
doc/v2/operators.html Executable file → Normal file
View File

0
doc/v2/raw_function.html Executable file → Normal file
View File

0
doc/v2/return_arg.html Executable file → Normal file
View File

0
doc/v2/stl_iterator.html Executable file → Normal file
View File

0
doc/v2/type_id.html Executable file → Normal file
View File

0
doc/v2/wrapper.html Executable file → Normal file
View File

0
example/Jamroot Executable file → Normal file
View File

0
example/boost-build.jam Executable file → Normal file
View File

0
example/quickstart/Jamroot Executable file → Normal file
View File

0
example/tutorial/Jamroot Executable file → Normal file
View File

0
include/boost/python/arg_from_python.hpp Executable file → Normal file
View File

0
include/boost/python/base_type_traits.hpp Executable file → Normal file
View File

0
include/boost/python/borrowed.hpp Executable file → Normal file
View File

0
include/boost/python/cast.hpp Executable file → Normal file
View File

0
include/boost/python/converter/arg_from_python.hpp Executable file → Normal file
View File

0
include/boost/python/converter/arg_to_python.hpp Executable file → Normal file
View File

0
include/boost/python/converter/arg_to_python_base.hpp Executable file → Normal file
View File

View File

@@ -90,6 +90,14 @@ namespace detail
BOOST_PYTHON_ARG_TO_PYTHON_BY_VALUE(T,expr)
// Specialize converters for signed and unsigned T to Python Int
#if PY_VERSION_HEX >= 0x03000000
# define BOOST_PYTHON_TO_INT(T) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyLong_FromLong(x), &PyLong_Type) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned T, ::PyLong_FromUnsignedLong(x), &PyLong_Type)
#else
# define BOOST_PYTHON_TO_INT(T) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed T, ::PyInt_FromLong(x), &PyInt_Type) \
BOOST_PYTHON_TO_PYTHON_BY_VALUE( \
@@ -98,6 +106,7 @@ namespace detail
(std::numeric_limits<long>::max)()) \
? ::PyLong_FromUnsignedLong(x) \
: ::PyInt_FromLong(x), &PyInt_Type)
#endif
// Bool is not signed.
#if PY_VERSION_HEX >= 0x02030000
@@ -116,17 +125,24 @@ BOOST_PYTHON_TO_INT(long)
// using Python's macro instead of Boost's - we don't seem to get the
// config right all the time.
# ifdef HAVE_LONG_LONG
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyInt_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyInt_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyLong_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyLong_Type)
# endif
# undef BOOST_TO_PYTHON_INT
#if PY_VERSION_HEX >= 0x03000000
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyUnicode_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyUnicode_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyUnicode_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
#else
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyString_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyString_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyString_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyString_Type)
#endif
#if defined(Py_USING_UNICODE) && !defined(BOOST_NO_STD_WSTRING)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<ssize_t>(x.size())), &PyString_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::wstring, ::PyUnicode_FromWideChar(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
# endif
BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, ::PyFloat_FromDouble(x), &PyFloat_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, ::PyFloat_FromDouble(x), &PyFloat_Type)

View File

0
include/boost/python/converter/object_manager.hpp Executable file → Normal file
View File

View File

@@ -34,7 +34,9 @@ struct pyobject_traits<PyObject>
// This is not an exhaustive list; should be expanded.
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Type);
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(List);
#if PY_VERSION_HEX < 0x03000000
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Int);
#endif
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Long);
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Dict);
BOOST_PYTHON_BUILTIN_OBJECT_TRAITS(Tuple);

0
include/boost/python/converter/pytype_function.hpp Executable file → Normal file
View File

0
include/boost/python/converter/return_from_python.hpp Executable file → Normal file
View File

0
include/boost/python/def_visitor.hpp Executable file → Normal file
View File

0
include/boost/python/detail/borrowed_ptr.hpp Executable file → Normal file
View File

0
include/boost/python/detail/convertible.hpp Executable file → Normal file
View File

0
include/boost/python/detail/copy_ctor_mutates_rhs.hpp Executable file → Normal file
View File

0
include/boost/python/detail/decorated_type_id.hpp Executable file → Normal file
View File

0
include/boost/python/detail/def_helper_fwd.hpp Executable file → Normal file
View File

0
include/boost/python/detail/enable_if.hpp Executable file → Normal file
View File

0
include/boost/python/detail/force_instantiate.hpp Executable file → Normal file
View File

0
include/boost/python/detail/is_shared_ptr.hpp Executable file → Normal file
View File

0
include/boost/python/detail/is_wrapper.hpp Executable file → Normal file
View File

View File

4
include/boost/python/detail/operator_id.hpp Executable file → Normal file
View File

@@ -47,7 +47,11 @@ enum operator_id
op_ixor,
op_ior,
op_complex,
#if PY_VERSION_HEX >= 0x03000000
op_bool,
#else
op_nonzero,
#endif
op_repr
};

0
include/boost/python/detail/prefix.hpp Executable file → Normal file
View File

0
include/boost/python/detail/python_type.hpp Executable file → Normal file
View File

0
include/boost/python/detail/sfinae.hpp Executable file → Normal file
View File

0
include/boost/python/detail/unwind_type.hpp Executable file → Normal file
View File

0
include/boost/python/detail/unwrap_type_id.hpp Executable file → Normal file
View File

0
include/boost/python/detail/unwrap_wrapper.hpp Executable file → Normal file
View File

0
include/boost/python/detail/value_arg.hpp Executable file → Normal file
View File

View File

@@ -175,6 +175,19 @@ typedef int pid_t;
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#endif
// Define Python 3 macros for Python 2.x
#if PY_VERSION_HEX < 0x02060000
# define Py_TYPE(o) (((PyObject*)(o))->ob_type)
# define Py_REFCNT(o) (((PyObject*)(o))->ob_refcnt)
# define Py_SIZE(o) (((PyVarObject*)(o))->ob_size)
# define PyVarObject_HEAD_INIT(type, size) \
PyObject_HEAD_INIT(type) size,
#endif
#ifdef __MWERKS__
# pragma warn_possunwant off
#elif _MSC_VER

0
include/boost/python/detail/wrapper_base.hpp Executable file → Normal file
View File

0
include/boost/python/docstring_options.hpp Executable file → Normal file
View File

View File

@@ -79,7 +79,11 @@ void* enum_<T>::convertible_from_python(PyObject* obj)
template <class T>
void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
{
#if PY_VERSION_HEX >= 0x03000000
T x = static_cast<T>(PyLong_AS_LONG(obj));
#else
T x = static_cast<T>(PyInt_AS_LONG(obj));
#endif
void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
new (storage) T(x);
data->convertible = storage;

0
include/boost/python/handle.hpp Executable file → Normal file
View File

0
include/boost/python/handle_fwd.hpp Executable file → Normal file
View File

0
include/boost/python/instance_holder.hpp Executable file → Normal file
View File

View File

@@ -19,7 +19,7 @@ namespace detail
{
void append(object_cref); // append object to end
long count(object_cref value) const; // return number of occurrences of value
Py_ssize_t count(object_cref value) const; // return number of occurrences of value
void extend(object_cref sequence); // extend list by appending sequence elements
@@ -37,8 +37,12 @@ namespace detail
void reverse(); // reverse *IN PLACE*
void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
#if PY_VERSION_HEX >= 0x03000000
void sort(args_proxy const &args,
kwds_proxy const &kwds);
#else
void sort(object_cref cmpfunc);
#endif
protected:
list_base(); // new list
@@ -113,13 +117,15 @@ class list : public detail::list_base
base::remove(object(value));
}
#if PY_VERSION_HEX <= 0x03000000
void sort() { base::sort(); }
template <class T>
void sort(T const& value)
{
base::sort(object(value));
}
#endif
public: // implementation detail -- for internal use only
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)

4
include/boost/python/lvalue_from_pytype.hpp Executable file → Normal file
View File

@@ -63,7 +63,7 @@ struct extract_member
{
static MemberType& execute(InstanceType& c)
{
(void)c.ob_type; // static assertion
(void)Py_TYPE(&c); // static assertion
return c.*member;
}
};
@@ -75,7 +75,7 @@ struct extract_identity
{
static InstanceType& execute(InstanceType& c)
{
(void)c.ob_type; // static assertion
(void)Py_TYPE(&c); // static assertion
return c;
}
};

0
include/boost/python/make_constructor.hpp Executable file → Normal file
View File

View File

@@ -11,40 +11,49 @@
namespace boost { namespace python { namespace detail {
BOOST_PYTHON_DECL void init_module(char const* name, void(*)());
BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)());
}}}
# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE)
# if PY_VERSION_HEX >= 0x03000000
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
extern "C" __declspec(dllexport) void init##name() \
# define _BOOST_PYTHON_MODULE_INIT(name) \
PyObject* PyInit_##name() \
{ \
return boost::python::detail::init_module( \
#name,&init_module_##name); \
} \
void init_module_##name()
# else
# define _BOOST_PYTHON_MODULE_INIT(name) \
void init##name() \
{ \
boost::python::detail::init_module( \
#name,&init_module_##name); \
} \
void init_module_##name()
# endif
# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE)
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
extern "C" __declspec(dllexport) _BOOST_PYTHON_MODULE_INIT(name)
# elif BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
extern "C" __attribute__ ((visibility("default"))) void init##name() \
{ \
boost::python::detail::init_module(#name, &init_module_##name); \
} \
void init_module_##name()
extern "C" __attribute__ ((visibility("default"))) _BOOST_PYTHON_MODULE_INIT(name)
# else
# define BOOST_PYTHON_MODULE_INIT(name) \
void init_module_##name(); \
extern "C" void init##name() \
{ \
boost::python::detail::init_module(#name, &init_module_##name); \
} \
void init_module_##name()
extern "C" _BOOST_PYTHON_MODULE_INIT(name)
# endif

0
include/boost/python/object.hpp Executable file → Normal file
View File

0
include/boost/python/object/class_metadata.hpp Executable file → Normal file
View File

0
include/boost/python/object/function_doc_signature.hpp Executable file → Normal file
View File

0
include/boost/python/object/inheritance_query.hpp Executable file → Normal file
View File

View File

@@ -129,7 +129,11 @@ namespace detail
return class_<range_>(name, no_init)
.def("__iter__", identity_function())
.def(
#if PY_VERSION_HEX >= 0x03000000
"__next__"
#else
"next"
#endif
, make_function(
next_fn()
, policies

View File

@@ -43,7 +43,7 @@ struct make_instance_impl
// Note the position of the internally-stored Holder,
// for the sake of destruction
instance->ob_size = offsetof(instance_t, storage);
Py_SIZE(instance) = offsetof(instance_t, storage);
// Release ownership of the python object
protect.cancel();

0
include/boost/python/object/stl_iterator_core.hpp Executable file → Normal file
View File

View File

@@ -126,6 +126,10 @@ namespace api
const_object_objattribute attr(object const&) const;
object_objattribute attr(object const&);
// Wrap 'in' operator (aka. __contains__)
template <class T>
object contains(T const& key) const;
// item access
//
const_object_item operator[](object_cref) const;
@@ -483,6 +487,15 @@ object api::object_operators<U>::operator()(detail::args_proxy const &args,
}
template <typename U>
template <class T>
object api::object_operators<U>::contains(T const& key) const
{
return this->attr("__contains__")(object(key));
}
inline object::object()
: object_base(python::incref(Py_None))
{}

0
include/boost/python/object_items.hpp Executable file → Normal file
View File

0
include/boost/python/object_protocol.hpp Executable file → Normal file
View File

0
include/boost/python/object_protocol_core.hpp Executable file → Normal file
View File

View File

@@ -121,8 +121,7 @@ opaque<Pointee> opaque<Pointee>::instance;
template <class Pointee>
PyTypeObject opaque<Pointee>::type_object =
{
PyObject_HEAD_INIT(0)
0,
PyVarObject_HEAD_INIT(NULL, 0)
0,
sizeof( BOOST_DEDUCED_TYPENAME opaque<Pointee>::python_instance ),
0,

View File

@@ -341,7 +341,11 @@ BOOST_PYTHON_UNARY_OPERATOR(neg, -, operator-)
BOOST_PYTHON_UNARY_OPERATOR(pos, +, operator+)
BOOST_PYTHON_UNARY_OPERATOR(abs, abs, abs)
BOOST_PYTHON_UNARY_OPERATOR(invert, ~, operator~)
#if PY_VERSION_HEX >= 0x03000000
BOOST_PYTHON_UNARY_OPERATOR(bool, !!, operator!)
#else
BOOST_PYTHON_UNARY_OPERATOR(nonzero, !!, operator!)
#endif
BOOST_PYTHON_UNARY_OPERATOR(int, long, int_)
BOOST_PYTHON_UNARY_OPERATOR(long, PyLong_FromLong, long_)
BOOST_PYTHON_UNARY_OPERATOR(float, double, float_)

0
include/boost/python/other.hpp Executable file → Normal file
View File

0
include/boost/python/override.hpp Executable file → Normal file
View File

0
include/boost/python/proxy.hpp Executable file → Normal file
View File

0
include/boost/python/pure_virtual.hpp Executable file → Normal file
View File

0
include/boost/python/raw_function.hpp Executable file → Normal file
View File

0
include/boost/python/refcount.hpp Executable file → Normal file
View File

0
include/boost/python/return_arg.hpp Executable file → Normal file
View File

0
include/boost/python/self.hpp Executable file → Normal file
View File

0
include/boost/python/stl_iterator.hpp Executable file → Normal file
View File

View File

@@ -37,10 +37,12 @@ namespace detail
long count(object_cref sub, object_cref start, object_cref end) const;
#if PY_VERSION_HEX < 0x03000000
object decode() const;
object decode(object_cref encoding) const;
object decode(object_cref encoding, object_cref errors) const;
#endif
object encode() const;
object encode(object_cref encoding) const;
@@ -185,6 +187,7 @@ class str : public detail::str_base
return base::count(object(sub), object(start));
}
#if PY_VERSION_HEX < 0x03000000
object decode() const { return base::decode(); }
template<class T>
@@ -198,6 +201,7 @@ class str : public detail::str_base
{
return base::decode(object(encoding),object(errors));
}
#endif
object encode() const { return base::encode(); }
@@ -404,7 +408,11 @@ namespace converter
{
template <>
struct object_manager_traits<str>
#if PY_VERSION_HEX >= 0x03000000
: pytype_object_manager_traits<&PyUnicode_Type,str>
#else
: pytype_object_manager_traits<&PyString_Type,str>
#endif
{
};
}

0
include/boost/python/wrapper.hpp Executable file → Normal file
View File

View File

@@ -37,12 +37,20 @@ void shared_ptr_deleter::operator()(void const*)
namespace
{
// An lvalue conversion function which extracts a char const* from a
// Python String.
#if PY_VERSION_HEX < 0x03000000
void* convert_to_cstring(PyObject* obj)
{
return PyString_Check(obj) ? PyString_AsString(obj) : 0;
}
#else
void* convert_to_cstring(PyObject* obj)
{
return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;
}
#endif
// Given a target type and a SlotPolicy describing how to perform a
// given conversion, registers from_python converters which use the
@@ -90,6 +98,52 @@ namespace
}
};
// identity_unaryfunc/py_object_identity -- manufacture a unaryfunc
// "slot" which just returns its argument.
extern "C" PyObject* identity_unaryfunc(PyObject* x)
{
Py_INCREF(x);
return x;
}
unaryfunc py_object_identity = identity_unaryfunc;
#if PY_VERSION_HEX >= 0x03000000
// As in Python 3 there is only one integer type, we can have much
// simplified logic.
// XXX(bhy) maybe the code will work with 2.6 or even 2.5?
struct int_rvalue_from_python_base
{
static unaryfunc* get_slot(PyObject* obj)
{
return PyLong_Check(obj) ? &py_object_identity : 0;
}
static PyTypeObject const* get_pytype() {return &PyLong_Type;}
};
template <class T>
struct signed_int_rvalue_from_python : int_rvalue_from_python_base
{
static T extract(PyObject* intermediate)
{
long x = PyLong_AsLong(intermediate);
if (PyErr_Occurred())
throw_error_already_set();
return numeric_cast<T>(x);
}
};
template <class T>
struct unsigned_int_rvalue_from_python : int_rvalue_from_python_base
{
static T extract(PyObject* intermediate)
{
unsigned long x = PyLong_AsUnsignedLong(intermediate);
if (PyErr_Occurred())
throw_error_already_set();
return numeric_cast<T>(x);
}
};
#else // PY_VERSION_HEX >= 0x03000000
// A SlotPolicy for extracting signed integer types from Python objects
struct signed_int_rvalue_from_python_base
{
@@ -116,16 +170,7 @@ namespace
return numeric_cast<T>(x);
}
};
// identity_unaryfunc/py_object_identity -- manufacture a unaryfunc
// "slot" which just returns its argument.
extern "C" PyObject* identity_unaryfunc(PyObject* x)
{
Py_INCREF(x);
return x;
}
unaryfunc py_object_identity = identity_unaryfunc;
// A SlotPolicy for extracting unsigned integer types from Python objects
struct unsigned_int_rvalue_from_python_base
{
@@ -152,6 +197,7 @@ namespace
: PyInt_AS_LONG(intermediate));
}
};
#endif // PY_VERSION_HEX >= 0x03000000
// Checking Python's macro instead of Boost's - we don't seem to get
// the config right all the time. Furthermore, Python's is defined
@@ -164,6 +210,9 @@ namespace
{
static unaryfunc* get_slot(PyObject* obj)
{
#if PY_VERSION_HEX >= 0x03000000
return PyLong_Check(obj) ? &py_object_identity : 0;
#else
PyNumberMethods* number_methods = obj->ob_type->tp_as_number;
if (number_methods == 0)
return 0;
@@ -176,19 +225,22 @@ namespace
return &number_methods->nb_long;
else
return 0;
#endif
}
static PyTypeObject const* get_pytype() { return &PyInt_Type;}
static PyTypeObject const* get_pytype() { return &PyLong_Type;}
};
struct long_long_rvalue_from_python : long_long_rvalue_from_python_base
{
static BOOST_PYTHON_LONG_LONG extract(PyObject* intermediate)
{
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
}
else
#endif
{
BOOST_PYTHON_LONG_LONG result = PyLong_AsLongLong(intermediate);
@@ -204,11 +256,13 @@ namespace
{
static unsigned BOOST_PYTHON_LONG_LONG extract(PyObject* intermediate)
{
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AS_LONG(intermediate));
}
else
#endif
{
unsigned BOOST_PYTHON_LONG_LONG result = PyLong_AsUnsignedLongLong(intermediate);
@@ -226,7 +280,11 @@ namespace
{
static unaryfunc* get_slot(PyObject* obj)
{
#if PY_VERSION_HEX >= 0x03000000
return obj == Py_None || PyLong_Check(obj) ? &py_object_identity : 0;
#else
return obj == Py_None || PyInt_Check(obj) ? &py_object_identity : 0;
#endif
}
static bool extract(PyObject* intermediate)
@@ -255,8 +313,10 @@ namespace
// For integer types, return the tp_int conversion slot to avoid
// creating a new object. We'll handle that below
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj))
return &number_methods->nb_int;
#endif
return (PyLong_Check(obj) || PyFloat_Check(obj))
? &number_methods->nb_float : 0;
@@ -264,11 +324,13 @@ namespace
static double extract(PyObject* intermediate)
{
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
}
else
#endif
{
return PyFloat_AS_DOUBLE(intermediate);
}
@@ -276,22 +338,36 @@ namespace
static PyTypeObject const* get_pytype() { return &PyFloat_Type;}
};
unaryfunc py_unicode_as_string_unaryfunc = PyUnicode_AsUTF8String;
// A SlotPolicy for extracting C++ strings from Python objects.
struct string_rvalue_from_python
{
// If the underlying object is "string-able" this will succeed
static unaryfunc* get_slot(PyObject* obj)
{
return (PyString_Check(obj))
? &obj->ob_type->tp_str : 0;
#if PY_VERSION_HEX >= 0x03000000
return (PyUnicode_Check(obj)) ? &py_unicode_as_string_unaryfunc : 0;
#else
return (PyString_Check(obj)) ? &obj->ob_type->tp_str : 0;
#endif
};
// Remember that this will be used to construct the result object
#if PY_VERSION_HEX >= 0x03000000
static std::string extract(PyObject* intermediate)
{
return std::string(PyBytes_AsString(intermediate),PyBytes_Size(intermediate));
}
static PyTypeObject const* get_pytype() { return &PyUnicode_Type;}
#else
static std::string extract(PyObject* intermediate)
{
return std::string(PyString_AsString(intermediate),PyString_Size(intermediate));
}
static PyTypeObject const* get_pytype() { return &PyString_Type;}
#endif
};
#if defined(Py_USING_UNICODE) && !defined(BOOST_NO_STD_WSTRING)
@@ -311,7 +387,11 @@ namespace
{
return PyUnicode_Check(obj)
? &py_object_identity
#if PY_VERSION_HEX >= 0x03000000
: PyBytes_Check(obj)
#else
: PyString_Check(obj)
#endif
? &py_encode_string
: 0;
};
@@ -354,10 +434,12 @@ namespace
PyComplex_RealAsDouble(intermediate)
, PyComplex_ImagAsDouble(intermediate));
}
#if PY_VERSION_HEX < 0x03000000
else if (PyInt_Check(intermediate))
{
return PyInt_AS_LONG(intermediate);
}
#endif
else
{
return PyFloat_AS_DOUBLE(intermediate);
@@ -369,12 +451,20 @@ namespace
BOOST_PYTHON_DECL PyObject* do_return_to_python(char x)
{
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromStringAndSize(&x, 1);
#else
return PyString_FromStringAndSize(&x, 1);
#endif
}
BOOST_PYTHON_DECL PyObject* do_return_to_python(char const* x)
{
#if PY_VERSION_HEX >= 0x03000000
return x ? PyUnicode_FromString(x) : boost::python::detail::none();
#else
return x ? PyString_FromString(x) : boost::python::detail::none();
#endif
}
BOOST_PYTHON_DECL PyObject* do_return_to_python(PyObject* x)
@@ -429,13 +519,18 @@ void initialize_builtin_converters()
slot_rvalue_from_python<std::complex<long double>,complex_rvalue_from_python>();
// Add an lvalue converter for char which gets us char const*
#if PY_VERSION_HEX < 0x03000000
registry::insert(convert_to_cstring,type_id<char>(),&converter::wrap_pytype<&PyString_Type>::get_pytype);
#else
registry::insert(convert_to_cstring,type_id<char>(),&converter::wrap_pytype<&PyUnicode_Type>::get_pytype);
#endif
// Register by-value converters to std::string, std::wstring
#if defined(Py_USING_UNICODE) && !defined(BOOST_NO_STD_WSTRING)
slot_rvalue_from_python<std::wstring, wstring_rvalue_from_python>();
# endif
slot_rvalue_from_python<std::string, string_rvalue_from_python>();
}
}}} // namespace boost::python::converter

View File

@@ -96,7 +96,12 @@ BOOST_PYTHON_DECL void* rvalue_from_python_stage2(
if (!data.convertible)
{
handle<> msg(
::PyString_FromFormat(
#if PY_VERSION_HEX >= 0x03000000
::PyUnicode_FromFormat
#else
::PyString_FromFormat
#endif
(
"No registered converter was able to produce a C++ rvalue of type %s from this Python object of type %s"
, converters.target_type.name()
, source->ob_type->tp_name
@@ -196,7 +201,12 @@ namespace
void throw_no_lvalue_from_python(PyObject* source, registration const& converters, char const* ref_type)
{
handle<> msg(
::PyString_FromFormat(
#if PY_VERSION_HEX >= 0x03000000
::PyUnicode_FromFormat
#else
::PyString_FromFormat
#endif
(
"No registered converter was able to extract a C++ %s to type %s"
" from this Python object of type %s"
, ref_type
@@ -218,7 +228,12 @@ namespace
if (source->ob_refcnt <= 1)
{
handle<> msg(
::PyString_FromFormat(
#if PY_VERSION_HEX >= 0x3000000
::PyUnicode_FromFormat
#else
::PyString_FromFormat
#endif
(
"Attempt to return dangling %s to object of type: %s"
, ref_type
, converters.target_type.name()));

View File

@@ -70,7 +70,12 @@ BOOST_PYTHON_DECL PyObject* registration::to_python(void const volatile* source)
if (this->m_to_python == 0)
{
handle<> msg(
::PyString_FromFormat(
#if PY_VERSION_HEX >= 0x3000000
::PyUnicode_FromFormat
#else
::PyString_FromFormat
#endif
(
"No to_python (by-value) converter found for C++ type: %s"
, this->target_type.name()
)

View File

@@ -84,7 +84,7 @@ object dict_base::get(object_cref k, object_cref d) const
bool dict_base::has_key(object_cref k) const
{
return extract<bool>(this->attr("has_key")(k));
return extract<bool>(this->contains(k));
}
list dict_base::items() const

View File

@@ -38,11 +38,19 @@ 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);
#if PY_VERSION_HEX >= 0x03000000
// TODO(bhy) temporary workaround for Python 3.
// should figure out a way to avoid binary incompatibilities as the Python 2
// version did.
FILE *fs = fopen(f, "r");
#else
// Let python open the file to avoid potential binary incompatibilities.
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()),
FILE *fs = PyFile_AsFile(file.get());
#endif
PyObject* result = PyRun_File(fs,
f,
Py_file_input,
global.ptr(), local.ptr());

View File

@@ -48,7 +48,11 @@ void list_base::extend(object_cref sequence)
long list_base::index(object_cref value) const
{
object result_obj(this->attr("index")(value));
#if PY_VERSION_HEX >= 0x03000000
ssize_t result = PyLong_AsSsize_t(result_obj.ptr());
#else
long result = PyInt_AsLong(result_obj.ptr());
#endif
if (result == -1)
throw_error_already_set();
return result;
@@ -69,7 +73,11 @@ void list_base::insert(ssize_t index, object_cref item)
void list_base::insert(object const& index, object_cref x)
{
#if PY_VERSION_HEX >= 0x03000000
ssize_t index_ = PyLong_AsSsize_t(index.ptr());
#else
long index_ = PyInt_AsLong(index.ptr());
#endif
if (index_ == -1 && PyErr_Occurred())
throw_error_already_set();
this->insert(index_, x);
@@ -121,17 +129,29 @@ void list_base::sort()
}
}
#if PY_VERSION_HEX >= 0x03000000
void list_base::sort(args_proxy const &args,
kwds_proxy const &kwds)
{
this->attr("sort")(args, kwds);
}
#else
void list_base::sort(object_cref cmpfunc)
{
this->attr("sort")(cmpfunc);
}
#endif
// For some reason, moving this to the end of the TU suppresses an ICE
// with vc6.
long list_base::count(object_cref value) const
Py_ssize_t list_base::count(object_cref value) const
{
object result_obj(this->attr("count")(value));
#if PY_VERSION_HEX >= 0x03000000
Py_ssize_t result = PyLong_AsSsize_t(result_obj.ptr());
#else
long result = PyInt_AsLong(result_obj.ptr());
#endif
if (result == -1)
throw_error_already_set();
return result;

Some files were not shown because too many files have changed in this diff Show More