From 65b3aadc63cd400d2950289b304744cf2c1ad5c5 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 12 Jul 2010 22:29:41 +0000 Subject: [PATCH] merging current boost/python and libs/python from trunk into release branch [SVN r63937] --- build/Jamfile.v2 | 23 ++++++++++------ .../python/converter/builtin_converters.hpp | 27 ++++++++++++++++--- include/boost/python/converter/registry.hpp | 2 +- include/boost/python/exception_translator.hpp | 2 +- include/boost/python/module_init.hpp | 20 +++++++------- include/boost/python/object/make_instance.hpp | 3 --- src/converter/registry.cpp | 4 +-- test/Jamfile.v2 | 13 ++++++--- 8 files changed, 63 insertions(+), 31 deletions(-) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index cc8a8be2..32bffb0f 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -14,14 +14,20 @@ if ! [ python.configured ] && ! ( --without-python in [ modules.peek : ARGV ] ) # Attempt default configuration of python import toolset : using ; using python ; - - if ! [ python.configured ] - { - ECHO "WARNING: No python installation configured and autoconfiguration" ; - ECHO " failed. See http://www.boost.org/libs/python/doc/building.html" ; - ECHO " for configuration instructions or pass --without-python to" ; - ECHO " suppress this message and silently skip all Boost.Python targets" ; - } +} + +if [ python.configured ] || ( --without-python in [ modules.peek : ARGV ] ) +{ + alias config-warning ; +} +else +{ + message config-warning + : "warning: No python installation configured and autoconfiguration" + : "note: failed. See http://www.boost.org/libs/python/doc/building.html" + : "note: for configuration instructions or pass --without-python to" + : "note: suppress this message and silently skip all Boost.Python targets" + ; } rule find-py3-version @@ -122,6 +128,7 @@ rule lib_boost_python ( is-py3 ? ) # as it's not possible anyway, and to cause dependents to # fail to build [ unless [ python.configured ] : no ] + config-warning on:BOOST_DEBUG_PYTHON [ cond $(is-py3) : $(py3-version) ] diff --git a/include/boost/python/converter/builtin_converters.hpp b/include/boost/python/converter/builtin_converters.hpp index 63ae1e1a..978f4f1f 100644 --- a/include/boost/python/converter/builtin_converters.hpp +++ b/include/boost/python/converter/builtin_converters.hpp @@ -122,9 +122,30 @@ BOOST_PYTHON_TO_INT(short) BOOST_PYTHON_TO_INT(int) 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 +# if defined(_MSC_VER) && defined(_WIN64) +/* Under 64-bit Windows std::size_t is "unsigned long long". To avoid + getting a Python long for each std::size_t the value is checked before + the conversion. A std::size_t is converted to a simple Python int + if possible; a Python long appears only if the value is too small or + too large to fit into a simple int. */ +BOOST_PYTHON_TO_PYTHON_BY_VALUE( + signed BOOST_PYTHON_LONG_LONG, + ( x < static_cast( + (std::numeric_limits::min)()) + || x > static_cast( + (std::numeric_limits::max)())) + ? ::PyLong_FromLongLong(x) + : ::PyInt_FromLong(static_cast(x)), &PyInt_Type) +BOOST_PYTHON_TO_PYTHON_BY_VALUE( + unsigned BOOST_PYTHON_LONG_LONG, + x > static_cast( + (std::numeric_limits::max)()) + ? ::PyLong_FromUnsignedLongLong(x) + : ::PyInt_FromLong(static_cast(x)), &PyInt_Type) +// +# elif defined(HAVE_LONG_LONG) // using Python's macro instead of Boost's + // - we don't seem to get the config right + // all the time. 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 diff --git a/include/boost/python/converter/registry.hpp b/include/boost/python/converter/registry.hpp index e037bbcc..368adcc6 100644 --- a/include/boost/python/converter/registry.hpp +++ b/include/boost/python/converter/registry.hpp @@ -30,7 +30,7 @@ namespace registry BOOST_PYTHON_DECL void insert(to_python_function_t, type_info, PyTypeObject const* (*to_python_target_type)() = 0); // Insert an lvalue from_python converter - BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), type_info, PyTypeObject const* (*expected_pytype)() = 0); + BOOST_PYTHON_DECL void insert(convertible_function, type_info, PyTypeObject const* (*expected_pytype)() = 0); // Insert an rvalue from_python converter BOOST_PYTHON_DECL void insert( diff --git a/include/boost/python/exception_translator.hpp b/include/boost/python/exception_translator.hpp index 60760dce..eb72da62 100644 --- a/include/boost/python/exception_translator.hpp +++ b/include/boost/python/exception_translator.hpp @@ -18,7 +18,7 @@ template void register_exception_translator(Translate translate, boost::type* = 0) { detail::register_exception_handler( - bind(detail::translate_exception(), _1, _2, translate) + boost::bind(detail::translate_exception(), _1, _2, translate) ); } diff --git a/include/boost/python/module_init.hpp b/include/boost/python/module_init.hpp index e552dcce..e06aa794 100644 --- a/include/boost/python/module_init.hpp +++ b/include/boost/python/module_init.hpp @@ -6,6 +6,8 @@ # define MODULE_INIT_DWA20020722_HPP # include +# include +# include # ifndef BOOST_PYTHON_MODULE_INIT @@ -18,41 +20,41 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)()); # if PY_VERSION_HEX >= 0x03000000 # define _BOOST_PYTHON_MODULE_INIT(name) \ -PyObject* PyInit_##name() \ + PyObject* BOOST_PP_CAT (PyInit_,name)() \ { \ return boost::python::detail::init_module( \ - #name,&init_module_##name); \ + BOOST_PP_STRINGIZE(name),&BOOST_PP_CAT(init_module_,name)); \ } \ -void init_module_##name() + void BOOST_PP_CAT(init_module_,name)() # else # define _BOOST_PYTHON_MODULE_INIT(name) \ -void init##name() \ + void BOOST_PP_CAT(init,name)() \ { \ boost::python::detail::init_module( \ - #name,&init_module_##name); \ + BOOST_PP_STRINGIZE(name),&BOOST_PP_CAT(init_module_,name)); \ } \ -void init_module_##name() + void BOOST_PP_CAT(init_module_,name)() # endif # if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE) # define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ + void BOOST_PP_CAT(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(); \ + void BOOST_PP_CAT(init_module_,name)(); \ extern "C" __attribute__ ((visibility("default"))) _BOOST_PYTHON_MODULE_INIT(name) # else # define BOOST_PYTHON_MODULE_INIT(name) \ -void init_module_##name(); \ + void BOOST_PP_CAT(init_module_,name)(); \ extern "C" _BOOST_PYTHON_MODULE_INIT(name) # endif diff --git a/include/boost/python/object/make_instance.hpp b/include/boost/python/object/make_instance.hpp index 264a05b4..1ffded12 100644 --- a/include/boost/python/object/make_instance.hpp +++ b/include/boost/python/object/make_instance.hpp @@ -10,10 +10,7 @@ # include # include # include -# include # include -# include -# include namespace boost { namespace python { namespace objects { diff --git a/src/converter/registry.cpp b/src/converter/registry.cpp index d203ea8c..aa20c3f6 100644 --- a/src/converter/registry.cpp +++ b/src/converter/registry.cpp @@ -243,7 +243,7 @@ namespace registry } // Insert an rvalue from_python converter - void insert(void* (*convertible)(PyObject*) + void insert(convertible_function convertible , constructor_function construct , type_info key , PyTypeObject const* (*exp_pytype)()) @@ -261,7 +261,7 @@ namespace registry } // Insert an rvalue from_python converter - void push_back(void* (*convertible)(PyObject*) + void push_back(convertible_function convertible , constructor_function construct , type_info key , PyTypeObject const* (*exp_pytype)()) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b09d5e8e..34f63b3c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -37,6 +37,13 @@ rule py-compile-fail ( sources * ) return [ compile-fail $(sources) /boost/python//boost_python ] ; } +rule require-windows ( properties * ) +{ + if ! windows in $(properties) + { + return no ; + } +} test-suite python : @@ -184,10 +191,8 @@ bpl-test crossmod_opaque # bpl-test bienstman5 ; # } -# XXX disabled on release branch only, -# XXX to avoid failures on platforms other than Windows -# [ bpl-test calling_conventions ] -# [ bpl-test calling_conventions_mf ] +[ bpl-test calling_conventions : : @require-windows ] +[ bpl-test calling_conventions_mf : : @require-windows ] # --- unit tests of library components ---