From 865ff7fb4f11bbf1f0e139e16470727828f54e63 Mon Sep 17 00:00:00 2001 From: nagai Date: Sun, 7 Sep 2003 07:10:44 +0000 Subject: * tcltklib.c (lib_mainloop_core): fixed signal-trap bug * multi-tk.rb, tk.rb, tkafter.rb, tkcanvas.rb, tkfont.rb, tktext.rb, tkvirtevent.rb : Ruby/Tk works at $SAFE == 4 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tcltklib/MANUAL.euc | 11 ++++++++++- ext/tcltklib/tcltklib.c | 36 +++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 12 deletions(-) (limited to 'ext/tcltklib') diff --git a/ext/tcltklib/MANUAL.euc b/ext/tcltklib/MANUAL.euc index f04d036c64..8a7143892c 100644 --- a/ext/tcltklib/MANUAL.euc +++ b/ext/tcltklib/MANUAL.euc @@ -192,13 +192,16 @@ require "tcltklib" : ( 監視スレッドを生成した後にイベントループを実行する ). : 引数の意味は mainloop と同じである. - do_one_event(flag = TclTkLib::EventFlag::ALL) + do_one_event(flag = TclTkLib::EventFlag::ALL | + TclTkLib::EventFlag::DONT_WAIT) : 処理待ちのイベント 1 個を実行する. : イベントを処理した場合は true を返す. : フラグで DONT_WAIT を指定していない場合,フラグで処理対 : 象となっている種類のイベントが発生するまで待ち続ける. : DONT_WAIT を指定していた場合,処理対象イベントがなくても : すぐに終了し false を返す. + : $SAFE >= 4 か,$SAFE >= 1 かつ flag が汚染されているならば + : flag には DONT_WAIT が強制的に付けられる. set_eventloop_tick(timer_tick) : イベントループと同時に別スレッドが稼働している場合に,時 @@ -213,6 +216,7 @@ require "tcltklib" : 定される. : 詳細な説明は略すが,これは CPU パワーを節約しつつ安全で : 安定した動作を実現するために実装した仕様である. + : $SAFE >= 4 では実行が禁止される. get_eventloop_tick : timer_tick の現在値を返す. @@ -222,6 +226,7 @@ require "tcltklib" : く存在しなかった際に sleep 状態に入る時間長を指定する. : 稼働スレッドがイベントループだけの場合には意味をなさない. : デフォルトの値は 20 (ms) + : $SAFE >= 4 では実行が禁止される. get_no_event_wait : no_event_wait の現在値を返す. @@ -239,6 +244,7 @@ require "tcltklib" : が全く発生しないままに 80 回の処理待ちイベント検査が完了 : するとかでカウントが 800 以上になるとスレッドスイッチング : が発生することになる. + : $SAFE >= 4 では実行が禁止される. get_eventloop_weight : 現在の loop_max と no_event_tick との値を返す. @@ -258,6 +264,7 @@ require "tcltklib" : 他のインタープリタの処理継続が不可能になることがある.その : ような場合でもエラーを無視してイベントループが稼働を続ける : ことで,他のインタープリタが正常に動作し続けることができる. + : $SAFE >= 4 では実行が禁止される. mainloop_abort_on_exception : Tk インタープリタ上で例外を発生した際に,イベントループをエ @@ -295,6 +302,7 @@ require "tcltklib" : たとえ明確に false を指定していたとしても,親となるインター : プリタが safe インタープリタであれば,その設定を引き継いで : safe インタープリタとして生成される. + : $SAFE >= 4 では,safe インタープリタ以外の生成が禁止される. make_safe : Tcl/Tk インタープリタを safe インタープリタに変更する. @@ -319,6 +327,7 @@ require "tcltklib" : Tcl/Tk インタープリタの Tk 部分の初期化,再起動を行う. : 一旦 root widget を破壊した後に再度 Tk の機能が必要と : なった場合に用いる. + : $SAFE >= 4 では実行が禁止される. _eval(str) _invoke(*args) diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index ef91fcae3d..fdc4b00305 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -154,6 +154,8 @@ set_eventloop_tick(self, tick) { int ttick = NUM2INT(tick); + rb_secure(4); + if (ttick < 0) { rb_raise(rb_eArgError, "timer-tick parameter must be 0 or positive number"); @@ -209,6 +211,8 @@ set_no_event_wait(self, wait) { int t_wait = NUM2INT(wait); + rb_secure(4); + if (t_wait <= 0) { rb_raise(rb_eArgError, "no_event_wait parameter must be positive number"); @@ -256,6 +260,8 @@ set_eventloop_weight(self, loop_max, no_event) int lpmax = NUM2INT(loop_max); int no_ev = NUM2INT(no_event); + rb_secure(4); + if (lpmax <= 0 || no_ev <= 0) { rb_raise(rb_eArgError, "weight parameters must be positive numbers"); } @@ -336,6 +342,7 @@ ip_evloop_abort_on_exc_set(self, val) { struct tcltkip *ptr = get_ip(self); + rb_secure(4); if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) { /* slave IP */ return lib_evloop_abort_on_exc(self); @@ -392,6 +399,8 @@ lib_mainloop_core(check_root_widget) if (run_timer_flag) { DUMP1("timer interrupt"); run_timer_flag = 0; + DUMP1("call rb_trap_exec()"); + rb_trap_exec(); DUMP1("check Root Widget"); if (check && Tk_GetNumMainWindows() == 0) { return Qnil; @@ -619,15 +628,18 @@ lib_do_one_event_core(argc, argv, self, is_ip) { VALUE vflags; int flags; - int ret; if (rb_scan_args(argc, argv, "01", &vflags) == 0) { - flags = TCL_ALL_EVENTS; + flags = TCL_ALL_EVENTS | TCL_DONT_WAIT; } else { Check_Type(vflags, T_FIXNUM); flags = FIX2INT(vflags); } - + + if (rb_safe_level() >= 4 || (rb_safe_level() >=1 && OBJ_TAINTED(vflags))) { + flags |= TCL_DONT_WAIT; + } + if (is_ip) { /* check IP */ struct tcltkip *ptr = get_ip(self); @@ -637,8 +649,7 @@ lib_do_one_event_core(argc, argv, self, is_ip) } } - ret = Tcl_DoOneEvent(flags); - if (ret) { + if (Tcl_DoOneEvent(flags)) { return Qtrue; } else { return Qfalse; @@ -681,6 +692,8 @@ lib_restart(self) { struct tcltkip *ptr = get_ip(self); + rb_secure(4); + /* destroy the root wdiget */ ptr->return_value = Tcl_Eval(ptr->ip, "destroy ."); /* ignore ERROR */ @@ -715,6 +728,7 @@ ip_restart(self) { struct tcltkip *ptr = get_ip(self); + rb_secure(4); if (Tcl_GetMaster(ptr->ip) != (Tcl_Interp*)NULL) { /* slave IP */ return Qnil; @@ -912,6 +926,7 @@ ip_create_slave(argc, argv, self) safe = 1; } else if (safemode == Qfalse || safemode == Qnil) { safe = 0; + rb_secure(4); } else { safe = 1; } @@ -961,7 +976,7 @@ ip_delete(self) VALUE self; { struct tcltkip *ptr = get_ip(self); - + Tcl_DeleteInterp(ptr->ip); return Qnil; @@ -1131,7 +1146,6 @@ ip_invoke_real(argc, argv, obj) /* ip is deleted? */ if (Tcl_InterpDeleted(ptr->ip)) { - Tcl_ResetResult(ptr->ip); return rb_tainted_str_new2(""); } @@ -1139,7 +1153,7 @@ ip_invoke_real(argc, argv, obj) if (!Tcl_GetCommandInfo(ptr->ip, cmd, &info)) { /* if (event_loop_abort_on_exc || cmd[0] != '.') { */ if (event_loop_abort_on_exc > 0) { - /*rb_ip_raise(obj, rb_eNameError, "invalid command name `%s'", cmd);*/ + /*rb_ip_raise(obj,rb_eNameError,"invalid command name `%s'",cmd);*/ return create_ip_exc(obj, rb_eNameError, "invalid command name `%s'", cmd); } else { @@ -1349,11 +1363,11 @@ ip_invoke(argc, argv, obj) /* get result & free allocated memory */ result = *alloc_result; - if (rb_obj_is_kind_of(result, rb_eException)) { - rb_exc_raise(result); - } free(alloc_argv); free(alloc_result); + if (rb_obj_is_kind_of(result, rb_eException)) { + rb_exc_raise(result); + } return result; } -- cgit v1.2.3