diff --git a/config/cxx.py b/config/cxx.py index ae34beb09c..deb7be73ac 100644 --- a/config/cxx.py +++ b/config/cxx.py @@ -15,7 +15,7 @@ def add_options(vars): def check(context): - source = r"""#if __cplusplus < 201103L + source = r"""#if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_VER < 1800) #error no C++11 #endif""" diff --git a/include/boost/python/converter/registered.hpp b/include/boost/python/converter/registered.hpp index 73f4d98466..98013052ec 100644 --- a/include/boost/python/converter/registered.hpp +++ b/include/boost/python/converter/registered.hpp @@ -76,7 +76,7 @@ namespace detail registry::lookup_shared_ptr(type_id >()); } -#if __cplusplus >= 201103L +#if !defined(BOOST_NO_CXX11_SMART_PTR) template inline void register_shared_ptr0(std::shared_ptr*) diff --git a/include/boost/python/converter/shared_ptr_to_python.hpp b/include/boost/python/converter/shared_ptr_to_python.hpp index cc68646109..02649d406e 100644 --- a/include/boost/python/converter/shared_ptr_to_python.hpp +++ b/include/boost/python/converter/shared_ptr_to_python.hpp @@ -25,7 +25,7 @@ PyObject* shared_ptr_to_python(shared_ptr const& x) return converter::registered const&>::converters.to_python(&x); } -#if __cplusplus >= 201103L +#if !defined(BOOST_NO_CXX11_SMART_PTR) template PyObject* shared_ptr_to_python(std::shared_ptr const& x) { diff --git a/include/boost/python/detail/caller.hpp b/include/boost/python/detail/caller.hpp index c572d35aa9..1bd30bfb5a 100644 --- a/include/boost/python/detail/caller.hpp +++ b/include/boost/python/detail/caller.hpp @@ -48,7 +48,7 @@ inline PyObject* get(mpl::int_, PyObject* const& args_) return PyTuple_GET_ITEM(args_,N); } -inline unsigned arity(PyObject* const& args_) +inline Py_ssize_t arity(PyObject* const& args_) { return PyTuple_GET_SIZE(args_); } diff --git a/include/boost/python/detail/is_shared_ptr.hpp b/include/boost/python/detail/is_shared_ptr.hpp index bef0e05afb..383383bc12 100644 --- a/include/boost/python/detail/is_shared_ptr.hpp +++ b/include/boost/python/detail/is_shared_ptr.hpp @@ -13,7 +13,7 @@ namespace boost { namespace python { namespace detail { BOOST_PYTHON_IS_XXX_DEF(shared_ptr, shared_ptr, 1) -#if __cplusplus >= 201103L +#if !defined(BOOST_NO_CXX11_SMART_PTR) template struct is_shared_ptr > : std::true_type {}; #endif diff --git a/include/boost/python/detail/type_traits.hpp b/include/boost/python/detail/type_traits.hpp index df940c7ea2..381132eec5 100644 --- a/include/boost/python/detail/type_traits.hpp +++ b/include/boost/python/detail/type_traits.hpp @@ -7,7 +7,8 @@ # define BOOST_PYTHON_DETAIL_TYPE_TRAITS_HPP -#if __cplusplus < 201103L +#if __cplusplus < 201103L && (!defined(BOOST_MSVC) || BOOST_MSVC<=1600) +#define BOOST_PYTHON_USE_BOOST_TYPES # include # include # include @@ -34,7 +35,7 @@ namespace boost { namespace python { namespace detail { -#if __cplusplus < 201103L +#if defined(BOOST_PYTHON_USE_BOOST_TYPES) using boost::alignment_of; using boost::add_const; using boost::add_cv; diff --git a/include/boost/python/make_constructor.hpp b/include/boost/python/make_constructor.hpp index 053d050cd6..3ec9ad5f86 100644 --- a/include/boost/python/make_constructor.hpp +++ b/include/boost/python/make_constructor.hpp @@ -45,7 +45,7 @@ namespace detail template void dispatch(U* x, detail::true_) const { -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) std::auto_ptr owner(x); dispatch(owner, detail::false_()); #else @@ -63,7 +63,7 @@ namespace detail void* memory = holder::allocate(this->m_self, offsetof(instance_t, storage), sizeof(holder)); try { -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) (new (memory) holder(x))->install(this->m_self); #else (new (memory) holder(std::move(x)))->install(this->m_self); diff --git a/include/boost/python/module_init.hpp b/include/boost/python/module_init.hpp index a9536c88ee..7fe5a1c8a2 100644 --- a/include/boost/python/module_init.hpp +++ b/include/boost/python/module_init.hpp @@ -66,25 +66,9 @@ BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)()); # endif -# if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE) - -# define BOOST_PYTHON_MODULE_INIT(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 BOOST_PP_CAT(init_module_,name)(); \ -extern "C" __attribute__ ((__visibility__("default"))) _BOOST_PYTHON_MODULE_INIT(name) - -# else - -# define BOOST_PYTHON_MODULE_INIT(name) \ - void BOOST_PP_CAT(init_module_,name)(); \ -extern "C" _BOOST_PYTHON_MODULE_INIT(name) - -# endif +# define BOOST_PYTHON_MODULE_INIT(name) \ + void BOOST_PP_CAT(init_module_,name)(); \ +extern "C" BOOST_SYMBOL_EXPORT _BOOST_PYTHON_MODULE_INIT(name) # endif diff --git a/include/boost/python/object/class_metadata.hpp b/include/boost/python/object/class_metadata.hpp index 93303ecb60..06d3f8efa7 100644 --- a/include/boost/python/object/class_metadata.hpp +++ b/include/boost/python/object/class_metadata.hpp @@ -83,7 +83,7 @@ inline void register_shared_ptr_from_python_and_casts(T*, Bases) { // Constructor performs registration python::detail::force_instantiate(converter::shared_ptr_from_python()); -#if __cplusplus >= 201103L +#if !defined(BOOST_NO_CXX11_SMART_PTR) python::detail::force_instantiate(converter::shared_ptr_from_python()); #endif diff --git a/include/boost/python/object/make_ptr_instance.hpp b/include/boost/python/object/make_ptr_instance.hpp index 21089c6b88..92412b31fe 100644 --- a/include/boost/python/object/make_ptr_instance.hpp +++ b/include/boost/python/object/make_ptr_instance.hpp @@ -21,7 +21,7 @@ struct make_ptr_instance template static inline Holder* construct(void* storage, PyObject*, Arg& x) { -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) return new (storage) Holder(x); #else return new (storage) Holder(std::move(x)); @@ -58,7 +58,7 @@ struct make_ptr_instance static inline PyTypeObject* get_derived_class_object(boost::python::detail::true_, U const volatile* x) { converter::registration const* r = converter::registry::query( - type_info(typeid(*get_pointer(x))) + type_info(typeid(*x)) ); return r ? r->m_class_object : 0; } diff --git a/include/boost/python/object/pointer_holder.hpp b/include/boost/python/object/pointer_holder.hpp index c5caefe62c..c3b57e833a 100644 --- a/include/boost/python/object/pointer_holder.hpp +++ b/include/boost/python/object/pointer_holder.hpp @@ -106,7 +106,7 @@ struct pointer_holder_back_reference : instance_holder template inline pointer_holder::pointer_holder(Pointer p) -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) : m_p(p) #else : m_p(std::move(p)) @@ -116,7 +116,7 @@ inline pointer_holder::pointer_holder(Pointer p) template inline pointer_holder_back_reference::pointer_holder_back_reference(Pointer p) -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) : m_p(p) #else : m_p(std::move(p)) diff --git a/include/boost/python/object/py_function.hpp b/include/boost/python/object/py_function.hpp index 05cedfa00a..df2fb44a4f 100644 --- a/include/boost/python/object/py_function.hpp +++ b/include/boost/python/object/py_function.hpp @@ -135,7 +135,7 @@ struct py_function {} py_function(py_function const& rhs) -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) : m_impl(rhs.m_impl) #else : m_impl(std::move(rhs.m_impl)) @@ -168,7 +168,7 @@ struct py_function } private: -#if __cplusplus < 201103L +#if defined(BOOST_NO_CXX11_SMART_PTR) mutable std::auto_ptr m_impl; #else mutable std::unique_ptr m_impl; diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp index 9b323a2823..ab4bca390a 100644 --- a/include/boost/python/signature.hpp +++ b/include/boost/python/signature.hpp @@ -111,7 +111,6 @@ struct most_derived // 'default' calling convention # define BOOST_PYTHON_FN_CC -# define BOOST_PYTHON_FN_CC_IS_DEFAULT # define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PYTHON_MAX_ARITY, )) @@ -119,7 +118,6 @@ struct most_derived # include BOOST_PP_ITERATE() # undef BOOST_PYTHON_FN_CC -# undef BOOST_PYTHON_FN_CC_IS_DEFAULT // __cdecl calling convention @@ -143,7 +141,6 @@ struct most_derived # if defined(BOOST_PYTHON_ENABLE_STDCALL) # define BOOST_PYTHON_FN_CC __stdcall -# define BOOST_PYTHON_FN_CC_IS_STDCALL # define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PYTHON_MAX_ARITY, )) @@ -151,7 +148,6 @@ struct most_derived # include BOOST_PP_ITERATE() # undef BOOST_PYTHON_FN_CC -# undef BOOST_PYTHON_FN_CC_IS_STDCALL # endif // defined(BOOST_PYTHON_ENABLE_STDCALL) @@ -160,14 +156,12 @@ struct most_derived # if defined(BOOST_PYTHON_ENABLE_FASTCALL) # define BOOST_PYTHON_FN_CC __fastcall -# define BOOST_PYTHON_FN_CC_IS_FASTCALL # define BOOST_PP_ITERATION_PARAMS_1 \ (3, (0, BOOST_PYTHON_MAX_ARITY, )) # include BOOST_PP_ITERATE() -# undef BOOST_PYTHON_FN_CC_IS_FASTCALL # undef BOOST_PYTHON_FN_CC # endif // defined(BOOST_PYTHON_ENABLE_FASTCALL) @@ -190,8 +184,8 @@ struct most_derived // as 'get_signature(RT(*)(T0...TN), void* = 0)' is the same // function as 'get_signature(RT(__cdecl *)(T0...TN), void* = 0)', - // we don't define it multiple times (i.e. for __cdecl, __stdcall ...) -# if defined(BOOST_PYTHON_FN_CC_IS_DEFAULT) + // we don't define it twice +# if !defined(BOOST_PYTHON_FN_CC_IS_CDECL) template < class RT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)> @@ -204,7 +198,7 @@ get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = >(); } -# endif // BOOST_PYTHON_FN_CC_IS_DEFAULT +# endif // !defined(BOOST_PYTHON_FN_CC_IS_CDECL) # undef N @@ -212,13 +206,11 @@ get_signature(RT(BOOST_PYTHON_FN_CC *)(BOOST_PP_ENUM_PARAMS_Z(1, N, T)), void* = (3, (0, 3, )) # include BOOST_PP_ITERATE() -#else // BOOST_PP_ITERATION_DEPTH() != 1 +#else # define N BOOST_PP_RELATIVE_ITERATION(1) # define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_ITERATION()) -# if defined(BOOST_PYTHON_FN_CC_IS_DEFAULT) - template < class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class T)> inline BOOST_PYTHON_LIST_INC(BOOST_PP_INC(N))< @@ -253,8 +245,6 @@ get_signature( >(); } -# endif // BOOST_PYTHON_FN_CC_IS_DEFAULT - # undef Q # undef N diff --git a/include/boost/python/to_python_indirect.hpp b/include/boost/python/to_python_indirect.hpp index 212e1db3d4..0a19aca5ff 100644 --- a/include/boost/python/to_python_indirect.hpp +++ b/include/boost/python/to_python_indirect.hpp @@ -83,7 +83,7 @@ namespace detail // copy constructor. # if defined(__ICL) && __ICL < 600 typedef boost::shared_ptr smart_pointer; -# elif __cplusplus < 201103L +# elif defined(BOOST_NO_CXX11_SMART_PTR) typedef std::auto_ptr smart_pointer; # else typedef std::unique_ptr smart_pointer; diff --git a/include/boost/python/to_python_value.hpp b/include/boost/python/to_python_value.hpp index 2066d3a2ab..b6ec0135ba 100644 --- a/include/boost/python/to_python_value.hpp +++ b/include/boost/python/to_python_value.hpp @@ -118,7 +118,7 @@ struct object_manager_get_pytype PyTypeObject const* get_pytype(boost::type &> *) const {return converter::registered::converters.to_python_target_type();} template PyTypeObject const* get_pytype(boost::type &> *) const {return converter::registered::converters.to_python_target_type();} -# if __cplusplus >= 201103L +# if !defined(BOOST_NO_CXX11_SMART_PTR) template PyTypeObject const* get_pytype(boost::type &> *) const {return converter::registered::converters.to_python_target_type();} template diff --git a/src/object/enum.cpp b/src/object/enum.cpp index 3063320cb0..4d73ee23d4 100644 --- a/src/object/enum.cpp +++ b/src/object/enum.cpp @@ -34,11 +34,17 @@ static PyMemberDef enum_members[] = { extern "C" { + static void + enum_dealloc(enum_object* self) + { + Py_XDECREF(self->name); + Py_TYPE(self)->tp_free((PyObject*)self); + } + static PyObject* enum_repr(PyObject* self_) { - // XXX(bhy) Potentional memory leak here since PyObject_GetAttrString returns a new reference - // const char *mod = PyString_AsString(PyObject_GetAttrString( self_, const_cast("__module__"))); PyObject *mod = PyObject_GetAttrString( self_, "__module__"); + object auto_free(handle<>(mod)); enum_object* self = downcast(self_); if (!self->name) { @@ -88,7 +94,7 @@ static PyTypeObject enum_type_object = { const_cast("Boost.Python.enum"), sizeof(enum_object), /* tp_basicsize */ 0, /* tp_itemsize */ - 0, /* tp_dealloc */ + (destructor) enum_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */