An improvement to error reporting and

more tests added to std::vector.




git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9723 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-04-30 17:53:04 +00:00
commit 7c4d3d8bd8
3 changed files with 13 additions and 7 deletions

View file

@ -52,6 +52,7 @@ swig_assert_each_line(<<'EOF')
@iv.unshift(7, 3)
@iv.insert(1,5)
@iv.insert(0, 3)
@iv.unshift(2,3,4)
x = average(@iv)
y = average([1, 2, 3, 4])
half([10, 10.5, 11, 11.5])

View file

@ -105,9 +105,7 @@ const char* Ruby_Format_TypeError( const char* msg,
str = rb_str_new(NULL, 0);
}
str = rb_str_cat2( str, "in method '" );
str = rb_str_cat2( str, name );
str = rb_str_cat2( str, "', argument " );
str = rb_str_cat2( str, "Expected argument " );
sprintf( buf, "%d of type ", argn-1 );
str = rb_str_cat2( str, buf );
str = rb_str_cat2( str, type );
@ -125,5 +123,12 @@ const char* Ruby_Format_TypeError( const char* msg,
str = rb_str_append( str, asStr );
}
if ( name )
{
str = rb_str_cat2( str, "\n\tin SWIG method '" );
str = rb_str_cat2( str, name );
str = rb_str_cat2( str, "'\n" );
}
return StringValuePtr( str );
}

View file

@ -111,11 +111,11 @@ namespace swig {
Type v;
int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) {
if (throw_error) throw std::invalid_argument("bad type");
VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
}
return v;
}
@ -136,12 +136,12 @@ namespace swig {
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (throw_error) throw std::invalid_argument("bad type");
VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
static Type *v_def = (Type*) malloc(sizeof(Type));
memset(v_def,0,sizeof(Type));
return *v_def;
}
@ -156,11 +156,11 @@ namespace swig {
if (SWIG_IsOK(res)) {
return v;
} else {
if (throw_error) throw std::invalid_argument("bad type");
VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
return 0;
}
}