From 4cf7ab3425eb69b3d68b4edb0ac8906c0d08d7ab Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 13 Apr 2002 04:06:26 +0000 Subject: [PATCH] fixes for GCC .so/exception problems [SVN r13469] --- include/boost/python/classes.hpp | 8 ++++--- include/boost/python/cross_module.hpp | 12 +++++----- .../boost/python/detail/extension_class.hpp | 9 +++----- include/boost/python/detail/init_function.hpp | 22 +++++++++---------- include/boost/python/errors.hpp | 7 ++++-- include/boost/python/operators.hpp | 4 ++-- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/include/boost/python/classes.hpp b/include/boost/python/classes.hpp index 114bb16a..22fcb3d2 100644 --- a/include/boost/python/classes.hpp +++ b/include/boost/python/classes.hpp @@ -349,19 +349,21 @@ int class_t::instance_mapping_ass_subscript(PyObject* obj, PyObject* key, PyO return 0; } -void BOOST_PYTHON_DECL adjust_slice_indices(PyObject* obj, int& start, int& finish); +bool BOOST_PYTHON_DECL adjust_slice_indices(PyObject* obj, int& start, int& finish); template PyObject* class_t::instance_sequence_slice(PyObject* obj, int start, int finish) const { - adjust_slice_indices(obj, start, finish); + if (!adjust_slice_indices(obj, start, finish)) + return 0; return downcast(obj)->get_slice(start, finish); } template int class_t::instance_sequence_ass_slice(PyObject* obj, int start, int finish, PyObject* value) const { - adjust_slice_indices(obj, start, finish); + if (!adjust_slice_indices(obj, start, finish)) + return -1; downcast(obj)->set_slice(start, finish, value); return 0; } diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp index f5ca315d..c6ac8c22 100644 --- a/include/boost/python/cross_module.hpp +++ b/include/boost/python/cross_module.hpp @@ -18,8 +18,12 @@ # include namespace boost { namespace python { - struct BOOST_PYTHON_DECL import_error: error_already_set {}; - struct BOOST_PYTHON_DECL export_error : error_already_set {}; + +struct BOOST_PYTHON_DECL import_error: error_already_set {}; +struct BOOST_PYTHON_DECL export_error : error_already_set {}; + +void BOOST_PYTHON_DECL throw_import_error(); +void BOOST_PYTHON_DECL throw_export_error(); namespace detail { @@ -170,10 +174,8 @@ struct export_converter_object_noncopyable : export_converter_object_base virtual PyObject* to_python(const T& x) { PyErr_SetString(PyExc_RuntimeError, "to_python(const T&) converter not exported"); - throw import_error(); -#if defined(__MWERKS__) && __MWERKS__ <= 0x2406 + throw_import_error(); return 0; -#endif } virtual T* from_python_Ts(PyObject* p, boost::python::type t) { diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp index d3016744..19aec0eb 100644 --- a/include/boost/python/detail/extension_class.hpp +++ b/include/boost/python/detail/extension_class.hpp @@ -255,10 +255,8 @@ class python_extension_class_converters return static_cast(target); } boost::python::detail::report_missing_instance_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - throw boost::python::argument_error(); -#if defined(__MWERKS__) && __MWERKS__ <= 0x2406 + boost::python::throw_argument_error(); return 0; -#endif } // Convert to T* @@ -286,10 +284,9 @@ class python_extension_class_converters return held->ptr(); } boost::python::detail::report_missing_ptr_data(self, boost::python::detail::class_registry::class_object(), typeid(T)); - throw boost::python::argument_error(); -#if defined(__MWERKS__) && __MWERKS__ <= 0x2406 + boost::python::throw_argument_error(); + return *(PtrType*)0; -#endif } // Extract from obj a reference to the PtrType object which is holding a diff --git a/include/boost/python/detail/init_function.hpp b/include/boost/python/detail/init_function.hpp index 048c90dd..928159c2 100644 --- a/include/boost/python/detail/init_function.hpp +++ b/include/boost/python/detail/init_function.hpp @@ -299,7 +299,7 @@ struct init0 : init virtual instance_holder_base* create_holder(extension_instance* self, PyObject* args, PyObject* /*keywords*/) const { if (!PyArg_ParseTuple(args, const_cast(""))) - throw argument_error(); + throw_argument_error(); return new T(self ); } @@ -314,7 +314,7 @@ struct init1 : init { PyObject* a1; if (!PyArg_ParseTuple(args, const_cast("O"), &a1)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())) ); @@ -331,7 +331,7 @@ struct init2 : init PyObject* a1; PyObject* a2; if (!PyArg_ParseTuple(args, const_cast("OO"), &a1, &a2)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())) @@ -350,7 +350,7 @@ struct init3 : init PyObject* a2; PyObject* a3; if (!PyArg_ParseTuple(args, const_cast("OOO"), &a1, &a2, &a3)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -371,7 +371,7 @@ struct init4 : init PyObject* a3; PyObject* a4; if (!PyArg_ParseTuple(args, const_cast("OOOO"), &a1, &a2, &a3, &a4)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -394,7 +394,7 @@ struct init5 : init PyObject* a4; PyObject* a5; if (!PyArg_ParseTuple(args, const_cast("OOOOO"), &a1, &a2, &a3, &a4, &a5)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -419,7 +419,7 @@ struct init6 : init PyObject* a5; PyObject* a6; if (!PyArg_ParseTuple(args, const_cast("OOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -446,7 +446,7 @@ struct init7 : init PyObject* a6; PyObject* a7; if (!PyArg_ParseTuple(args, const_cast("OOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -475,7 +475,7 @@ struct init8 : init PyObject* a7; PyObject* a8; if (!PyArg_ParseTuple(args, const_cast("OOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -506,7 +506,7 @@ struct init9 : init PyObject* a8; PyObject* a9; if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), @@ -539,7 +539,7 @@ struct init10 : init PyObject* a9; PyObject* a10; if (!PyArg_ParseTuple(args, const_cast("OOOOOOOOOO"), &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10)) - throw argument_error(); + throw_argument_error(); return new T(self, boost::python::detail::reference_parameter(from_python(a1, type())), boost::python::detail::reference_parameter(from_python(a2, type())), diff --git a/include/boost/python/errors.hpp b/include/boost/python/errors.hpp index d0f71a24..02fbeff9 100644 --- a/include/boost/python/errors.hpp +++ b/include/boost/python/errors.hpp @@ -15,8 +15,8 @@ namespace boost { namespace python { -struct error_already_set {}; -struct argument_error : error_already_set {}; +struct BOOST_PYTHON_DECL error_already_set {}; +struct BOOST_PYTHON_DECL argument_error : error_already_set {}; // Handles exceptions caught just before returning to Python code. // Returns true iff an exception was caught. @@ -43,6 +43,9 @@ T* expect_non_null(T* x) return (T*)expect_non_null((PyObject*)x); } +BOOST_PYTHON_DECL void throw_argument_error(); +BOOST_PYTHON_DECL void throw_error_already_set(); + }} // namespace boost::python #endif // ERRORS_DWA052500_H_ diff --git a/include/boost/python/operators.hpp b/include/boost/python/operators.hpp index c766c8b6..70e57b71 100644 --- a/include/boost/python/operators.hpp +++ b/include/boost/python/operators.hpp @@ -344,7 +344,7 @@ namespace detail if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type) { PyErr_SetString(PyExc_TypeError, "expected 2 arguments, got 3"); - throw argument_error(); + throw_argument_error(); } return BOOST_PYTHON_CONVERSION::to_python( @@ -367,7 +367,7 @@ namespace detail if (args.size() == 3 && args[2]->ob_type != Py_None->ob_type) { PyErr_SetString(PyExc_TypeError, "bad operand type(s) for pow()"); - throw argument_error(); + throw_argument_error(); } return BOOST_PYTHON_CONVERSION::to_python(