summaryrefslogtreecommitdiff
path: root/Lib/python/pycontainer.swg
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2019-02-18 18:50:22 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2019-02-18 18:50:22 +0000
commita628bf9b6f5bf79cc28cfa09dbb76279b4d97f77 (patch)
tree63823a6282197bcd3b33e7fa22a02c749bb8d0d2 /Lib/python/pycontainer.swg
parentb634905b65e4920312637343bd4c606a1e8806ad (diff)
downloadswig-a628bf9b6f5bf79cc28cfa09dbb76279b4d97f77.tar.gz
Python std::vector back-reference changes
Give reference in container_owner a more unique name (back_reference). Change back-reference 'ret' typemap to have a function name so that they are less unwittingly be used elsewhere where not intended. Note that they can be overridden by users if needed using: %extend std::vector { %typemap(ret) value_type const& __getitem__, value_type const& front, value_type const& back { ... } } These override the SWIG supplied versions because the SWIG supplied typemaps use non-const value_type&, but the methods use const, so the above have a higher precedence in the typemap search algorithm.
Diffstat (limited to 'Lib/python/pycontainer.swg')
-rw-r--r--Lib/python/pycontainer.swg10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index a2ee9522c..5c2a981ee 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -52,7 +52,7 @@ namespace swig {
struct container_owner {
// By default, do not add the back-reference (for value types)
// Specialization below will check the reference for pointer types.
- static bool reference(PyObject* child, PyObject* owner) {
+ static bool back_reference(PyObject* child, PyObject* owner) {
return false;
}
};
@@ -66,7 +66,7 @@ namespace swig {
*
* returns whether the reference was set or not
*/
- static bool reference(PyObject* child, PyObject* owner) {
+ static bool back_reference(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);
@@ -809,8 +809,10 @@ namespace swig
return self->size();
}
- %typemap(ret, fragment="reference_container_owner", noblock=1) value_type& {
- (void)swig::container_owner<swig::traits<$*1_ltype>::category>::reference($result, $self);
+ // Although __getitem__, front, back actually use a const value_type& return type, the typemaps below
+ // use non-const so that they can be easily overridden by users if necessary.
+ %typemap(ret, fragment="reference_container_owner", noblock=1) value_type& __getitem__, value_type& front, value_type& back {
+ (void)swig::container_owner<swig::traits<$*1_ltype>::category>::back_reference($result, $self);
}
}
%enddef