mirror of
https://github.com/boostorg/python.git
synced 2026-01-21 17:12:22 +00:00
Compare commits
204 Commits
boost-1.42
...
sandbox-br
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36cda0a8c8 | ||
|
|
5c49d45f34 | ||
|
|
1210f54233 | ||
|
|
067d9da915 | ||
|
|
07abe23ae4 | ||
|
|
f7c5139fe3 | ||
|
|
fed453563a | ||
|
|
7bf964b1ce | ||
|
|
e428495a96 | ||
|
|
5e68c24f10 | ||
|
|
f1ee4a4b86 | ||
|
|
b4dbda873a | ||
|
|
db78e5242f | ||
|
|
3dff5215cd | ||
|
|
0536dad8ab | ||
|
|
c6bb65197f | ||
|
|
a272bb801a | ||
|
|
3a75666f22 | ||
|
|
ff0e58d30d | ||
|
|
c4c7fe6dc0 | ||
|
|
ec4a1df1e0 | ||
|
|
5f7eaa4617 | ||
|
|
3f536cc0c0 | ||
|
|
b934253848 | ||
|
|
c219ae50c4 | ||
|
|
28c7185654 | ||
|
|
7beda2e192 | ||
|
|
1370f36d45 | ||
|
|
06aca4c52d | ||
|
|
15f4a59969 | ||
|
|
9b06248e81 | ||
|
|
4e0a826b50 | ||
|
|
58f1684885 | ||
|
|
eea11df1ea | ||
|
|
6fe34b46d4 | ||
|
|
e33ce235a8 | ||
|
|
caf661cfeb | ||
|
|
86f44ed159 | ||
|
|
e73277e156 | ||
|
|
92f07fc4d6 | ||
|
|
99737170f8 | ||
|
|
ce3992ce52 | ||
|
|
60ed8e57c1 | ||
|
|
41bcac0369 | ||
|
|
a0f61cdfd1 | ||
|
|
98a9fa445b | ||
|
|
354fbb4d24 | ||
|
|
472b18881b | ||
|
|
96798a3a38 | ||
|
|
7d2f44b21e | ||
|
|
5cda75ebe7 | ||
|
|
6347f2e86c | ||
|
|
97f3d849df | ||
|
|
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 |
80
CMakeLists.txt
Normal file
80
CMakeLists.txt
Normal file
@@ -0,0 +1,80 @@
|
||||
if (PYTHON_LIBRARIES)
|
||||
include_directories(${PYTHON_INCLUDE_PATH})
|
||||
|
||||
# Determine extra libraries we need to link against to build Python
|
||||
# extension modules.
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "dl")
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "rt")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSD")
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "pthread")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
|
||||
# DragonFly is a variant of FreeBSD
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "pthread")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "OSF")
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "pthread" "dl")
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "rt")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "QNX")
|
||||
# No options necessary for QNX
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
# No options necessary for Mac OS X
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "rt")
|
||||
elseif(UNIX)
|
||||
# Assume -pthread and -ldl on all other variants
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "pthread" "dl")
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} "util")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
endif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
|
||||
|
||||
################################################################################
|
||||
#-- Macro for building Boost.Python extension modules
|
||||
macro(boost_python_extension MODULE_NAME)
|
||||
parse_arguments(BPL_EXT
|
||||
""
|
||||
""
|
||||
${ARGN})
|
||||
|
||||
#TODO: The target properties are NOT being set correctly for the test libraries
|
||||
if (FALSE)
|
||||
# Create the library target itself
|
||||
add_library(${MODULE_NAME} MODULE ${BPL_EXT_DEFAULT_ARGS} )
|
||||
|
||||
# Miscellaneous target properties
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
# Link against Boost.Python library
|
||||
target_link_libraries(${MODULE_NAME} boost_python-static)
|
||||
|
||||
# Link against Python libraries
|
||||
target_link_libraries(${MODULE_NAME} ${PYTHON_LIBRARIES})
|
||||
endif(FALSE)
|
||||
|
||||
boost_add_library(
|
||||
${MODULE_NAME}
|
||||
${BPL_EXT_DEFAULT_ARGS}
|
||||
MODULE
|
||||
LINK_LIBS ${PYTHON_LIBRARIES}
|
||||
DEPENDS boost_python
|
||||
)
|
||||
|
||||
endmacro(boost_python_extension)
|
||||
#--
|
||||
################################################################################
|
||||
|
||||
|
||||
boost_library_project(
|
||||
Python
|
||||
SRCDIRS src
|
||||
TESTDIRS test
|
||||
HEADERS python.hpp python
|
||||
MODULARIZED
|
||||
DESCRIPTION "A framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ classes functions and objects to Python, and vice-versa, using no special tools -- just your C++ compiler."
|
||||
AUTHORS "David Abrahams <dave -at- boostpro.com>"
|
||||
)
|
||||
endif (PYTHON_LIBRARIES)
|
||||
@@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Chapter 1. python 2.0</title>
|
||||
<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.66.1">
|
||||
<link rel="start" href="index.html" title="Chapter 1. python 1.0">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[library python
|
||||
[version 2.0]
|
||||
[version 1.0]
|
||||
[authors [de Guzman, Joel], [Abrahams, David]]
|
||||
[copyright 2002 2003 2004 2005 Joel de Guzman, David Abrahams]
|
||||
[category inter-language support]
|
||||
@@ -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]
|
||||
|
||||
@@ -2,15 +2,6 @@
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import python ;
|
||||
|
||||
if ! [ python.configured ]
|
||||
{
|
||||
ECHO "notice: no Python configured in user-config.jam" ;
|
||||
ECHO "notice: will use default configuration" ;
|
||||
using python ;
|
||||
}
|
||||
|
||||
# Specify the path to the Boost project. If you move this project,
|
||||
# adjust this path to refer to the Boost root directory.
|
||||
use-project boost
|
||||
|
||||
@@ -55,8 +55,8 @@ inline decorated_type_info::decorated_type_info(type_info base_t, decoration dec
|
||||
inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| (m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type);
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
// 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)
|
||||
#ifndef TRANSLATE_EXCEPTION_TDS20091020_HPP
|
||||
# define TRANSLATE_EXCEPTION_TDS20091020_HPP
|
||||
#ifndef TRANSLATE_EXCEPTION_DWA2002810_HPP
|
||||
# define TRANSLATE_EXCEPTION_DWA2002810_HPP
|
||||
|
||||
# include <boost/python/detail/exception_handler.hpp>
|
||||
|
||||
# include <boost/call_traits.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
# include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
# include <boost/function/function0.hpp>
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ inline enum_<T>::enum_(char const* name, char const* doc )
|
||||
, &enum_<T>::convertible_from_python
|
||||
, &enum_<T>::construct
|
||||
, type_id<T>()
|
||||
, doc
|
||||
, doc
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,13 +20,6 @@ object
|
||||
BOOST_PYTHON_DECL
|
||||
eval(str string, object global = object(), object local = object());
|
||||
|
||||
// Execute an individual python statement from str.
|
||||
// global and local are the global and local scopes respectively,
|
||||
// used during execution.
|
||||
object
|
||||
BOOST_PYTHON_DECL
|
||||
exec_statement(str string, object global = object(), object local = object());
|
||||
|
||||
// Execute python source code from str.
|
||||
// global and local are the global and local scopes respectively,
|
||||
// used during execution.
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace detail
|
||||
{
|
||||
void append(object_cref); // append object to end
|
||||
|
||||
ssize_t 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
|
||||
|
||||
|
||||
@@ -105,12 +105,12 @@ namespace detail
|
||||
// If the BasePolicy_ supplied a result converter it would be
|
||||
// ignored; issue an error if it's not the default.
|
||||
#if defined _MSC_VER && _MSC_VER < 1300
|
||||
typedef is_same<
|
||||
typedef is_same<
|
||||
typename BasePolicy_::result_converter
|
||||
, default_result_converter
|
||||
> same_result_converter;
|
||||
//see above for explanation
|
||||
BOOST_STATIC_ASSERT(same_result_converter::value) ;
|
||||
//see above for explanation
|
||||
BOOST_STATIC_ASSERT(same_result_converter::value) ;
|
||||
#else
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(is_same<
|
||||
|
||||
@@ -60,9 +60,7 @@ inline
|
||||
object_operators<U>::operator bool_type() const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
int is_true = PyObject_IsTrue(x.ptr());
|
||||
if (is_true < 0) throw_error_already_set();
|
||||
return is_true ? &object::ptr : 0;
|
||||
return PyObject_IsTrue(x.ptr()) ? &object::ptr : 0;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -70,9 +68,7 @@ inline bool
|
||||
object_operators<U>::operator!() const
|
||||
{
|
||||
object_cref2 x = *static_cast<U const*>(this);
|
||||
int is_true = PyObject_IsTrue(x.ptr());
|
||||
if (is_true < 0) throw_error_already_set();
|
||||
return !is_true;
|
||||
return !PyObject_IsTrue(x.ptr());
|
||||
}
|
||||
|
||||
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
|
||||
|
||||
3
module.cmake
Normal file
3
module.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
boost_module(python DEPENDS graph numeric)
|
||||
|
||||
# numeric is there because of boost/cast.hpp from libs/python/src/errors.cpp:11
|
||||
64
src/CMakeLists.txt
Normal file
64
src/CMakeLists.txt
Normal file
@@ -0,0 +1,64 @@
|
||||
if (PYTHON_DEBUG_LIBRARIES AND BUILD_BOOST_PYTHON)
|
||||
# We have detected that there might be Python debug libraries
|
||||
# available, but check for ourselves whether this is true by trying
|
||||
# to compile/link a program against them.
|
||||
set(CMAKE_REQUIRED_DEFINITIONS "-DBOOST_DEBUG_PYTHON -DPy_DEBUG")
|
||||
get_directory_property(CMAKE_REQUIRED_INCLUDES INCLUDE_DIRECTORIES)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${PYTHON_DEBUG_LIBRARIES})
|
||||
set(CHECK_PYDEBUG_SOURCE
|
||||
"#include <boost/python/object.hpp>")
|
||||
check_cxx_source_compiles(
|
||||
"#include <boost/python/object.hpp>
|
||||
void check(PyObject *obj) { Py_INCREF(obj); } int main() { }"
|
||||
PYDEBUG_CAN_BUILD)
|
||||
|
||||
# Setup an option to enable/disable building variants with Python
|
||||
# debugging. If we were able to link against the debug libraries,
|
||||
# default to ON; otherwise, default to OFF.
|
||||
option(BUILD_PYTHON_DEBUG
|
||||
"Build an additional Boost.Python library with Python debugging enabled"
|
||||
${PYDEBUG_CAN_BUILD})
|
||||
endif (PYTHON_DEBUG_LIBRARIES AND BUILD_BOOST_PYTHON)
|
||||
|
||||
# Always build the non-debug variants of the boost_python library
|
||||
set(BUILD_PYTHON_NODEBUG ON)
|
||||
|
||||
boost_add_library(boost_python
|
||||
numeric.cpp
|
||||
list.cpp
|
||||
long.cpp
|
||||
dict.cpp
|
||||
tuple.cpp
|
||||
str.cpp
|
||||
slice.cpp
|
||||
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
|
||||
|
||||
STATIC_COMPILE_FLAGS "-DBOOST_PYTHON_SOURCE -DBOOST_PYTHON_STATIC_LIB"
|
||||
SHARED_COMPILE_FLAGS "-DBOOST_PYTHON_SOURCE"
|
||||
PYTHON_NODEBUG_LINK_LIBS "${PYTHON_LIBRARIES}"
|
||||
|
||||
# Support for Python debugging
|
||||
EXTRA_VARIANTS PYTHON_NODEBUG:PYTHON_DEBUG
|
||||
PYTHON_DEBUG_COMPILE_FLAGS "-DBOOST_DEBUG_PYTHON -DPy_DEBUG"
|
||||
PYTHON_DEBUG_LINK_LIBS "${PYTHON_DEBUG_LIBRARIES}"
|
||||
)
|
||||
@@ -153,13 +153,8 @@ namespace
|
||||
if (number_methods == 0)
|
||||
return 0;
|
||||
|
||||
return (
|
||||
#if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT)
|
||||
!PyBool_Check(obj) &&
|
||||
#endif
|
||||
(PyInt_Check(obj) || PyLong_Check(obj)))
|
||||
|
||||
? &number_methods->nb_int : 0;
|
||||
return (PyInt_Check(obj) || PyLong_Check(obj))
|
||||
? &number_methods->nb_int : 0;
|
||||
}
|
||||
static PyTypeObject const* get_pytype() { return &PyInt_Type;}
|
||||
};
|
||||
@@ -185,11 +180,7 @@ namespace
|
||||
if (number_methods == 0)
|
||||
return 0;
|
||||
|
||||
return (
|
||||
#if PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT)
|
||||
!PyBool_Check(obj) &&
|
||||
#endif
|
||||
(PyInt_Check(obj) || PyLong_Check(obj)))
|
||||
return (PyInt_Check(obj) || PyLong_Check(obj))
|
||||
? &py_object_identity : 0;
|
||||
}
|
||||
static PyTypeObject const* get_pytype() { return &PyInt_Type;}
|
||||
@@ -200,27 +191,10 @@ namespace
|
||||
{
|
||||
static T extract(PyObject* intermediate)
|
||||
{
|
||||
if (PyLong_Check(intermediate)) {
|
||||
// PyLong_AsUnsignedLong() checks for negative overflow, so no
|
||||
// need to check it here.
|
||||
unsigned long result = PyLong_AsUnsignedLong(intermediate);
|
||||
if (PyErr_Occurred())
|
||||
throw_error_already_set();
|
||||
return numeric_cast<T>(result);
|
||||
} else {
|
||||
// None of PyInt_AsUnsigned*() functions check for negative
|
||||
// overflow, so use PyInt_AS_LONG instead and check if number is
|
||||
// negative, issuing the exception appropriately.
|
||||
long result = PyInt_AS_LONG(intermediate);
|
||||
if (PyErr_Occurred())
|
||||
throw_error_already_set();
|
||||
if (result < 0) {
|
||||
PyErr_SetString(PyExc_OverflowError, "can't convert negative"
|
||||
" value to unsigned");
|
||||
throw_error_already_set();
|
||||
}
|
||||
return numeric_cast<T>(result);
|
||||
}
|
||||
return numeric_cast<T>(
|
||||
PyLong_Check(intermediate)
|
||||
? PyLong_AsUnsignedLong(intermediate)
|
||||
: PyInt_AS_LONG(intermediate));
|
||||
}
|
||||
};
|
||||
#endif // PY_VERSION_HEX >= 0x03000000
|
||||
@@ -308,8 +282,6 @@ namespace
|
||||
{
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
return obj == Py_None || PyLong_Check(obj) ? &py_object_identity : 0;
|
||||
#elif PY_VERSION_HEX >= 0x02040000 && defined(BOOST_PYTHON_BOOL_INT_STRICT)
|
||||
return obj == Py_None || PyBool_Check(obj) ? &py_object_identity : 0;
|
||||
#else
|
||||
return obj == Py_None || PyInt_Check(obj) ? &py_object_identity : 0;
|
||||
#endif
|
||||
|
||||
50
src/exec.cpp
50
src/exec.cpp
@@ -5,7 +5,6 @@
|
||||
|
||||
#include <boost/python/exec.hpp>
|
||||
#include <boost/python/borrowed.hpp>
|
||||
#include <boost/python/dict.hpp>
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/handle.hpp>
|
||||
|
||||
@@ -16,16 +15,6 @@ namespace python
|
||||
|
||||
object BOOST_PYTHON_DECL eval(str string, object global, object local)
|
||||
{
|
||||
// Set suitable default values for global and local dicts.
|
||||
object none;
|
||||
if (global.ptr() == none.ptr())
|
||||
{
|
||||
if (PyObject *g = PyEval_GetGlobals())
|
||||
global = object(detail::borrowed_reference(g));
|
||||
else
|
||||
global = dict();
|
||||
}
|
||||
if (local.ptr() == none.ptr()) local = global;
|
||||
// should be 'char const *' but older python versions don't use 'const' yet.
|
||||
char *s = python::extract<char *>(string);
|
||||
PyObject* result = PyRun_String(s, Py_eval_input, global.ptr(), local.ptr());
|
||||
@@ -35,16 +24,6 @@ object BOOST_PYTHON_DECL eval(str string, object global, object local)
|
||||
|
||||
object BOOST_PYTHON_DECL exec(str string, object global, object local)
|
||||
{
|
||||
// Set suitable default values for global and local dicts.
|
||||
object none;
|
||||
if (global.ptr() == none.ptr())
|
||||
{
|
||||
if (PyObject *g = PyEval_GetGlobals())
|
||||
global = object(detail::borrowed_reference(g));
|
||||
else
|
||||
global = dict();
|
||||
}
|
||||
if (local.ptr() == none.ptr()) local = global;
|
||||
// should be 'char const *' but older python versions don't use 'const' yet.
|
||||
char *s = python::extract<char *>(string);
|
||||
PyObject* result = PyRun_String(s, Py_file_input, global.ptr(), local.ptr());
|
||||
@@ -52,40 +31,11 @@ object BOOST_PYTHON_DECL exec(str string, object global, object local)
|
||||
return object(detail::new_reference(result));
|
||||
}
|
||||
|
||||
object BOOST_PYTHON_DECL exec_statement(str string, object global, object local)
|
||||
{
|
||||
// Set suitable default values for global and local dicts.
|
||||
object none;
|
||||
if (global.ptr() == none.ptr())
|
||||
{
|
||||
if (PyObject *g = PyEval_GetGlobals())
|
||||
global = object(detail::borrowed_reference(g));
|
||||
else
|
||||
global = dict();
|
||||
}
|
||||
if (local.ptr() == none.ptr()) local = global;
|
||||
// should be 'char const *' but older python versions don't use 'const' yet.
|
||||
char *s = python::extract<char *>(string);
|
||||
PyObject* result = PyRun_String(s, Py_single_input, global.ptr(), local.ptr());
|
||||
if (!result) throw_error_already_set();
|
||||
return object(detail::new_reference(result));
|
||||
}
|
||||
|
||||
// Execute python source code from file filename.
|
||||
// global and local are the global and local scopes respectively,
|
||||
// used during execution.
|
||||
object BOOST_PYTHON_DECL exec_file(str filename, object global, object local)
|
||||
{
|
||||
// Set suitable default values for global and local dicts.
|
||||
object none;
|
||||
if (global.ptr() == none.ptr())
|
||||
{
|
||||
if (PyObject *g = PyEval_GetGlobals())
|
||||
global = object(detail::borrowed_reference(g));
|
||||
else
|
||||
global = dict();
|
||||
}
|
||||
if (local.ptr() == none.ptr()) local = global;
|
||||
// should be 'char const *' but older python versions don't use 'const' yet.
|
||||
char *f = python::extract<char *>(filename);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
|
||||
@@ -144,11 +144,11 @@ void list_base::sort(object_cref cmpfunc)
|
||||
|
||||
// For some reason, moving this to the end of the TU suppresses an ICE
|
||||
// with vc6.
|
||||
ssize_t 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
|
||||
ssize_t result = PyLong_AsSsize_t(result_obj.ptr());
|
||||
Py_ssize_t result = PyLong_AsSsize_t(result_obj.ptr());
|
||||
#else
|
||||
long result = PyInt_AsLong(result_obj.ptr());
|
||||
#endif
|
||||
|
||||
@@ -182,7 +182,7 @@ static PyTypeObject static_data_object = {
|
||||
0, /* tp_alloc */
|
||||
0, // filled in with type_new /* tp_new */
|
||||
0, // filled in with __PyObject_GC_Del /* tp_free */
|
||||
0, /* tp_is_gc */
|
||||
(inquiry)type_is_gc, /* tp_is_gc */
|
||||
0, /* tp_bases */
|
||||
0, /* tp_mro */
|
||||
0, /* tp_cache */
|
||||
@@ -355,7 +355,7 @@ namespace objects
|
||||
PyObject* d = type_->tp_dict;
|
||||
PyObject* instance_size_obj = PyObject_GetAttrString(d, const_cast<char*>("__instance_size__"));
|
||||
|
||||
ssize_t instance_size = instance_size_obj ?
|
||||
Py_ssize_t instance_size = instance_size_obj ?
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyLong_AsSsize_t(instance_size_obj) : 0;
|
||||
#else
|
||||
@@ -552,12 +552,13 @@ namespace objects
|
||||
// Build a tuple of the base Python type objects. If no bases
|
||||
// were declared, we'll use our class_type() as the single base
|
||||
// class.
|
||||
ssize_t const num_bases = (std::max)(num_types - 1, static_cast<std::size_t>(1));
|
||||
handle<> bases(PyTuple_New(num_bases));
|
||||
std::size_t const num_bases = (std::max)(num_types - 1, static_cast<std::size_t>(1));
|
||||
assert(num_bases <= ssize_t_max);
|
||||
handle<> bases(PyTuple_New(static_cast<ssize_t>(num_bases)));
|
||||
|
||||
for (ssize_t i = 1; i <= num_bases; ++i)
|
||||
for (std::size_t i = 1; i <= num_bases; ++i)
|
||||
{
|
||||
type_handle c = (i >= static_cast<ssize_t>(num_types)) ? class_type() : get_class(types[i]);
|
||||
type_handle c = (i >= num_types) ? class_type() : get_class(types[i]);
|
||||
// PyTuple_SET_ITEM steals this reference
|
||||
PyTuple_SET_ITEM(bases.get(), static_cast<ssize_t>(i - 1), upcast<PyObject>(c.release()));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <boost/python/object_protocol.hpp>
|
||||
#include <structmember.h>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
struct enum_object
|
||||
{
|
||||
@@ -51,6 +51,7 @@ extern "C"
|
||||
}
|
||||
else
|
||||
{
|
||||
//char* name = PyString_AsString(self->name);
|
||||
PyObject* name = self->name;
|
||||
if (name == 0)
|
||||
return 0;
|
||||
@@ -165,16 +166,15 @@ namespace
|
||||
dict d;
|
||||
d["__slots__"] = tuple();
|
||||
d["values"] = dict();
|
||||
d["names"] = dict();
|
||||
|
||||
object module_name = module_prefix();
|
||||
if (module_name)
|
||||
d["__module__"] = module_name;
|
||||
if (doc)
|
||||
d["__doc__"] = doc;
|
||||
|
||||
|
||||
object result = (object(metatype))(name, make_tuple(base), d);
|
||||
|
||||
|
||||
scope().attr(name) = result;
|
||||
|
||||
return result;
|
||||
@@ -194,7 +194,7 @@ enum_base::enum_base(
|
||||
converter::registration& converters
|
||||
= const_cast<converter::registration&>(
|
||||
converter::registry::lookup(id));
|
||||
|
||||
|
||||
converters.m_class_object = downcast<PyTypeObject>(this->ptr());
|
||||
converter::registry::insert(to_python, id);
|
||||
converter::registry::insert(convertible, construct, id);
|
||||
@@ -213,24 +213,23 @@ void enum_base::add_value(char const* name_, long value)
|
||||
|
||||
dict d = extract<dict>(this->attr("values"))();
|
||||
d[value] = x;
|
||||
|
||||
|
||||
// Set the name field in the new enum instanec
|
||||
enum_object* p = downcast<enum_object>(x.ptr());
|
||||
Py_XDECREF(p->name);
|
||||
p->name = incref(name.ptr());
|
||||
|
||||
dict names_dict = extract<dict>(this->attr("names"))();
|
||||
names_dict[x.attr("name")] = x;
|
||||
}
|
||||
|
||||
void enum_base::export_values()
|
||||
{
|
||||
dict d = extract<dict>(this->attr("names"))();
|
||||
list items = d.items();
|
||||
dict d = extract<dict>(this->attr("values"))();
|
||||
list values = d.values();
|
||||
scope current;
|
||||
|
||||
for (unsigned i = 0, max = len(items); i < max; ++i)
|
||||
api::setattr(current, items[i][0], items[i][1]);
|
||||
|
||||
for (unsigned i = 0, max = len(values); i < max; ++i)
|
||||
{
|
||||
api::setattr(current, object(values[i].attr("name")), values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* enum_base::to_python(PyTypeObject* type_, long x)
|
||||
|
||||
@@ -166,7 +166,7 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const
|
||||
else
|
||||
{
|
||||
// build a new arg tuple, will adjust its size later
|
||||
assert(max_arity <= static_cast<std::size_t>(ssize_t_max));
|
||||
assert(max_arity <= ssize_t_max);
|
||||
inner_args = handle<>(
|
||||
PyTuple_New(static_cast<ssize_t>(max_arity)));
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// boost::python::make_tuple below are for gcc 4.4 -std=c++0x compatibility
|
||||
// (Intel C++ 10 and 11 with -std=c++0x don't need the full qualification).
|
||||
|
||||
#include <boost/python/converter/registrations.hpp>
|
||||
#include <boost/python/object/function_doc_signature.hpp>
|
||||
#include <boost/python/errors.hpp>
|
||||
@@ -15,6 +12,7 @@
|
||||
|
||||
#include <boost/python/detail/signature.hpp>
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
@@ -54,9 +52,9 @@ namespace boost { namespace python { namespace objects {
|
||||
//check if the argument default values are the same
|
||||
bool f1_has_names = bool(f1->m_arg_names);
|
||||
bool f2_has_names = bool(f2->m_arg_names);
|
||||
if ( (f1_has_names && f2_has_names && f2->m_arg_names[i-1]!=f1->m_arg_names[i-1])
|
||||
|| (f1_has_names && !f2_has_names)
|
||||
|| (!f1_has_names && f2_has_names && f2->m_arg_names[i-1]!=python::object())
|
||||
if ( f1_has_names && f2_has_names && f2->m_arg_names[i-1]!=f1->m_arg_names[i-1]
|
||||
|| f1_has_names && !f2_has_names
|
||||
|| !f1_has_names && f2_has_names && f2->m_arg_names[i-1]!=python::object()
|
||||
)
|
||||
return false;
|
||||
}
|
||||
@@ -230,7 +228,7 @@ namespace boost { namespace python { namespace objects {
|
||||
{
|
||||
return str(
|
||||
"%s %s(%s%s%s%s)"
|
||||
% boost::python::make_tuple // workaround, see top
|
||||
% make_tuple
|
||||
( ret_type
|
||||
, f->m_name
|
||||
, str(",").join(formal_params.slice(0,arity-n_overloads))
|
||||
@@ -241,7 +239,7 @@ namespace boost { namespace python { namespace objects {
|
||||
}else{
|
||||
return str(
|
||||
"%s(%s%s%s%s) -> %s"
|
||||
% boost::python::make_tuple // workaround, see top
|
||||
% make_tuple
|
||||
( f->m_name
|
||||
, str(",").join(formal_params.slice(0,arity-n_overloads))
|
||||
, n_overloads ? (n_overloads!=arity?str(" [,"):str("[ ")) : str()
|
||||
@@ -253,7 +251,7 @@ namespace boost { namespace python { namespace objects {
|
||||
|
||||
return str(
|
||||
"%s %s(%s%s%s%s) %s"
|
||||
% boost::python::make_tuple // workaround, see top
|
||||
% make_tuple
|
||||
( cpp_types?ret_type:str("")
|
||||
, f->m_name
|
||||
, str(",").join(formal_params.slice(0,arity-n_overloads))
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#endif
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include <boost/graph/reverse_graph.hpp>
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/property_map.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/integer_traits.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace {
|
||||
|
||||
ssize_t str_size_as_py_ssize_t(std::size_t n)
|
||||
{
|
||||
if (n > static_cast<std::size_t>(ssize_t_max))
|
||||
if (n > ssize_t_max)
|
||||
{
|
||||
throw std::range_error("str size > ssize_t_max");
|
||||
}
|
||||
|
||||
194
test/CMakeLists.txt
Normal file
194
test/CMakeLists.txt
Normal file
@@ -0,0 +1,194 @@
|
||||
macro(bpl_test TESTNAME)
|
||||
parse_arguments(BPL_TEST
|
||||
"ARGS"
|
||||
""
|
||||
${ARGN})
|
||||
|
||||
# Determine the Python and C++ source files for this test
|
||||
if (BPL_TEST_DEFAULT_ARGS)
|
||||
# First argument is the Python source we will run, the rest are
|
||||
# either extra Python sources we're dependent on or C++ files from
|
||||
# which we will build extension modules.
|
||||
car(BPL_TEST_PYSOURCE ${BPL_TEST_DEFAULT_ARGS})
|
||||
cdr(BPL_TEST_DEFAULT_ARGS ${BPL_TEST_DEFAULT_ARGS})
|
||||
|
||||
get_filename_component(BPL_TEST_PYBASE ${BPL_TEST_PYSOURCE} NAME_WE)
|
||||
foreach(SRC ${BPL_TEST_DEFAULT_ARGS})
|
||||
get_filename_component(BPL_SRC_EXT ${SRC} EXT)
|
||||
if (BPL_SRC_EXT STREQUAL ".cpp")
|
||||
# Build a Python extension module from this source file
|
||||
get_filename_component(BPL_SRC_NAME ${SRC} NAME_WE)
|
||||
if(BPL_TEST_PYBASE STREQUAL "${BPL_SRC_NAME}")
|
||||
boost_python_extension(${BPL_SRC_NAME}_ext ${SRC})
|
||||
else(BPL_TEST_PYBASE STREQUAL "${BPL_SRC_NAME}")
|
||||
boost_python_extension(${BPL_SRC_NAME} ${SRC})
|
||||
endif(BPL_TEST_PYBASE STREQUAL "${BPL_SRC_NAME}")
|
||||
endif (BPL_SRC_EXT STREQUAL ".cpp")
|
||||
endforeach(SRC ${BPL_TEST_DEFAULT_ARGS})
|
||||
else (BPL_TEST_DEFAULT_ARGS)
|
||||
set(BPL_TEST_PYSOURCE "${TESTNAME}.py")
|
||||
|
||||
# Build a Python extension module from this source file
|
||||
boost_python_extension(${TESTNAME}_ext "${TESTNAME}.cpp")
|
||||
endif(BPL_TEST_DEFAULT_ARGS)
|
||||
|
||||
# We'll need the full patch to run the Python test
|
||||
set(BPL_TEST_PYSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${BPL_TEST_PYSOURCE})
|
||||
|
||||
# Run the test itself
|
||||
file(TO_NATIVE_PATH "${LIBRARY_OUTPUT_PATH}" PYTHONPATH)
|
||||
if(WIN32 AND NOT UNIX)
|
||||
string(REPLACE "\\" "\\\\" PYTHONPATH "${PYTHONPATH}")
|
||||
endif(WIN32 AND NOT UNIX)
|
||||
add_test("${PROJECT_NAME}::${TESTNAME}"
|
||||
${PYTHON_EXECUTABLE}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pyrun.py"
|
||||
"${PYTHONPATH}"
|
||||
${BPL_TEST_PYSOURCE} ${BPL_TEST_ARGS})
|
||||
endmacro(bpl_test)
|
||||
|
||||
macro(py_run TESTNAME)
|
||||
boost_test_run(${TESTNAME}
|
||||
${TESTNAME}.cpp
|
||||
DEPENDS boost_python STATIC
|
||||
LINK_LIBS ${PYTHON_LIBRARIES})
|
||||
endmacro(py_run)
|
||||
|
||||
boost_test_run(exec
|
||||
DEPENDS boost_python STATIC
|
||||
ARGS "${CMAKE_CURRENT_SOURCE_DIR}/exec.py"
|
||||
LINK_LIBS ${PYTHON_LIBRARIES})
|
||||
boost_test_run(exec-dynamic
|
||||
exec.cpp
|
||||
ARGS "${CMAKE_CURRENT_SOURCE_DIR}/exec.py"
|
||||
DEPENDS boost_python SHARED
|
||||
LINK_LIBS ${PYTHON_LIBRARIES})
|
||||
|
||||
bpl_test(crossmod_exception
|
||||
crossmod_exception.py crossmod_exception_a.cpp crossmod_exception_b.cpp)
|
||||
|
||||
bpl_test(injected)
|
||||
bpl_test(properties)
|
||||
bpl_test(return_arg)
|
||||
bpl_test(staticmethod)
|
||||
bpl_test(shared_ptr)
|
||||
bpl_test(andreas_beyer)
|
||||
bpl_test(polymorphism)
|
||||
bpl_test(polymorphism2)
|
||||
|
||||
bpl_test(wrapper_held_type)
|
||||
bpl_test(polymorphism2_auto_ptr)
|
||||
|
||||
bpl_test(auto_ptr)
|
||||
|
||||
bpl_test(minimal)
|
||||
bpl_test(args)
|
||||
bpl_test(raw_ctor)
|
||||
bpl_test(numpy numpy.py printer.py numeric_tests.py numarray_tests.py numpy.cpp)
|
||||
bpl_test(enum)
|
||||
bpl_test(exception_translator)
|
||||
bpl_test(pearu1 test_cltree.py cltree.cpp)
|
||||
bpl_test(try newtest.py m1.cpp m2.cpp)
|
||||
bpl_test(const_argument)
|
||||
bpl_test(keywords keywords_test.py keywords.cpp)
|
||||
|
||||
boost_python_extension(builtin_converters_ext test_builtin_converters.cpp)
|
||||
bpl_test(builtin_converters test_builtin_converters.py builtin_converters_ext)
|
||||
|
||||
bpl_test(test_pointer_adoption)
|
||||
bpl_test(operators)
|
||||
bpl_test(callbacks)
|
||||
bpl_test(defaults)
|
||||
|
||||
bpl_test(object)
|
||||
bpl_test(list)
|
||||
bpl_test(long)
|
||||
bpl_test(dict)
|
||||
bpl_test(tuple)
|
||||
bpl_test(str)
|
||||
bpl_test(slice)
|
||||
|
||||
bpl_test(virtual_functions)
|
||||
bpl_test(back_reference)
|
||||
bpl_test(implicit)
|
||||
bpl_test(data_members)
|
||||
|
||||
bpl_test(ben_scott1)
|
||||
|
||||
bpl_test(bienstman1)
|
||||
bpl_test(bienstman2)
|
||||
bpl_test(bienstman3)
|
||||
|
||||
bpl_test(multi_arg_constructor)
|
||||
# TODO: A bug in the Win32 intel compilers causes compilation of one
|
||||
# of our tests to take forever when debug symbols are
|
||||
# enabled. This rule turns them off when added to the requirements
|
||||
# section
|
||||
# <toolset>intel-win:<debug-symbols>off
|
||||
|
||||
bpl_test(iterator iterator.py iterator.cpp input_iterator.cpp)
|
||||
|
||||
bpl_test(stl_iterator stl_iterator.py stl_iterator.cpp)
|
||||
|
||||
bpl_test(extract)
|
||||
|
||||
bpl_test (crossmod_opaque
|
||||
crossmod_opaque.py crossmod_opaque_a.cpp crossmod_opaque_b.cpp)
|
||||
|
||||
bpl_test(opaque)
|
||||
bpl_test(voidptr)
|
||||
|
||||
bpl_test(pickle1)
|
||||
bpl_test(pickle2)
|
||||
bpl_test(pickle3)
|
||||
bpl_test(pickle4)
|
||||
|
||||
bpl_test(nested)
|
||||
|
||||
bpl_test(docstring)
|
||||
|
||||
bpl_test(vector_indexing_suite)
|
||||
|
||||
bpl_test(pointer_vector)
|
||||
# TODO: Turn off this test on HP CXX, as the test hangs when executing.
|
||||
# Whenever the cause for the failure of the polymorphism test is found
|
||||
# and fixed, this should be retested.
|
||||
# <toolset>hp_cxx:<build>no
|
||||
|
||||
boost_python_extension(map_indexing_suite_ext
|
||||
map_indexing_suite.cpp int_map_indexing_suite.cpp a_map_indexing_suite.cpp)
|
||||
|
||||
bpl_test(map_indexing_suite
|
||||
map_indexing_suite.py map_indexing_suite_ext)
|
||||
|
||||
|
||||
# --- unit tests of library components ---
|
||||
|
||||
boost_test_compile(indirect_traits_test)
|
||||
boost_test_run(destroy_test)
|
||||
py_run(pointer_type_id_test)
|
||||
py_run(bases)
|
||||
boost_test_run(if_else)
|
||||
py_run(pointee)
|
||||
boost_test_run(result)
|
||||
|
||||
boost_test_compile(string_literal)
|
||||
boost_test_compile(borrowed)
|
||||
boost_test_compile(object_manager)
|
||||
boost_test_compile(copy_ctor_mutates_rhs)
|
||||
|
||||
py_run(upcast)
|
||||
|
||||
boost_test_compile(select_holder)
|
||||
|
||||
boost_test_run(select_from_python_test
|
||||
select_from_python_test.cpp ../src/converter/type_id.cpp
|
||||
COMPILE_FLAGS "-DBOOST_PYTHON_STATIC_LIB"
|
||||
LINK_LIBS ${PYTHON_LIBRARIES})
|
||||
|
||||
boost_test_compile(select_arg_to_python_test)
|
||||
|
||||
boost_test_compile_fail(raw_pyobject_fail1)
|
||||
boost_test_compile_fail(raw_pyobject_fail2)
|
||||
boost_test_compile_fail(as_to_python_function)
|
||||
boost_test_compile_fail(object_fail1)
|
||||
@@ -12,7 +12,7 @@
|
||||
#endif
|
||||
using namespace boost::python;
|
||||
|
||||
enum color { red = 1, green = 2, blue = 4, blood = 1 };
|
||||
enum color { red = 1, green = 2, blue = 4 };
|
||||
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
namespace boost // Pro7 has a hard time detecting enums
|
||||
@@ -34,7 +34,6 @@ BOOST_PYTHON_MODULE(enum_ext)
|
||||
.value("red", red)
|
||||
.value("green", green)
|
||||
.value("blue", blue)
|
||||
.value("blood", blood)
|
||||
.export_values()
|
||||
;
|
||||
|
||||
|
||||
20
test/enum.py
20
test/enum.py
@@ -4,8 +4,8 @@
|
||||
'''
|
||||
>>> from enum_ext import *
|
||||
|
||||
>>> identity(color.red) # in case of duplicated enums it always take the last enum
|
||||
enum_ext.color.blood
|
||||
>>> identity(color.red)
|
||||
enum_ext.color.red
|
||||
|
||||
>>> identity(color.green)
|
||||
enum_ext.color.green
|
||||
@@ -13,8 +13,8 @@ enum_ext.color.green
|
||||
>>> identity(color.blue)
|
||||
enum_ext.color.blue
|
||||
|
||||
>>> identity(color(1)) # in case of duplicated enums it always take the last enum
|
||||
enum_ext.color.blood
|
||||
>>> identity(color(1))
|
||||
enum_ext.color.red
|
||||
|
||||
>>> identity(color(2))
|
||||
enum_ext.color.green
|
||||
@@ -28,7 +28,7 @@ enum_ext.color.blue
|
||||
--- check export to scope ---
|
||||
|
||||
>>> identity(red)
|
||||
enum_ext.color.blood
|
||||
enum_ext.color.red
|
||||
|
||||
>>> identity(green)
|
||||
enum_ext.color.green
|
||||
@@ -42,18 +42,10 @@ enum_ext.color.blue
|
||||
|
||||
>>> c = colorized()
|
||||
>>> c.x
|
||||
enum_ext.color.blood
|
||||
enum_ext.color.red
|
||||
>>> c.x = green
|
||||
>>> c.x
|
||||
enum_ext.color.green
|
||||
>>> red == blood
|
||||
True
|
||||
>>> red == green
|
||||
False
|
||||
>>> hash(red) == hash(blood)
|
||||
True
|
||||
>>> hash(red) == hash(green)
|
||||
False
|
||||
'''
|
||||
|
||||
# pickling of enums only works with Python 2.3 or higher
|
||||
|
||||
@@ -59,13 +59,13 @@ void eval_test()
|
||||
void exec_test()
|
||||
{
|
||||
// Register the module with the interpreter
|
||||
if (PyImport_AppendInittab(const_cast<char*>("embedded_hello"),
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyInit_embedded_hello
|
||||
#else
|
||||
initembedded_hello
|
||||
#endif
|
||||
) == -1)
|
||||
if (PyImport_AppendInittab(const_cast<char*>("embedded_hello"),
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyInit_embedded_hello
|
||||
#else
|
||||
initembedded_hello
|
||||
#endif
|
||||
) == -1)
|
||||
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
|
||||
"builtin modules");
|
||||
// Retrieve the main module
|
||||
@@ -114,75 +114,49 @@ void exec_test_error()
|
||||
python::object result = python::exec("print(unknown) \n", global, global);
|
||||
}
|
||||
|
||||
void exercise_embedding_html()
|
||||
{
|
||||
using namespace boost::python;
|
||||
/* code from: libs/python/doc/tutorial/doc/tutorial.qbk
|
||||
(generates libs/python/doc/tutorial/doc/html/python/embedding.html)
|
||||
*/
|
||||
object main_module = import("__main__");
|
||||
object main_namespace = main_module.attr("__dict__");
|
||||
|
||||
object ignored = exec("hello = file('hello.txt', 'w')\n"
|
||||
"hello.write('Hello world!')\n"
|
||||
"hello.close()",
|
||||
main_namespace);
|
||||
}
|
||||
|
||||
void check_pyerr(bool pyerr_expected=false)
|
||||
{
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
if (!pyerr_expected) {
|
||||
BOOST_ERROR("Python Error detected");
|
||||
PyErr_Print();
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("A C++ exception was thrown for which "
|
||||
"there was no exception handler registered.");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BOOST_TEST(argc == 2 || argc == 3);
|
||||
BOOST_TEST(argc == 2);
|
||||
std::string script = argv[1];
|
||||
// Initialize the interpreter
|
||||
Py_Initialize();
|
||||
|
||||
if (python::handle_exception(eval_test)) {
|
||||
check_pyerr();
|
||||
}
|
||||
else if(python::handle_exception(exec_test)) {
|
||||
check_pyerr();
|
||||
}
|
||||
else if (python::handle_exception(boost::bind(exec_file_test, script))) {
|
||||
check_pyerr();
|
||||
if (python::handle_exception(eval_test)
|
||||
|| python::handle_exception(exec_test)
|
||||
|| python::handle_exception(boost::bind(exec_file_test, script))
|
||||
)
|
||||
{
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
BOOST_ERROR("Python Error detected");
|
||||
PyErr_Print();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("A C++ exception was thrown for which "
|
||||
"there was no exception handler registered.");
|
||||
}
|
||||
}
|
||||
|
||||
if (python::handle_exception(exec_test_error))
|
||||
{
|
||||
check_pyerr(/*pyerr_expected*/ true);
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("A C++ exception was thrown for which "
|
||||
"there was no exception handler registered.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_ERROR("Python exception expected, but not seen.");
|
||||
BOOST_ERROR("Python exception expected, but not seen.");
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
// The main purpose is to test compilation. Since this test generates
|
||||
// a file and I (rwgk) am uncertain about the side-effects, run it only
|
||||
// if explicitly requested.
|
||||
exercise_embedding_html();
|
||||
}
|
||||
|
||||
|
||||
// Boost.Python doesn't support Py_Finalize yet.
|
||||
// Py_Finalize();
|
||||
//Py_Finalize();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ BOOST_PYTHON_MODULE(map_indexing_suite_ext)
|
||||
|
||||
void a_map_indexing_suite(); // moved to a_map_indexing_suite.cpp to
|
||||
a_map_indexing_suite(); // avoid MSVC 6/7 internal structure overflow
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include "module_tail.cpp"
|
||||
|
||||
@@ -40,7 +40,8 @@ namespace boost_python_test {
|
||||
boost::python::tuple
|
||||
getinitargs(const world& w)
|
||||
{
|
||||
return boost::python::make_tuple(w.get_country());
|
||||
using namespace boost::python;
|
||||
return make_tuple(w.get_country());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -52,14 +52,16 @@ namespace boost_python_test {
|
||||
boost::python::tuple
|
||||
getinitargs(const world& w)
|
||||
{
|
||||
return boost::python::make_tuple(w.get_country());
|
||||
using namespace boost::python;
|
||||
return make_tuple(w.get_country());
|
||||
}
|
||||
|
||||
static
|
||||
boost::python::tuple
|
||||
getstate(const world& w)
|
||||
{
|
||||
return boost::python::make_tuple(w.get_secret_number());
|
||||
using namespace boost::python;
|
||||
return make_tuple(w.get_secret_number());
|
||||
}
|
||||
|
||||
static
|
||||
@@ -75,7 +77,7 @@ namespace boost_python_test {
|
||||
);
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
|
||||
long number = extract<long>(state[0]);
|
||||
if (number != 42)
|
||||
w.set_secret_number(number);
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#include <boost/python/extract.hpp>
|
||||
#include <boost/python/back_reference.hpp>
|
||||
|
||||
#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
|
||||
|
||||
namespace boost_python_test {
|
||||
|
||||
// A friendly class.
|
||||
@@ -49,18 +53,18 @@ namespace boost_python_test {
|
||||
boost::python::tuple
|
||||
getinitargs(const world& w)
|
||||
{
|
||||
return boost::python::make_tuple(w.get_country());
|
||||
using namespace boost::python;
|
||||
return make_tuple(w.get_country());
|
||||
}
|
||||
|
||||
static
|
||||
boost::python::tuple
|
||||
getstate(boost::python::object w_obj)
|
||||
{
|
||||
world const& w = boost::python::extract<world const&>(w_obj)();
|
||||
using namespace boost::python;
|
||||
world const& w = extract<world const&>(w_obj)();
|
||||
|
||||
return boost::python::make_tuple(
|
||||
w_obj.attr("__dict__"),
|
||||
w.get_secret_number());
|
||||
return make_tuple(w_obj.attr("__dict__"), w.get_secret_number());
|
||||
}
|
||||
|
||||
static
|
||||
@@ -69,7 +73,7 @@ namespace boost_python_test {
|
||||
{
|
||||
using namespace boost::python;
|
||||
world& w = extract<world&>(w_obj)();
|
||||
|
||||
|
||||
if (len(state) != 2)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
@@ -78,11 +82,11 @@ namespace boost_python_test {
|
||||
);
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
|
||||
// restore the object's __dict__
|
||||
dict d = extract<dict>(w_obj.attr("__dict__"))();
|
||||
d.update(state[0]);
|
||||
|
||||
|
||||
// restore the internal state of the C++ object
|
||||
long number = extract<long>(state[1]);
|
||||
if (number != 42)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import sys
|
||||
|
||||
pythonpath = sys.argv[1]
|
||||
scriptfile = sys.argv[2]
|
||||
sys.argv = sys.argv[2:]
|
||||
sys.path.append(pythonpath)
|
||||
execfile(scriptfile)
|
||||
@@ -17,10 +17,6 @@ struct by_value
|
||||
{
|
||||
return x;
|
||||
}
|
||||
static int size(void)
|
||||
{
|
||||
return sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@@ -65,17 +61,7 @@ BOOST_PYTHON_MODULE(builtin_converters_ext)
|
||||
{
|
||||
def("get_type", get_type);
|
||||
def("return_null_handle", return_null_handle);
|
||||
|
||||
// These methods are used solely for getting some C++ type sizes
|
||||
def("bool_size", by_value<bool>::size);
|
||||
def("char_size", by_value<char>::size);
|
||||
def("int_size", by_value<int>::size);
|
||||
def("short_size", by_value<short>::size);
|
||||
def("long_size", by_value<long>::size);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
def("long_long_size", by_value<BOOST_PYTHON_LONG_LONG>::size);
|
||||
#endif
|
||||
|
||||
|
||||
def("rewrap_value_bool", by_value<bool>::rewrap);
|
||||
def("rewrap_value_char", by_value<char>::rewrap);
|
||||
def("rewrap_value_signed_char", by_value<signed char>::rewrap);
|
||||
|
||||
@@ -4,33 +4,12 @@
|
||||
r"""
|
||||
>>> from builtin_converters_ext import *
|
||||
|
||||
# Provide values for integer converter tests
|
||||
>>> def _signed_values(s):
|
||||
... base = 2 ** (8 * s - 1)
|
||||
... return [[-base, -1, 1, base - 1], [-base - 1, base]]
|
||||
>>> def _unsigned_values(s):
|
||||
... base = 2 ** (8 * s)
|
||||
... return [[1, base - 1], [-1L, -1, base]]
|
||||
|
||||
# Wrappers to simplify tests
|
||||
>>> def should_pass(method, values):
|
||||
... result = map(method, values[0])
|
||||
... if result != values[0]:
|
||||
... print "Got %s but expected %s" % (result, values[0])
|
||||
>>> def test_overflow(method, values):
|
||||
... for v in values[1]:
|
||||
... try: method(v)
|
||||
... except OverflowError: pass
|
||||
... else: print "OverflowError expected"
|
||||
|
||||
# Synthesize idendity functions in case long long not supported
|
||||
>>> if not 'rewrap_value_long_long' in dir():
|
||||
... def rewrap_value_long_long(x): return long(x)
|
||||
... def rewrap_value_unsigned_long_long(x): return long(x)
|
||||
... def rewrap_const_reference_long_long(x): return long(x)
|
||||
... def rewrap_const_reference_unsigned_long_long(x): return long(x)
|
||||
>>> if not 'long_long_size' in dir():
|
||||
... def long_long_size(): return long_size()
|
||||
|
||||
>>> try: bool_exists = bool
|
||||
... except: pass
|
||||
@@ -83,37 +62,15 @@ True
|
||||
True
|
||||
|
||||
show that we have range checking.
|
||||
|
||||
>>> try: rewrap_value_unsigned_short(-42)
|
||||
... except OverflowError: pass
|
||||
... else: print 'expected an OverflowError!'
|
||||
|
||||
>>> should_pass(rewrap_value_signed_char, _signed_values(char_size()))
|
||||
>>> should_pass(rewrap_value_short, _signed_values(short_size()))
|
||||
>>> should_pass(rewrap_value_int, _signed_values(int_size()))
|
||||
>>> should_pass(rewrap_value_long, _signed_values(long_size()))
|
||||
>>> should_pass(rewrap_value_long_long, _signed_values(long_long_size()))
|
||||
>>> try: rewrap_value_int(sys.maxint * 2)
|
||||
... except OverflowError: pass
|
||||
... else: print 'expected an OverflowError!'
|
||||
|
||||
>>> should_pass(rewrap_value_unsigned_char, _unsigned_values(char_size()))
|
||||
>>> should_pass(rewrap_value_unsigned_short, _unsigned_values(short_size()))
|
||||
>>> should_pass(rewrap_value_unsigned_int, _unsigned_values(int_size()))
|
||||
>>> should_pass(rewrap_value_unsigned_long, _unsigned_values(long_size()))
|
||||
>>> should_pass(rewrap_value_unsigned_long_long,
|
||||
... _unsigned_values(long_long_size()))
|
||||
|
||||
>>> test_overflow(rewrap_value_signed_char, _signed_values(char_size()))
|
||||
>>> test_overflow(rewrap_value_short, _signed_values(short_size()))
|
||||
>>> test_overflow(rewrap_value_int, _signed_values(int_size()))
|
||||
>>> test_overflow(rewrap_value_long, _signed_values(long_size()))
|
||||
>>> test_overflow(rewrap_value_long_long, _signed_values(long_long_size()))
|
||||
|
||||
>>> test_overflow(rewrap_value_unsigned_char, _unsigned_values(char_size()))
|
||||
>>> test_overflow(rewrap_value_unsigned_short, _unsigned_values(short_size()))
|
||||
>>> test_overflow(rewrap_value_unsigned_int, _unsigned_values(int_size()))
|
||||
>>> test_overflow(rewrap_value_unsigned_long, _unsigned_values(long_size()))
|
||||
|
||||
# Exceptionally for PyLong_AsUnsignedLongLong(), a negative value raises
|
||||
# TypeError on Python versions prior to 2.7
|
||||
>>> for v in _unsigned_values(long_long_size())[1]:
|
||||
... try: rewrap_value_unsigned_long_long(v)
|
||||
... except (OverflowError, TypeError): pass
|
||||
... else: print "OverflowError or TypeError expected"
|
||||
|
||||
>>> assert abs(rewrap_value_float(4.2) - 4.2) < .000001
|
||||
>>> rewrap_value_double(4.2) - 4.2
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright Troy D. Straszheim 2009
|
||||
// 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)
|
||||
//
|
||||
//
|
||||
// example that shows problems with overloading and automatic conversion.
|
||||
// if you call one of the below functions from python with bool/int/double,
|
||||
// you'll see that the overload called is first match, not best match.
|
||||
// See overload matching in luabind for an example of how to do this better.
|
||||
//
|
||||
// see this mail:
|
||||
// http://mail.python.org/pipermail/cplusplus-sig/2009-March/014362.html
|
||||
//
|
||||
// This test isn't called by the cmake/jamfiles. For future use.
|
||||
//
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
#include <complex>
|
||||
#include <boost/python/handle.hpp>
|
||||
#include <boost/python/cast.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
#include <boost/python/detail/wrap_python.hpp>
|
||||
|
||||
using boost::python::def;
|
||||
using boost::python::handle;
|
||||
using boost::python::object;
|
||||
using boost::python::borrowed;
|
||||
|
||||
std::string takes_bool(bool b) { return "bool"; }
|
||||
std::string takes_int(int b) { return "int"; }
|
||||
std::string takes_double(double b) { return "double"; }
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(overload_resolution)
|
||||
{
|
||||
def("bid", takes_bool);
|
||||
def("bid", takes_int);
|
||||
def("bid", takes_double);
|
||||
|
||||
def("dib", takes_double);
|
||||
def("dib", takes_int);
|
||||
def("dib", takes_bool);
|
||||
|
||||
def("idb", takes_int);
|
||||
def("idb", takes_double);
|
||||
def("idb", takes_bool);
|
||||
|
||||
def("bdi", takes_bool);
|
||||
def("bdi", takes_double);
|
||||
def("bdi", takes_int);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user