From 9a183f6cfcb9bfc57166324955a38f3caa515cec Mon Sep 17 00:00:00 2001 From: Gonzalo Garramuno Date: Sun, 29 Apr 2007 22:26:30 +0000 Subject: [PATCH] Made Ruby_Format_TypeError() thread safe. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9713 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ruby/rubyerrors.swg | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Lib/ruby/rubyerrors.swg b/Lib/ruby/rubyerrors.swg index 53c494f8e..3ddba31cc 100644 --- a/Lib/ruby/rubyerrors.swg +++ b/Lib/ruby/rubyerrors.swg @@ -90,10 +90,40 @@ SWIG_Ruby_ErrorType(int SWIG_code) { const char* Ruby_Format_TypeError( const char* msg, const char* type, const char* name, - const int argn ) + const int argn, + VALUE input ) { - static char buf[1024]; - sprintf( buf, "%sin method '%s', argument %d of type %s", - msg, name, argn-1, type ); - return buf; + char buf[128]; + VALUE str; + if ( msg && *msg ) + { + str = rb_str_new2(msg); + } + else + { + 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 " ); + sprintf( buf, "%d of type ", argn ); + str = rb_str_cat2( str, buf ); + str = rb_str_cat2( str, type ); + str = rb_str_cat2( str, ", but got " ); + str = rb_str_cat2( str, rb_obj_classname(input) ); + str = rb_str_cat2( str, " (" ); + VALUE asStr = rb_obj_as_string(input); + if ( RSTRING_LEN(asStr) > 30 ) + { + str = rb_str_cat( str, StringValuePtr(asStr), 30 ); + str = rb_str_cat2( str, "..." ); + } + else + { + str = rb_str_concat( str, asStr ); + } + str = rb_str_cat2( str, ")" ); + + return StringValuePtr( str ); }