diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp index cf102aea..45304082 100644 --- a/include/boost/python/conversions.hpp +++ b/include/boost/python/conversions.hpp @@ -33,6 +33,10 @@ # pragma warning(pop) # endif +namespace boost { namespace python { + enum semantics { search_namespace }; // Used to find to_python functions via koenig lookup. +}} + BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround // This can be instantiated on an enum to provide the to_python/from_python @@ -61,7 +65,7 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE namespace boost { namespace python { template class enum_as_int_converters - : public BOOST_PYTHON_CONVERSION::py_enum_as_int_converters {}; + : public py_enum_as_int_converters {}; template class wrapped_pointer; @@ -116,70 +120,70 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // // Converters // -PyObject* to_python(boost::python::search_namespace, long); +PyObject* to_python(boost::python::semantics, long); long from_python(PyObject* p, boost::python::type); long from_python(PyObject* p, boost::python::type); -PyObject* to_python(boost::python::search_namespace, unsigned long); +PyObject* to_python(boost::python::semantics, unsigned long); unsigned long from_python(PyObject* p, boost::python::type); unsigned long from_python(PyObject* p, boost::python::type); -PyObject* to_python(boost::python::search_namespace, int); +PyObject* to_python(boost::python::semantics, int); int from_python(PyObject*, boost::python::type); int from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, unsigned int); +PyObject* to_python(boost::python::semantics, unsigned int); unsigned int from_python(PyObject*, boost::python::type); unsigned int from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, short); +PyObject* to_python(boost::python::semantics, short); short from_python(PyObject*, boost::python::type); short from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, unsigned short); +PyObject* to_python(boost::python::semantics, unsigned short); unsigned short from_python(PyObject*, boost::python::type); unsigned short from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, char); +PyObject* to_python(boost::python::semantics, char); char from_python(PyObject*, boost::python::type); char from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, signed char); +PyObject* to_python(boost::python::semantics, signed char); signed char from_python(PyObject*, boost::python::type); signed char from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, unsigned char); +PyObject* to_python(boost::python::semantics, unsigned char); unsigned char from_python(PyObject*, boost::python::type); unsigned char from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, float); +PyObject* to_python(boost::python::semantics, float); float from_python(PyObject*, boost::python::type); float from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, double); +PyObject* to_python(boost::python::semantics, double); double from_python(PyObject*, boost::python::type); double from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, bool); +PyObject* to_python(boost::python::semantics, bool); bool from_python(PyObject*, boost::python::type); bool from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, void); +PyObject* to_python(boost::python::semantics); void from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, const char* s); +PyObject* to_python(boost::python::semantics, const char* s); const char* from_python(PyObject*, boost::python::type); -PyObject* to_python(boost::python::search_namespace, const std::string& s); +PyObject* to_python(boost::python::semantics, const std::string& s); std::string from_python(PyObject*, boost::python::type); std::string from_python(PyObject*, boost::python::type); -inline PyObject* to_python(boost::python::search_namespace, const std::complex& x) +inline PyObject* to_python(boost::python::semantics, const std::complex& x) { return boost::python::detail::complex_to_python(x); } -inline PyObject* to_python(boost::python::search_namespace, const std::complex& x) +inline PyObject* to_python(boost::python::semantics, const std::complex& x) { return boost::python::detail::complex_to_python(x); } @@ -205,7 +209,7 @@ inline std::complex from_python(PyObject* p, } // For when your C++ function really wants to pass/return a PyObject* -PyObject* to_python(boost::python::search_namespace, PyObject*); +PyObject* to_python(boost::python::semantics, PyObject*); PyObject* from_python(PyObject*, boost::python::type); // Some standard conversions to/from smart pointer types. You can add your own @@ -259,13 +263,13 @@ boost::shared_ptr from_python(PyObject*p, boost::python::type -PyObject* to_python(boost::python::search_namespace, std::auto_ptr p) +PyObject* to_python(boost::python::semantics, std::auto_ptr p) { return new boost::python::wrapped_pointer, T>(p); } template -PyObject* to_python(boost::python::search_namespace, boost::shared_ptr p) +PyObject* to_python(boost::python::semantics, boost::shared_ptr p) { return new boost::python::wrapped_pointer, T>(p); } @@ -276,43 +280,43 @@ PyObject* to_python(boost::python::search_namespace, boost::shared_ptr p) // #ifndef BOOST_MSVC6_OR_EARLIER -inline PyObject* to_python(boost::python::search_namespace, double d) +inline PyObject* to_python(boost::python::semantics, double d) { return PyFloat_FromDouble(d); } -inline PyObject* to_python(boost::python::search_namespace, float f) +inline PyObject* to_python(boost::python::semantics, float f) { return PyFloat_FromDouble(f); } #endif // BOOST_MSVC6_OR_EARLIER -inline PyObject* to_python(boost::python::search_namespace, long l) +inline PyObject* to_python(boost::python::semantics, long l) { return PyInt_FromLong(l); } -inline PyObject* to_python(boost::python::search_namespace, int x) +inline PyObject* to_python(boost::python::semantics, int x) { return PyInt_FromLong(x); } -inline PyObject* to_python(boost::python::search_namespace, short x) +inline PyObject* to_python(boost::python::semantics, short x) { return PyInt_FromLong(x); } -inline PyObject* to_python(boost::python::search_namespace, bool b) +inline PyObject* to_python(boost::python::semantics, bool b) { return PyInt_FromLong(b); } -inline PyObject* to_python(boost::python::search_namespace, void) +inline PyObject* to_python(boost::python::semantics) { return boost::python::detail::none(); } -inline PyObject* to_python(boost::python::search_namespace, const char* s) +inline PyObject* to_python(boost::python::semantics, const char* s) { return PyString_FromString(s); } @@ -322,7 +326,7 @@ inline std::string from_python(PyObject* p, boost::python::type()); } -inline PyObject* to_python(boost::python::search_namespace, PyObject* p) +inline PyObject* to_python(boost::python::semantics, PyObject* p) { Py_INCREF(p); return p; diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp index ff4d56f1..0e5e55fa 100644 --- a/include/boost/python/cross_module.hpp +++ b/include/boost/python/cross_module.hpp @@ -66,8 +66,8 @@ class python_import_extension_class_converters return python_import_extension_class_converters(); } - PyObject* to_python(boost::python::semantics, const T& x) const { - return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x); + PyObject* member_to_python(const T& x) const { + return boost::python::detail::import_extension_class::get_converters()->dispatcher_to_python(x); } friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) { @@ -102,7 +102,7 @@ class python_import_extension_class_converters return boost::python::detail::import_extension_class::get_converters()->from_python_caTr(p, t); } friend PyObject* to_python(boost::python::semantics, std::auto_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x); + return boost::python::detail::import_extension_class::get_converters()->dispatcher_to_python(x); } friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) { @@ -115,7 +115,7 @@ class python_import_extension_class_converters return boost::python::detail::import_extension_class::get_converters()->from_python_csTr(p, t); } friend PyObject* to_python(boost::python::semantics, boost::shared_ptr x, bool sig = false) { - return boost::python::detail::import_extension_class::get_converters()->to_python(x); + return boost::python::detail::import_extension_class::get_converters()->dispatcher_to_python(x); } }; @@ -123,8 +123,6 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE namespace boost { namespace python { -BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters); - /* This class template is instantiated by export_converters(). A pointer to this class is exported/imported via the Python API. Using the Python API ensures maximum portability. @@ -140,7 +138,7 @@ struct export_converter_object_base virtual int get_api_major() const { return detail::export_converters_api_major; } virtual int get_api_minor() const { return detail::export_converters_api_minor; } - virtual PyObject* to_python(const T& x) = 0; + virtual PyObject* dispatcher_to_python(const T& x) = 0; virtual T* from_python_Ts(PyObject* p, type t) = 0; virtual const T* from_python_cTs(PyObject* p, type t) = 0; @@ -153,21 +151,21 @@ struct export_converter_object_base virtual std::auto_ptr& from_python_aTr(PyObject* p, type&> t) = 0; virtual std::auto_ptr from_python_aT(PyObject* p, type > t) = 0; virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) = 0; - virtual PyObject* to_python(std::auto_ptr x) = 0; + virtual PyObject* dispatcher_to_python(std::auto_ptr x) = 0; virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) = 0; virtual const boost::shared_ptr& from_python_sT(PyObject* p, type > t) = 0; virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) = 0; - virtual PyObject* to_python(boost::shared_ptr x) = 0; + virtual PyObject* dispatcher_to_python(boost::shared_ptr x) = 0; }; // Converters to be used if T is not copyable. template struct export_converter_object_noncopyable : export_converter_object_base { - virtual PyObject* to_python(const T& x) { + virtual PyObject* dispatcher_to_python(const T& x) { PyErr_SetString(PyExc_RuntimeError, - "to_python(const T&) converter not exported"); + "to_python(boost::python::semantics, const T&) converter not exported"); throw import_error(); } @@ -202,8 +200,8 @@ struct export_converter_object_noncopyable : export_converter_object_base virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) { return from_python(p, t); } - virtual PyObject* to_python(std::auto_ptr x) { - return to_python(x); + virtual PyObject* dispatcher_to_python(std::auto_ptr x) { + return to_python(search_namespace, x); } virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) { @@ -215,8 +213,8 @@ struct export_converter_object_noncopyable : export_converter_object_base virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) { return from_python(p, t); } - virtual PyObject* to_python(boost::shared_ptr x) { - return to_python(x); + virtual PyObject* dispatcher_to_python(boost::shared_ptr x) { + return to_python(search_namespace, x); } }; @@ -224,8 +222,8 @@ struct export_converter_object_noncopyable : export_converter_object_base template struct export_converter_object : export_converter_object_noncopyable { - virtual PyObject* to_python(const T& x) { - return BOOST_PYTHON_CONVERSION::py_extension_class_converters(type()).to_python(x); + virtual PyObject* dispatcher_to_python(const T& x) { + return py_extension_class_converters(type()).member_to_python(x); } }; diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp index 5f893f26..34790f1f 100644 --- a/include/boost/python/detail/extension_class.hpp +++ b/include/boost/python/detail/extension_class.hpp @@ -195,7 +195,7 @@ class python_extension_class_converters } /// This is a member function because in a conforming implementation, friend - /// funcitons defined inline in the class body are all instantiated as soon + /// functions defined inline in the class body are all instantiated as soon /// as the enclosing class is instantiated. If T is not copyable, that causes /// a compiler error. Instead, we access this function through the global /// template @@ -205,7 +205,7 @@ class python_extension_class_converters /// defined below this class. Since template functions are instantiated only /// on demand, errors will be avoided unless T is noncopyable and the user /// writes code which causes us to try to copy a T. - PyObject* to_python(const T& x) const + PyObject* member_to_python(const T& x) const { boost::python::reference result(create_instance()); result->add_implementation( @@ -240,13 +240,8 @@ class python_extension_class_converters /// Convert obj to T*. If obj == None, returns 0. friend T* from_python(PyObject* obj, boost::python::type) { - // forward declaration needed for ordinary lookup. - T* non_null_from_python(PyObject*, boost::python::type); - - if (obj == Py_None) - return 0; - else - return non_null_from_python(obj, boost::python::type()); + if (obj == Py_None) return 0; + return non_null_from_python(obj, boost::python::type()); } /// Extract from obj a mutable reference to the PtrType object which is holding a T. @@ -369,15 +364,13 @@ class python_extension_class_converters template PyObject* to_python(boost::python::semantics, const T& x) { - return py_extension_class_converters(boost::python::type()).to_python(x); + return py_extension_class_converters(boost::python::type()).member_to_python(x); } BOOST_PYTHON_END_CONVERSION_NAMESPACE namespace boost { namespace python { -BOOST_PYTHON_IMPORT_CONVERSION(python_extension_class_converters); - namespace detail { template class instance_holder; diff --git a/include/boost/python/objects.hpp b/include/boost/python/objects.hpp index c8b4840f..5a146781 100644 --- a/include/boost/python/objects.hpp +++ b/include/boost/python/objects.hpp @@ -297,7 +297,7 @@ struct list::slice_proxy BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE -PyObject* to_python(boost::python::search_namespace, const boost::python::tuple&); +PyObject* to_python(boost::python::semantics, const boost::python::tuple&); boost::python::tuple from_python(PyObject* p, boost::python::type); inline boost::python::tuple from_python(PyObject* p, boost::python::type) @@ -305,7 +305,7 @@ inline boost::python::tuple from_python(PyObject* p, boost::python::type()); } -PyObject* to_python(boost::python::search_namespace, const boost::python::list&); +PyObject* to_python(boost::python::semantics, const boost::python::list&); boost::python::list from_python(PyObject* p, boost::python::type); inline boost::python::list from_python(PyObject* p, boost::python::type) @@ -313,7 +313,7 @@ inline boost::python::list from_python(PyObject* p, boost::python::type()); } -PyObject* to_python(boost::python::search_namespace, const boost::python::string&); +PyObject* to_python(boost::python::semantics, const boost::python::string&); boost::python::string from_python(PyObject* p, boost::python::type); inline boost::python::string from_python(PyObject* p, boost::python::type) @@ -321,7 +321,7 @@ inline boost::python::string from_python(PyObject* p, boost::python::type()); } -PyObject* to_python(boost::python::search_namespace, const boost::python::dictionary&); +PyObject* to_python(boost::python::semantics, const boost::python::dictionary&); boost::python::dictionary from_python(PyObject* p, boost::python::type); inline boost::python::dictionary from_python(PyObject* p, boost::python::type) diff --git a/include/boost/python/operators.hpp b/include/boost/python/operators.hpp index 0227b563..b4eaf1fa 100644 --- a/include/boost/python/operators.hpp +++ b/include/boost/python/operators.hpp @@ -239,7 +239,7 @@ namespace detail { \ tuple args(ref(arguments, ref::increment_count)); \ \ - return to_python(search_namespace \ + return to_python(search_namespace, \ from_python(args[0].get(), type()) oper \ from_python(args[1].get(), type())); \ } \ @@ -255,7 +255,7 @@ namespace detail { \ tuple args(ref(arguments, ref::increment_count)); \ \ - return to_python(search_namespace \ + return to_python(search_namespace, \ from_python(args[1].get(), type()) oper \ from_python(args[0].get(), type())); \ } \ diff --git a/include/boost/python/reference.hpp b/include/boost/python/reference.hpp index 6c05dd05..10d1412d 100644 --- a/include/boost/python/reference.hpp +++ b/include/boost/python/reference.hpp @@ -38,8 +38,6 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE namespace boost { namespace python { -BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions); - template class reference : public py_ptr_conversions, T,