From 661c3fc55472439803ff3b3742ad7c83228d2fb3 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Thu, 13 Apr 2017 15:43:25 +0900 Subject: [PATCH] [ruby] treat null shared_ptr in std containers properly. --- Lib/ruby/rubystdcommon_forward.swg | 3 ++- Lib/ruby/std_shared_ptr.i | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Lib/ruby/rubystdcommon_forward.swg b/Lib/ruby/rubystdcommon_forward.swg index 27bcb9960..4120b38e4 100644 --- a/Lib/ruby/rubystdcommon_forward.swg +++ b/Lib/ruby/rubystdcommon_forward.swg @@ -5,7 +5,8 @@ namespace swig { template struct traits_asval; struct pointer_category; template struct traits_as; - template struct traits_from; + template struct traits_from; + template struct traits_from_ptr; template struct noconst_traits; template swig_type_info* type_info(); template const char* type_name(); diff --git a/Lib/ruby/std_shared_ptr.i b/Lib/ruby/std_shared_ptr.i index f6c0a15ac..f2b05ef36 100644 --- a/Lib/ruby/std_shared_ptr.i +++ b/Lib/ruby/std_shared_ptr.i @@ -113,6 +113,17 @@ namespace swig { } }; + template + struct traits_from_ptr > { + static VALUE from(std::shared_ptr *val, int owner = 0) { + if (val && *val) { + return SWIG_NewPointerObj(val, type_info >(), owner); + } else { + return Qnil; + } + } + }; + /* The descriptors in the shared_ptr typemaps remove the const qualifier for the SWIG type system. Remove const likewise here, otherwise SWIG_TypeQuery("std::shared_ptr") will return NULL.