Python: Avoid container owner check for value types
This commit is contained in:
parent
5185ce67b5
commit
40e327d742
1 changed files with 10 additions and 2 deletions
|
|
@ -40,6 +40,7 @@
|
||||||
// thread safe initialization
|
// thread safe initialization
|
||||||
swig::container_owner_attribute();
|
swig::container_owner_attribute();
|
||||||
}
|
}
|
||||||
|
|
||||||
%fragment("reference_container_owner", "header", fragment="container_owner_attribute_init") {
|
%fragment("reference_container_owner", "header", fragment="container_owner_attribute_init") {
|
||||||
namespace swig {
|
namespace swig {
|
||||||
PyObject* container_owner_attribute() {
|
PyObject* container_owner_attribute() {
|
||||||
|
|
@ -47,6 +48,12 @@ namespace swig {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By default, do not add the back-reference (for value types)
|
||||||
|
// Specialization below will check the reference for pointer types.
|
||||||
|
template <typename Type>
|
||||||
|
bool reference_container_owner(PyObject* child, PyObject* owner)
|
||||||
|
{ return false; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call to add a back-reference to the owning object when returning a
|
* Call to add a back-reference to the owning object when returning a
|
||||||
* reference from a container. Will only set the reference if <code>child</code>
|
* reference from a container. Will only set the reference if <code>child</code>
|
||||||
|
|
@ -54,7 +61,8 @@ namespace swig {
|
||||||
*
|
*
|
||||||
* @return if the reference was set or not
|
* @return if the reference was set or not
|
||||||
*/
|
*/
|
||||||
bool reference_container_owner(PyObject* child, PyObject* owner) {
|
template <>
|
||||||
|
bool reference_container_owner<swig::pointer_category>(PyObject* child, PyObject* owner) {
|
||||||
SwigPyObject* swigThis = SWIG_Python_GetSwigThis(child);
|
SwigPyObject* swigThis = SWIG_Python_GetSwigThis(child);
|
||||||
if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) {
|
if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) {
|
||||||
PyObject_SetAttr(child, container_owner_attribute(), owner);
|
PyObject_SetAttr(child, container_owner_attribute(), owner);
|
||||||
|
|
@ -797,7 +805,7 @@ namespace swig
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(ret, fragment="reference_container_owner") value_type& {
|
%typemap(ret, fragment="reference_container_owner") value_type& {
|
||||||
swig::reference_container_owner($result, $self);
|
swig::reference_container_owner<swig::traits<$*1_ltype>::category>($result, $self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue