diff options
author | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-05 11:22:51 +0000 |
---|---|---|
committer | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-05 11:22:51 +0000 |
commit | d9498f743b8a0e361908d62ae429f7719124170a (patch) | |
tree | 45be633ce0285a078378db56d7134374bc38ee0c /ext/tk | |
parent | 993ad912a266f48e165029241375c41918ec6b8a (diff) | |
download | ruby-d9498f743b8a0e361908d62ae429f7719124170a.tar.gz |
* ext/tk/tcltklib.c: rectoring - tcl_protect.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/tcltklib.c | 65 |
1 files changed, 13 insertions, 52 deletions
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index 433b7ec2b0..b5fe92e80d 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/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; |