diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2020-02-13 19:46:05 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2020-02-13 19:48:30 +0000 |
commit | 6cec69ef7ba448f0be1ce3a51118bbbfc6f49aef (patch) | |
tree | 703e9d32ea6cfc4309e0119227f4ac45bf3ed462 /Lib/ruby | |
parent | 67a38589a8164237df82a65dc6f592b423012f87 (diff) | |
download | swig-6cec69ef7ba448f0be1ce3a51118bbbfc6f49aef.tar.gz |
Remove an unnecessary shared_ptr reference count increment in Ruby wrappers
When wrapping STL containers, remove a shared_ptr reference count
increment when an upcast is needed when checking type conversion
in traits_check::check.
Diffstat (limited to 'Lib/ruby')
-rw-r--r-- | Lib/ruby/std_shared_ptr.i | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/Lib/ruby/std_shared_ptr.i b/Lib/ruby/std_shared_ptr.i index dee35ec03..086e30814 100644 --- a/Lib/ruby/std_shared_ptr.i +++ b/Lib/ruby/std_shared_ptr.i @@ -13,24 +13,27 @@ namespace swig { template <class Type> struct traits_asptr<std::shared_ptr<Type> > { static int asptr(VALUE obj, std::shared_ptr<Type> **val) { - std::shared_ptr<Type> *p = 0; + int res = SWIG_ERROR; swig_type_info *descriptor = type_info<std::shared_ptr<Type> >(); - swig_ruby_owntype newmem = {0, 0}; - int res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR; - if (SWIG_IsOK(res)) { - if (val) { - if (*val) { - **val = p ? *p : std::shared_ptr<Type>(); - } else { - *val = p; - if (newmem.own & SWIG_CAST_NEW_MEMORY) { - // Upcast for pointers to shared_ptr in this generic framework has not been implemented - res = SWIG_ERROR; - } - } - } - if (newmem.own & SWIG_CAST_NEW_MEMORY) - delete p; + if (val) { + std::shared_ptr<Type> *p = 0; + swig_ruby_owntype newmem = {0, 0}; + res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR; + if (SWIG_IsOK(res)) { + if (*val) { + **val = p ? *p : std::shared_ptr<Type>(); + } else { + *val = p; + if (newmem.own & SWIG_CAST_NEW_MEMORY) { + // Upcast for pointers to shared_ptr in this generic framework has not been implemented + res = SWIG_ERROR; + } + } + if (newmem.own & SWIG_CAST_NEW_MEMORY) + delete p; + } + } else { + res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR; } return res; } |