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.
This commit is contained in:
William S Fulton 2020-02-13 19:46:05 +00:00
commit 6cec69ef7b

View file

@ -13,24 +13,27 @@ namespace swig {
template <class Type> template <class Type>
struct traits_asptr<std::shared_ptr<Type> > { struct traits_asptr<std::shared_ptr<Type> > {
static int asptr(VALUE obj, std::shared_ptr<Type> **val) { 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_type_info *descriptor = type_info<std::shared_ptr<Type> >();
swig_ruby_owntype newmem = {0, 0}; if (val) {
int res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR; std::shared_ptr<Type> *p = 0;
if (SWIG_IsOK(res)) { swig_ruby_owntype newmem = {0, 0};
if (val) { res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR;
if (*val) { if (SWIG_IsOK(res)) {
**val = p ? *p : std::shared_ptr<Type>(); if (*val) {
} else { **val = p ? *p : std::shared_ptr<Type>();
*val = p; } else {
if (newmem.own & SWIG_CAST_NEW_MEMORY) { *val = p;
// Upcast for pointers to shared_ptr in this generic framework has not been implemented if (newmem.own & SWIG_CAST_NEW_MEMORY) {
res = SWIG_ERROR; // Upcast for pointers to shared_ptr in this generic framework has not been implemented
} res = SWIG_ERROR;
} }
} }
if (newmem.own & SWIG_CAST_NEW_MEMORY) if (newmem.own & SWIG_CAST_NEW_MEMORY)
delete p; delete p;
}
} else {
res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR;
} }
return res; return res;
} }