aboutsummaryrefslogtreecommitdiff
path: root/Lib/python
diff options
context:
space:
mode:
authorJake Cobb <jake.cobb@gmail.com>2019-01-23 16:10:26 -0500
committerJake Cobb <jake.cobb@gmail.com>2019-01-23 16:10:26 -0500
commit40e327d742fa579a81573f900c0b8a9dcb9f5038 (patch)
treef955048dae4ec873573ba9e1756d2e9e55d13b84 /Lib/python
parent5185ce67b59045e20c1975319527b1ffbe705b20 (diff)
downloadswig-40e327d742fa579a81573f900c0b8a9dcb9f5038.tar.gz
Python: Avoid container owner check for value types
Diffstat (limited to 'Lib/python')
-rw-r--r--Lib/python/pycontainer.swg12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index b90068466..34bf3c110 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -40,6 +40,7 @@
// thread safe initialization
swig::container_owner_attribute();
}
+
%fragment("reference_container_owner", "header", fragment="container_owner_attribute_init") {
namespace swig {
PyObject* container_owner_attribute() {
@@ -47,6 +48,12 @@ namespace swig {
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
* 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
*/
- 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);
if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) {
PyObject_SetAttr(child, container_owner_attribute(), owner);
@@ -797,7 +805,7 @@ namespace swig
}
%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