2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-28 07:22:31 +00:00

fixes tested with vc60, tru64cxx, irixCC, gcc2952

[SVN r10208]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-05-24 08:28:46 +00:00
parent f0a0e9ec02
commit dac8e861c8
6 changed files with 60 additions and 67 deletions

View File

@@ -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 EnumType> class enum_as_int_converters
: public BOOST_PYTHON_CONVERSION::py_enum_as_int_converters<EnumType> {};
: public py_enum_as_int_converters<EnumType> {};
template <class P, class T> 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>);
long from_python(PyObject* p, boost::python::type<const long&>);
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>);
unsigned long from_python(PyObject* p, boost::python::type<const unsigned long&>);
PyObject* to_python(boost::python::search_namespace, int);
PyObject* to_python(boost::python::semantics, int);
int from_python(PyObject*, boost::python::type<int>);
int from_python(PyObject*, boost::python::type<const int&>);
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>);
unsigned int from_python(PyObject*, boost::python::type<const unsigned int&>);
PyObject* to_python(boost::python::search_namespace, short);
PyObject* to_python(boost::python::semantics, short);
short from_python(PyObject*, boost::python::type<short>);
short from_python(PyObject*, boost::python::type<const short&>);
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>);
unsigned short from_python(PyObject*, boost::python::type<const unsigned short&>);
PyObject* to_python(boost::python::search_namespace, char);
PyObject* to_python(boost::python::semantics, char);
char from_python(PyObject*, boost::python::type<char>);
char from_python(PyObject*, boost::python::type<const char&>);
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>);
signed char from_python(PyObject*, boost::python::type<const signed char&>);
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>);
unsigned char from_python(PyObject*, boost::python::type<const unsigned char&>);
PyObject* to_python(boost::python::search_namespace, float);
PyObject* to_python(boost::python::semantics, float);
float from_python(PyObject*, boost::python::type<float>);
float from_python(PyObject*, boost::python::type<const float&>);
PyObject* to_python(boost::python::search_namespace, double);
PyObject* to_python(boost::python::semantics, double);
double from_python(PyObject*, boost::python::type<double>);
double from_python(PyObject*, boost::python::type<const double&>);
PyObject* to_python(boost::python::search_namespace, bool);
PyObject* to_python(boost::python::semantics, bool);
bool from_python(PyObject*, boost::python::type<bool>);
bool from_python(PyObject*, boost::python::type<const bool&>);
PyObject* to_python(boost::python::search_namespace, void);
PyObject* to_python(boost::python::semantics);
void from_python(PyObject*, boost::python::type<void>);
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<const char*>);
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>);
std::string from_python(PyObject*, boost::python::type<const std::string&>);
inline PyObject* to_python(boost::python::search_namespace, const std::complex<float>& x)
inline PyObject* to_python(boost::python::semantics, const std::complex<float>& x)
{
return boost::python::detail::complex_to_python<float>(x);
}
inline PyObject* to_python(boost::python::search_namespace, const std::complex<double>& x)
inline PyObject* to_python(boost::python::semantics, const std::complex<double>& x)
{
return boost::python::detail::complex_to_python<double>(x);
}
@@ -205,7 +209,7 @@ inline std::complex<float> 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<PyObject*>);
// Some standard conversions to/from smart pointer types. You can add your own
@@ -259,13 +263,13 @@ boost::shared_ptr<T> from_python(PyObject*p, boost::python::type<boost::shared_p
#if 0
template <class T>
PyObject* to_python(boost::python::search_namespace, std::auto_ptr<T> p)
PyObject* to_python(boost::python::semantics, std::auto_ptr<T> p)
{
return new boost::python::wrapped_pointer<std::auto_ptr<T>, T>(p);
}
template <class T>
PyObject* to_python(boost::python::search_namespace, boost::shared_ptr<T> p)
PyObject* to_python(boost::python::semantics, boost::shared_ptr<T> p)
{
return new boost::python::wrapped_pointer<boost::shared_ptr<T>, T>(p);
}
@@ -276,43 +280,43 @@ PyObject* to_python(boost::python::search_namespace, boost::shared_ptr<T> 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<const std::strin
return from_python(p, boost::python::type<std::string>());
}
inline PyObject* to_python(boost::python::search_namespace, PyObject* p)
inline PyObject* to_python(boost::python::semantics, PyObject* p)
{
Py_INCREF(p);
return p;

View File

@@ -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<T>::get_converters()->to_python(boost::python::search_namespace, x);
PyObject* member_to_python(const T& x) const {
return boost::python::detail::import_extension_class<T>::get_converters()->dispatcher_to_python(x);
}
friend T* from_python(PyObject* p, boost::python::type<T*> t, bool sig = false) {
@@ -102,7 +102,7 @@ class python_import_extension_class_converters
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_caTr(p, t);
}
friend PyObject* to_python(boost::python::semantics, std::auto_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(boost::python::search_namespace, x);
return boost::python::detail::import_extension_class<T>::get_converters()->dispatcher_to_python(x);
}
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t, bool sig = false) {
@@ -115,7 +115,7 @@ class python_import_extension_class_converters
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_csTr(p, t);
}
friend PyObject* to_python(boost::python::semantics, boost::shared_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
return boost::python::detail::import_extension_class<T>::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*> t) = 0;
virtual const T* from_python_cTs(PyObject* p, type<const T*> t) = 0;
@@ -153,21 +151,21 @@ struct export_converter_object_base
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, type<std::auto_ptr<T>&> t) = 0;
virtual std::auto_ptr<T> from_python_aT(PyObject* p, type<std::auto_ptr<T> > t) = 0;
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, type<const std::auto_ptr<T>&> t) = 0;
virtual PyObject* to_python(std::auto_ptr<T> x) = 0;
virtual PyObject* dispatcher_to_python(std::auto_ptr<T> x) = 0;
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, type<boost::shared_ptr<T>&> t) = 0;
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, type<boost::shared_ptr<T> > t) = 0;
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, type<const boost::shared_ptr<T>&> t) = 0;
virtual PyObject* to_python(boost::shared_ptr<T> x) = 0;
virtual PyObject* dispatcher_to_python(boost::shared_ptr<T> x) = 0;
};
// Converters to be used if T is not copyable.
template <class T>
struct export_converter_object_noncopyable : export_converter_object_base<T>
{
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<T>
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, type<const std::auto_ptr<T>&> t) {
return from_python(p, t);
}
virtual PyObject* to_python(std::auto_ptr<T> x) {
return to_python(x);
virtual PyObject* dispatcher_to_python(std::auto_ptr<T> x) {
return to_python(search_namespace, x);
}
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, type<boost::shared_ptr<T>&> t) {
@@ -215,8 +213,8 @@ struct export_converter_object_noncopyable : export_converter_object_base<T>
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, type<const boost::shared_ptr<T>&> t) {
return from_python(p, t);
}
virtual PyObject* to_python(boost::shared_ptr<T> x) {
return to_python(x);
virtual PyObject* dispatcher_to_python(boost::shared_ptr<T> x) {
return to_python(search_namespace, x);
}
};
@@ -224,8 +222,8 @@ struct export_converter_object_noncopyable : export_converter_object_base<T>
template <class T>
struct export_converter_object : export_converter_object_noncopyable<T>
{
virtual PyObject* to_python(const T& x) {
return BOOST_PYTHON_CONVERSION::py_extension_class_converters(type<T>()).to_python(x);
virtual PyObject* dispatcher_to_python(const T& x) {
return py_extension_class_converters(type<T>()).member_to_python(x);
}
};

View File

@@ -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<boost::python::detail::extension_instance> 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<T*>)
{
// forward declaration needed for ordinary lookup.
T* non_null_from_python(PyObject*, boost::python::type<T*>);
if (obj == Py_None)
return 0;
else
return non_null_from_python(obj, boost::python::type<T*>());
if (obj == Py_None) return 0;
return non_null_from_python(obj, boost::python::type<T*>());
}
/// 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 <class T>
PyObject* to_python(boost::python::semantics, const T& x)
{
return py_extension_class_converters(boost::python::type<T>()).to_python(x);
return py_extension_class_converters(boost::python::type<T>()).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 T> class instance_holder;

View File

@@ -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<boost::python::tuple>);
inline boost::python::tuple from_python(PyObject* p, boost::python::type<const boost::python::tuple&>)
@@ -305,7 +305,7 @@ inline boost::python::tuple from_python(PyObject* p, boost::python::type<const b
return from_python(p, boost::python::type<boost::python::tuple>());
}
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<boost::python::list>);
inline boost::python::list from_python(PyObject* p, boost::python::type<const boost::python::list&>)
@@ -313,7 +313,7 @@ inline boost::python::list from_python(PyObject* p, boost::python::type<const bo
return from_python(p, boost::python::type<boost::python::list>());
}
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<boost::python::string>);
inline boost::python::string from_python(PyObject* p, boost::python::type<const boost::python::string&>)
@@ -321,7 +321,7 @@ inline boost::python::string from_python(PyObject* p, boost::python::type<const
return from_python(p, boost::python::type<boost::python::string>());
}
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<boost::python::dictionary>);
inline boost::python::dictionary from_python(PyObject* p, boost::python::type<const boost::python::dictionary&>)

View File

@@ -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<Left>()) oper \
from_python(args[1].get(), type<Right>())); \
} \
@@ -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<Left>()) oper \
from_python(args[0].get(), type<Right>())); \
} \

View File

@@ -38,8 +38,6 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions);
template <class T>
class reference
: public py_ptr_conversions<reference<T>, T,