2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

use the new "no-rethrow" way of handling exceptions.

[SVN r11691]
This commit is contained in:
Dave Abrahams
2001-11-14 20:07:38 +00:00
parent 5bec0d2d98
commit 7d6ff83760
2 changed files with 48 additions and 7 deletions

View File

@@ -9,13 +9,50 @@
#ifndef ERRORS_DWA052500_H_
# define ERRORS_DWA052500_H_
# include <boost/python/detail/wrap_python.hpp>
namespace boost { namespace python {
struct error_already_set {};
struct argument_error : error_already_set {};
struct object_functor_base
{
typedef PyObject* result_type;
virtual PyObject* operator()() const = 0;
private:
static void* operator new(std::size_t); // don't allow dynamic allocation
void operator delete(void*);
void operator delete(void*, size_t);
};
template <class T>
struct object_functor : object_functor_base
{
object_functor(T const& f)
: m_f(f)
{
}
PyObject* operator()() const
{
return m_f();
}
private:
T const& m_f;
};
// Handles exceptions caught just before returning to Python code.
void handle_exception();
PyObject* handle_exception_impl(object_functor_base const& f);
template <class T>
PyObject* handle_exception(T const& f)
{
return handle_exception_impl(object_functor<T>(f));
}
void handle_exception(void (*)());
template <class T>
T* expect_non_null(T* x)

View File

@@ -10,8 +10,9 @@
// 04 Mar 01 Use PyObject_INIT() instead of trying to hand-initialize (David Abrahams)
#include <boost/python/detail/extension_class.hpp>
#include <cstring>
#include <boost/utility.hpp>
#include <boost/bind.hpp>
#include <cstring>
namespace boost { namespace python {
namespace detail {
@@ -484,16 +485,19 @@ void operator_dispatcher_dealloc(PyObject* self)
int operator_dispatcher_coerce(PyObject** l, PyObject** r)
{
Py_INCREF(*l);
try
PyObject* new_r = handle_exception(
bind(operator_dispatcher::create,
ref(*r, ref::increment_count),
ref()));
if (new_r)
{
*r = operator_dispatcher::create(ref(*r, ref::increment_count), ref());
*r = new_r;
return 0;
}
catch(...)
else
{
handle_exception();
return -1;
}
return 0;
}