From 8f121914d692b34f7b61428dc9024db4258edf3e Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 15 Nov 2000 17:16:28 +0000 Subject: [PATCH] Moved operator_dispatcher into extclass.cpp Fixed Ullrich's refcount bug Numerous formatting tweaks [SVN r8218] --- extclass.h | 86 +++++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 62 deletions(-) diff --git a/extclass.h b/extclass.h index 840293f3..a123cb95 100644 --- a/extclass.h +++ b/extclass.h @@ -121,41 +121,6 @@ class ClassRegistry static std::vector static_derived_class_info; }; -namespace detail -{ - struct operator_dispatcher - : public PyObject - { - static PyTypeObject type_object; - static PyNumberMethods number_methods; - - operator_dispatcher(PyObject * o, PyObject * s); - static void dealloc(PyObject *self); - static int coerce(PyObject ** l, PyObject ** r); - static PyObject * call_add(PyObject *, PyObject *); - static PyObject * call_sub(PyObject *, PyObject *); - static PyObject * call_mul(PyObject *, PyObject *); - static PyObject * call_div(PyObject *, PyObject *); - static PyObject * call_mod(PyObject *, PyObject *); - static PyObject * call_divmod(PyObject *, PyObject *); - static PyObject * call_lshift(PyObject *, PyObject *); - static PyObject * call_rshift(PyObject *, PyObject *); - static PyObject * call_and(PyObject *, PyObject *); - static PyObject * call_xor(PyObject *, PyObject *); - static PyObject * call_or(PyObject *, PyObject *); - static PyObject * call_pow(PyObject *, PyObject *, PyObject *); - static int call_cmp(PyObject *, PyObject *); - - static bool unwrap_args(PyObject * left, PyObject * right, - PyObject * & self, PyObject * & other); - static int unwrap_pow_args(PyObject *, PyObject *, PyObject *, - PyObject * &, PyObject * &, PyObject * &); - - PyObject * object; - PyObject * self; - }; -} - } PY_BEGIN_CONVERSION_NAMESPACE @@ -216,9 +181,9 @@ class PyExtensionClassConverters return held->target(); // see extclass.cpp for an explanation of try_class_conversions() - void * target = py::ClassRegistry::class_object()->try_class_conversions(*p); + void* target = py::ClassRegistry::class_object()->try_class_conversions(*p); if(target) - return static_cast(target); + return static_cast(target); } py::report_missing_instance_data(self, py::ClassRegistry::class_object(), typeid(T)); throw py::ArgumentError(); @@ -268,7 +233,7 @@ class PyExtensionClassConverters { return from_python(p, py::Type()); } // Convert to const T* const& - friend const T* from_python(PyObject* p, py::Type) + friend const T* from_python(PyObject* p, py::Type) { return from_python(p, py::Type()); } // Convert to T* const& @@ -322,9 +287,6 @@ PyObject* to_python(const T& x) return py_extension_class_converters(py::Type()).to_python(x); } -inline PyObject * to_python(py::detail::operator_dispatcher * n) { return n; } - - PY_END_CONVERSION_NAMESPACE namespace py { @@ -412,14 +374,14 @@ namespace detail template struct DefineConversion { - static void * upcast_ptr(void * v) + static void* upcast_ptr(void* v) { - return static_cast(static_cast(v)); + return static_cast(static_cast(v)); } - static void * downcast_ptr(void * v) + static void* downcast_ptr(void* v) { - return dynamic_cast(static_cast(v)); + return dynamic_cast(static_cast(v)); } }; } @@ -472,7 +434,7 @@ class ExtensionClass // export homogeneous operators (type of both lhs and rhs is 'operator') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub), Foo>()); - // export homogeneous operators (type of both lhs and rhs is 'T const &') + // export homogeneous operators (type of both lhs and rhs is 'T const&') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub)>()); template inline void def(operators) @@ -483,11 +445,11 @@ class ExtensionClass // export heterogeneous operators (type of lhs: 'left', of rhs: 'right') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub), Foo>(), - // py::right_operand()); + // py::right_operand()); - // export heterogeneous operators (type of lhs: 'T const &', of rhs: 'right') + // export heterogeneous operators (type of lhs: 'T const&', of rhs: 'right') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub)>(), - // py::right_operand()); + // py::right_operand()); template inline void def(operators, right_operand r) { @@ -498,12 +460,12 @@ class ExtensionClass // export heterogeneous reverse-argument operators // (type of lhs: 'left', of rhs: 'right') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub), Foo>(), - // py::left_operand()); + // py::left_operand()); // export heterogeneous reverse-argument operators - // (type of lhs: 'left', of rhs: 'T const &') + // (type of lhs: 'left', of rhs: 'T const&') // usage: foo_class.def(py::operators<(py::op_add | py::op_sub)>(), - // py::left_operand()); + // py::left_operand()); template inline void def(operators, left_operand l) { @@ -512,11 +474,11 @@ class ExtensionClass } // define a function that passes Python arguments and keywords - // to C++ verbatim (as a 'Tuple const &' and 'Dict const &' + // to C++ verbatim (as a 'Tuple const&' and 'Dict const&' // respectively). This is useful for manual argument passing. // It's also the only possibility to pass keyword arguments to C++. // Fn must have a signatur that is compatible to - // PyObject * (*)(PyObject * aTuple, PyObject * aDictionary) + // PyObject* (*)(PyObject* aTuple, PyObject* aDictionary) template inline void def_raw(Fn fn, const char* name) { @@ -577,7 +539,7 @@ class ExtensionClass // declare the given class a base class of this one and register // up and down conversion functions template - void declare_base(ExtensionClass * base) + void declare_base(ExtensionClass* base) { // see extclass.cpp for an explanation of why we need to register // conversion functions @@ -594,7 +556,7 @@ class ExtensionClass // declare the given class a base class of this one and register // only up conversion function template - void declare_base(ExtensionClass * base, WithoutDowncast) + void declare_base(ExtensionClass* base, WithoutDowncast) { // see extclass.cpp for an explanation of why we need to register // conversion functions @@ -729,7 +691,7 @@ template class InstanceHolder : public InstanceHolderBase { public: - virtual Held *target() = 0; + virtual Held*target() = 0; }; // Concrete class which holds a Held by way of a wrapper class Wrapper. If Held @@ -810,7 +772,7 @@ class ExtensionInstance : public Instance namespace detail { - Tuple extension_class_coerce(PyObject * l, PyObject * r); + Tuple extension_class_coerce(Ptr l, Ptr r); } template @@ -838,7 +800,7 @@ void ExtensionClass::register_coerce() template inline -std::vector const & +std::vector const& ExtensionClass::base_classes() const { return ClassRegistry::base_classes(); @@ -846,7 +808,7 @@ ExtensionClass::base_classes() const template inline -std::vector const & +std::vector const& ExtensionClass::derived_classes() const { return ClassRegistry::derived_classes(); @@ -885,13 +847,13 @@ inline void ClassRegistry::unregister_class(ExtensionClassBase* p) } template -void ClassRegistry::register_base_class(py::detail::BaseClassInfo const & i) +void ClassRegistry::register_base_class(py::detail::BaseClassInfo const& i) { static_base_class_info.push_back(i); } template -void ClassRegistry::register_derived_class(py::detail::DerivedClassInfo const & i) +void ClassRegistry::register_derived_class(py::detail::DerivedClassInfo const& i) { static_derived_class_info.push_back(i); }