diff --git a/gen_extclass.py b/gen_extclass.py index 3e8896c6..6de88b92 100644 --- a/gen_extclass.py +++ b/gen_extclass.py @@ -126,41 +126,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 @@ -221,9 +186,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(); @@ -273,7 +238,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& @@ -327,9 +292,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 { @@ -417,14 +379,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)); } }; } @@ -478,7 +440,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) @@ -489,11 +451,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) { @@ -504,12 +466,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) { @@ -518,11 +480,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) { @@ -583,7 +545,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 @@ -600,7 +562,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 @@ -728,7 +690,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 @@ -797,7 +759,7 @@ class ExtensionInstance : public Instance namespace detail { - Tuple extension_class_coerce(PyObject * l, PyObject * r); + Tuple extension_class_coerce(Ptr l, Ptr r); } template @@ -825,7 +787,7 @@ void ExtensionClass::register_coerce() template inline -std::vector const & +std::vector const& ExtensionClass::base_classes() const { return ClassRegistry::base_classes(); @@ -833,7 +795,7 @@ ExtensionClass::base_classes() const template inline -std::vector const & +std::vector const& ExtensionClass::derived_classes() const { return ClassRegistry::derived_classes(); @@ -872,13 +834,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); }