[ruby] must not do null check for VALUE obj, which can be 0x0 == Qfalse, a valid Ruby object.

This commit is contained in:
Takashi Tamura 2017-03-06 15:13:05 +09:00
parent b451fc464b
commit d0af6fd97d
4 changed files with 12 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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