Merge branch 'tamuratak-fix_ruby_bool'

* tamuratak-fix_ruby_bool:
  [ruby] must not do null check for VALUE obj, which can be 0x0 == Qfalse, a valid Ruby object.
This commit is contained in:
William S Fulton 2017-03-24 20:06:03 +00:00
commit 3797eaac89
4 changed files with 12 additions and 6 deletions

View file

@ -13,6 +13,8 @@ require 'swig_assert'
require 'std_containers' require 'std_containers'
include Std_containers include Std_containers
swig_assert_equal("[true, false]", "videntb([true, false])")
swig_assert_each_line(<<'EOF', binding) swig_assert_each_line(<<'EOF', binding)
cube = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] cube = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]

View file

@ -115,6 +115,10 @@
return v; return v;
} }
std::vector<bool> videntb(const std::vector<bool>& v)
{
return v;
}
int get_elem(const std::vector<int>& v, int index) int get_elem(const std::vector<int>& v, int index)
{ {

View file

@ -246,7 +246,7 @@ typedef struct {
SWIGRUNTIME swig_ruby_owntype SWIGRUNTIME swig_ruby_owntype
SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) { SWIG_Ruby_AcquirePtr(VALUE obj, swig_ruby_owntype own) {
swig_ruby_owntype oldown = {0, 0}; swig_ruby_owntype oldown = {0, 0};
if (obj) { if (TYPE(obj) == T_DATA) {
oldown.datafree = RDATA(obj)->dfree; oldown.datafree = RDATA(obj)->dfree;
RDATA(obj)->dfree = own.datafree; RDATA(obj)->dfree = own.datafree;
} }

View file

@ -117,7 +117,7 @@ namespace swig {
static Type as(VALUE obj, bool throw_error) { static Type as(VALUE obj, bool throw_error) {
Type v; Type v;
int res = asval(obj, &v); int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) { if (!SWIG_IsOK(res)) {
if (throw_error) throw std::invalid_argument("bad type"); if (throw_error) throw std::invalid_argument("bad type");
VALUE lastErr = rb_gv_get("$!"); VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) { if (lastErr == Qnil) {
@ -132,7 +132,7 @@ namespace swig {
struct traits_as<Type, pointer_category> { struct traits_as<Type, pointer_category> {
static Type as(VALUE obj, bool throw_error) { static Type as(VALUE obj, bool throw_error) {
Type *v = 0; Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR); int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res) && v) { if (SWIG_IsOK(res) && v) {
if (SWIG_IsNewObj(res)) { if (SWIG_IsNewObj(res)) {
Type r(*v); Type r(*v);
@ -159,7 +159,7 @@ namespace swig {
struct traits_as<Type*, pointer_category> { struct traits_as<Type*, pointer_category> {
static Type* as(VALUE obj, bool throw_error) { static Type* as(VALUE obj, bool throw_error) {
Type *v = 0; Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR); int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res)) { if (SWIG_IsOK(res)) {
return v; return v;
} else { } else {
@ -181,7 +181,7 @@ namespace swig {
template <class Type> template <class Type>
struct traits_check<Type, value_category> { struct traits_check<Type, value_category> {
static bool check(VALUE obj) { static bool check(VALUE obj) {
int res = obj ? asval(obj, (Type *)(0)) : SWIG_ERROR; int res = asval(obj, (Type *)(0));
return SWIG_IsOK(res) ? true : false; return SWIG_IsOK(res) ? true : false;
} }
}; };
@ -189,7 +189,7 @@ namespace swig {
template <class Type> template <class Type>
struct traits_check<Type, pointer_category> { struct traits_check<Type, pointer_category> {
static bool check(VALUE obj) { static bool check(VALUE obj) {
int res = obj ? asptr(obj, (Type **)(0)) : SWIG_ERROR; int res = asptr(obj, (Type **)(0));
return SWIG_IsOK(res) ? true : false; return SWIG_IsOK(res) ? true : false;
} }
}; };