From 0ffbf6bca4e5b1dba25e4268015f5e395c79df27 Mon Sep 17 00:00:00 2001 From: ocean Date: Fri, 5 Aug 2005 11:22:18 +0000 Subject: * ext/tcltklib/tcltklib.c: rectoring - tcl_protect. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tcltklib/tcltklib.c | 65 ++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 52 deletions(-) diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index 433b7ec2b0..b5fe92e80d 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -2157,56 +2157,25 @@ tcl_protect(proc, data, failed) ret = rb_protect(proc, data, &status); rb_thread_critical = Qtrue; if (status) { - char *errtype, *buf; - int errtype_len, len; - VALUE old_gc; + char *buf; + VALUE old_gc, type, str; old_gc = rb_gc_disable(); switch(status) { case TAG_RETURN: - errtype = "LocalJumpError: "; - errtype_len = strlen(errtype); - len = errtype_len + RSTRING(rb_obj_as_string(ruby_errinfo))->len; - buf = ALLOC_N(char, len + 1); - memcpy(buf, errtype, errtype_len); - memcpy(buf + errtype_len, - RSTRING(rb_obj_as_string(ruby_errinfo))->ptr, - RSTRING(rb_obj_as_string(ruby_errinfo))->len); - *(buf + len) = 0; - - RARRAY(failed)->ptr[0] = rb_exc_new2(eTkCallbackReturn, buf); - free(buf); - break; - + type = eTkCallbackReturn; + goto error; case TAG_BREAK: - errtype = "LocalJumpError: "; - errtype_len = strlen(errtype); - len = errtype_len + RSTRING(rb_obj_as_string(ruby_errinfo))->len; - buf = ALLOC_N(char, len + 1); - memcpy(buf, errtype, errtype_len); - memcpy(buf + errtype_len, - RSTRING(rb_obj_as_string(ruby_errinfo))->ptr, - RSTRING(rb_obj_as_string(ruby_errinfo))->len); - *(buf + len) = 0; - - RARRAY(failed)->ptr[0] = rb_exc_new2(eTkCallbackBreak, buf); - free(buf); - break; - + type = eTkCallbackBreak; + goto error; case TAG_NEXT: - errtype = "LocalJumpError: "; - errtype_len = strlen(errtype); - len = errtype_len + RSTRING(rb_obj_as_string(ruby_errinfo))->len; - buf = ALLOC_N(char, len + 1); - memcpy(buf, errtype, errtype_len); - memcpy(buf + errtype_len, - RSTRING(rb_obj_as_string(ruby_errinfo))->ptr, - RSTRING(rb_obj_as_string(ruby_errinfo))->len); - *(buf + len) = 0; - - RARRAY(failed)->ptr[0] = rb_exc_new2(eTkCallbackContinue,buf); - free(buf); + type = eTkCallbackContinue; + goto error; + error: + str = rb_str_new2("LocalJumpError: "); + rb_str_append(str, rb_obj_as_string(ruby_errinfo)); + RARRAY(failed)->ptr[0] = rb_exc_new3(type, str); break; case TAG_RETRY: @@ -2815,13 +2784,7 @@ ip_RubyExitCommand(clientData, interp, argc, argv) Tcl_ResetResult(interp); - if (rb_safe_level() >= 4) { - ip_finalize(interp); - Tcl_DeleteInterp(interp); - Tcl_Release(interp); - return TCL_OK; - - } else if (Tcl_IsSafe(interp)) { + if (rb_safe_level() >= 4 || Tcl_IsSafe(interp)) { ip_finalize(interp); Tcl_DeleteInterp(interp); Tcl_Release(interp); @@ -4334,7 +4297,6 @@ ip_thread_vwait(self, var) VALUE var; { VALUE argv[2]; - VALUE retval; volatile VALUE cmd_str = rb_str_new2("thread_vwait"); argv[0] = cmd_str; @@ -4350,7 +4312,6 @@ ip_thread_tkwait(self, mode, target) VALUE target; { VALUE argv[3]; - VALUE retval; volatile VALUE cmd_str = rb_str_new2("thread_tkwait"); argv[0] = cmd_str; -- cgit v1.2.3