diff --git a/extclass.h b/extclass.h index 66e8bbe0..f338f29d 100644 --- a/extclass.h +++ b/extclass.h @@ -82,7 +82,7 @@ class ExtensionClassBase : public Class void* try_base_class_conversions(InstanceHolderBase*) const; void* try_derived_class_conversions(InstanceHolderBase*) const; - void set_attribute(const char* name, PyObject* x_); + void set_attribute(const char* name, PyObject* x); void set_attribute(const char* name, Ptr x); private: @@ -234,6 +234,14 @@ class PyExtensionClassConverters friend const T* from_python(PyObject* p, py::Type) { return from_python(p, py::Type()); } + // Convert to const T* const& + friend const T* from_python(PyObject* p, py::Type) + { return from_python(p, py::Type()); } + + // Convert to T* const& + friend T* from_python(PyObject* p, py::Type) + { return from_python(p, py::Type()); } + // Convert to T& friend T& from_python(PyObject* p, py::Type) { return *py::check_non_null(from_python(p, py::Type())); } diff --git a/gen_extclass.py b/gen_extclass.py index 3569dc68..64363ce9 100644 --- a/gen_extclass.py +++ b/gen_extclass.py @@ -87,7 +87,7 @@ class ExtensionClassBase : public Class void* try_base_class_conversions(InstanceHolderBase*) const; void* try_derived_class_conversions(InstanceHolderBase*) const; - void set_attribute(const char* name, PyObject* x_); + void set_attribute(const char* name, PyObject* x); void set_attribute(const char* name, Ptr x); private: @@ -239,6 +239,14 @@ class PyExtensionClassConverters friend const T* from_python(PyObject* p, py::Type) { return from_python(p, py::Type()); } + // Convert to const T* const& + friend const T* from_python(PyObject* p, py::Type) + { return from_python(p, py::Type()); } + + // Convert to T* const& + friend T* from_python(PyObject* p, py::Type) + { return from_python(p, py::Type()); } + // Convert to T& friend T& from_python(PyObject* p, py::Type) { return *py::check_non_null(from_python(p, py::Type())); }