ext/tk: remove $SAFE 2..4 code

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-09-24 01:37:14 +00:00
Родитель 61847a8279
Коммит c97a6987b6
11 изменённых файлов: 18 добавлений и 83 удалений

Просмотреть файл

@ -171,7 +171,7 @@ module TclTklib
: a target event.
: If set DONT_WAIT flag and no event for processing, returns
: false immediately.
: If $SAFE >= 4, or $SAFE >= 1 and the flag is tainted,
: If $SAFE >= 1 and the flag is tainted,
: force to set DONT_WAIT flag.
set_eventloop_tick(timer_tick)
@ -183,7 +183,6 @@ module TclTklib
: However, if the eventloop thread is the only thread,
: timer_tick cannot be set to 0. If 0, then is set to 100 ms
: automatically (see NO_THREAD_INTERRUPT_TIME on tcltklib.c).
: On $SAFE >= 4, cannot call this method.
get_eventloop_tick
: Get current value of 'timer_tick'
@ -194,7 +193,6 @@ module TclTklib
: Default value is 20 (ms).
: If the eventloop thread is the only thread, this value is
: invalid.
: On $SAFE >= 4, cannot call this method.
get_no_event_wait
: Get current value of 'no_event_wait'.
@ -207,7 +205,6 @@ module TclTklib
: when no event for processing (And then, the eventloop thread
: sleeps 'no_event_wait' mili-seconds).
: 'loop_max == 800' and 'no_event_tick == 10' are default.
: On $SAFE >= 4, cannot call this method.
get_eventloop_weight
: Get current values of 'loop_max' and 'no_event_tick'.
@ -223,7 +220,6 @@ module TclTklib
: interpreter kills the eventloop thread. Even if such
: situation, when abort_on_exception == false or nil,
: the eventloop ignores the exception and continue to working.
: On $SAFE >= 4, cannot call this method.
mainloop_abort_on_exception
: Get current status of that.
@ -294,7 +290,6 @@ class TclTkIp
: interpreter. Default is false. However, if the parent
: interpreter is a safe interpreter, the created interpreter is
: a safe interpreter (ignore 'safe' argument value).
: If $SAFE >= 4, can create a safe interpreter only.
make_safe
: Make the interpreter to the safe interpreter, and returns
@ -314,7 +309,7 @@ class TclTkIp
allow_ruby_exit=(mode)
: Change the mode of 'allow_ruby_exit?'.
: If $SAFE >= 4 or the interpreter is a "safe" interpreter,
: If the interpreter is a "safe" interpreter,
: this is not permitted (raise an exception).
delete
@ -335,7 +330,6 @@ class TclTkIp
: Restart Tk part of the interpreter.
: Use this when you need Tk functions after destroying the
: root widget.
: On $SAFE >= 4, cannot call this method.
_eval(str)
_invoke(*args)

Просмотреть файл

@ -272,7 +272,7 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 象となっている種類のイベントが発生するまで待ち続ける.
: DONT_WAIT を指定していた場合,処理対象イベントがなくても
: すぐに終了し false を返す.
: $SAFE >= 4 か,$SAFE >= 1 かつ flag が汚染されているならば
: $SAFE >= 1 かつ flag が汚染されているならば
: flag には DONT_WAIT が強制的に付けられる.
set_eventloop_tick(timer_tick)
@ -288,7 +288,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 定される.
: 詳細な説明は略すが,これは CPU パワーを節約しつつ安全で
: 安定した動作を実現するために実装した仕様である.
: $SAFE >= 4 では実行が禁止される.
get_eventloop_tick
: timer_tick の現在値を返す.
@ -298,7 +297,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: く存在しなかった際に sleep 状態に入る時間長を指定する.
: 稼働スレッドがイベントループだけの場合には意味をなさない.
: デフォルトの値は 20 (ms)
: $SAFE >= 4 では実行が禁止される.
get_no_event_wait
: no_event_wait の現在値を返す.
@ -316,7 +314,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: が全く発生しないままに 80 回の処理待ちイベント検査が完了
: するとかでカウントが 800 以上になるとスレッドスイッチング
: が発生することになる.
: $SAFE >= 4 では実行が禁止される.
get_eventloop_weight
: 現在の loop_max と no_event_tick との値を返す.
@ -336,7 +333,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 他のインタープリタの処理継続が不可能になることがある.その
: ような場合でもエラーを無視してイベントループが稼働を続ける
: ことで,他のインタープリタが正常に動作し続けることができる.
: $SAFE >= 4 では実行が禁止される.
mainloop_abort_on_exception
: Tk インタープリタ上で例外を発生した際に,イベントループをエ
@ -404,7 +400,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: たとえ明確に false を指定していたとしても,親となるインター
: プリタが safe インタープリタであれば,その設定を引き継いで
: safe インタープリタとして生成される.
: $SAFE >= 4 ではsafe インタープリタ以外の生成が禁止される.
make_safe
: Tcl/Tk インタープリタを safe インタープリタに変更する.
@ -425,8 +420,8 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
allow_ruby_exit=(mode)
: 対象となるインタープリタの allow_ruby_exit? の状態を変更する.
: $SAFE >= 4 またはインタープリタが safe インタープリタの場合は
: 変更が許されない (例外を発生)
: インタープリタが safe インタープリタの場合は変更が許されない
: (例外を発生)
delete
: Tcl/Tk インタープリタを delete する.
@ -447,7 +442,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: Tcl/Tk インタープリタの Tk 部分の初期化,再起動を行う.
: 一旦 root widget を破壊した後に再度 Tk の機能が必要と
: なった場合に用いる.
: $SAFE >= 4 では実行が禁止される.
_eval(str)
_invoke(*args)

Просмотреть файл

@ -1265,14 +1265,6 @@ class MultiTkIp
######################################
def initialize(master, safeip=true, keys={})
if $SAFE >= 4
fail SecurityError, "cannot create a new interpreter at level #{$SAFE}"
end
if safeip == nil && $SAFE >= 2
fail SecurityError, "cannot create a master-ip at level #{$SAFE}"
end
if master.deleted? && safeip == nil
fail RuntimeError, "cannot create a slave of a deleted interpreter"
end
@ -1307,7 +1299,7 @@ class MultiTkIp
name, safe, safe_opts, tk_opts = _parse_slaveopts(keys)
safe = 4 if safe && !safe.kind_of?(Fixnum)
safe = 1 if safe && !safe.kind_of?(Fixnum)
@safe_base = false
@ -1423,7 +1415,7 @@ class MultiTkIp
safe = master.safe_level if safe < master.safe_level
@safe_level = [safe]
else
@safe_level = [4]
@safe_level = [1]
end
else
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
@ -1615,7 +1607,7 @@ class << MultiTkIp
end
alias new_trusted_slave new_slave
def new_safe_slave(safe=4, keys={}, &blk)
def new_safe_slave(safe=1, keys={}, &blk)
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
@ -2754,13 +2746,9 @@ class MultiTkIp
if @wait_on_mainloop[0]
begin
@wait_on_mainloop[1] += 1
if $SAFE >= 4
_receiver_mainloop(check_root).join
else
@cmd_queue.enq([@system, 'call_mainloop',
Thread.current, check_root])
Thread.stop
end
@cmd_queue.enq([@system, 'call_mainloop',
Thread.current, check_root])
Thread.stop
rescue MultiTkIp_OK => ret
# return value
if ret.value.kind_of?(Thread)

Просмотреть файл

@ -61,10 +61,6 @@ end
class RemoteTkIp
def initialize(remote_ip, displayof=nil, timeout=5)
if $SAFE >= 4
fail SecurityError, "cannot access another interpreter at level #{$SAFE}"
end
@interp = MultiTkIp.__getip
if @interp.safe?
fail SecurityError, "safe-IP cannot create RemoteTkIp"
@ -199,9 +195,7 @@ class RemoteTkIp
raise SecurityError, "no permission to manipulate" unless self.manipulable?
p ['_appsend', [@remote, @displayof], enc_mode, async, cmds] if $DEBUG
if $SAFE >= 4
fail SecurityError, "cannot send commands at level 4"
elsif $SAFE >= 1 && cmds.find{|obj| obj.tainted?}
if $SAFE >= 1 && cmds.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted commands at level #{$SAFE}"
end

Просмотреть файл

@ -1785,9 +1785,7 @@ EOS
end
def appsend(interp, async, *args)
if $SAFE >= 4
fail SecurityError, "cannot send Tk commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
end
if async != true && async != false && async != nil
@ -1802,9 +1800,7 @@ EOS
end
def rb_appsend(interp, async, *args)
if $SAFE >= 4
fail SecurityError, "cannot send Ruby commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
end
if async != true && async != false && async != nil
@ -1820,9 +1816,7 @@ EOS
end
def appsend_displayof(interp, win, async, *args)
if $SAFE >= 4
fail SecurityError, "cannot send Tk commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
end
win = '.' if win == nil
@ -1838,9 +1832,7 @@ EOS
end
def rb_appsend_displayof(interp, win, async, *args)
if $SAFE >= 4
fail SecurityError, "cannot send Ruby commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
end
win = '.' if win == nil
@ -1899,7 +1891,7 @@ EOS
INTERP_ROOT_CHECK.wait(INTERP_MUTEX)
status = INTERP_THREAD_STATUS.value
if status && TkCore::INTERP.default_master?
INTERP_THREAD_STATUS.value = nil if $SAFE < 4
INTERP_THREAD_STATUS.value = nil
raise status if status.kind_of?(Exception)
end
}
@ -2209,9 +2201,6 @@ module Tk
# tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath'))
when :PLATFORM, :TCL_PLATFORM
if $SAFE >= 4
fail SecurityError, "can't get #{sym} when $SAFE >= 4"
end
INTERP._invoke_without_enc('global', 'tcl_platform')
Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get',
'tcl_platform'))]
@ -3746,7 +3735,6 @@ module TkConfigMethod
@mode || false
end
def TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
fail SecurityError, "can't change the mode" if $SAFE>=4
@mode = (mode)? true: false
end
@ -5650,9 +5638,6 @@ class TkWindow<TkObject
end
def wait_visibility(on_thread = true)
if $SAFE >= 4
fail SecurityError, "can't wait visibility at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1)
if on_thread
INTERP._thread_tkwait('visibility', path)
@ -5676,9 +5661,6 @@ class TkWindow<TkObject
alias thread_tkwait_visibility thread_wait_visibility
def wait_destroy(on_thread = true)
if $SAFE >= 4
fail SecurityError, "can't wait destroy at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1)
if on_thread
INTERP._thread_tkwait('window', epath)

Просмотреть файл

@ -124,7 +124,6 @@ module TkItemConfigMethod
@mode || false
end
def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
fail SecurityError, "can't change the mode" if $SAFE>=4
@mode = (mode)? true: false
end

Просмотреть файл

@ -22,15 +22,9 @@ module TkOptionDB
end
def add(pat, value, pri=None)
# if $SAFE >= 4
# fail SecurityError, "can't call 'TkOptionDB.add' at $SAFE >= 4"
# end
tk_call('option', 'add', pat, value, pri)
end
def clear
# if $SAFE >= 4
# fail SecurityError, "can't call 'TkOptionDB.crear' at $SAFE >= 4"
# end
tk_call_without_enc('option', 'clear')
end
def get(win, name, klass)

Просмотреть файл

@ -498,10 +498,6 @@ class TkTimer
end
def wait(on_thread = true, check_root = false)
if $SAFE >= 4
fail SecurityError, "can't wait timer at $SAFE >= 4"
end
unless @running
if @return_value.kind_of?(Exception)
fail @return_value

Просмотреть файл

@ -360,9 +360,6 @@ class TkVariable
end
def wait(on_thread = false, check_root = false)
if $SAFE >= 4
fail SecurityError, "can't wait variable at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1)
if on_thread
if check_root

3
ext/tk/sample/safe-tk.rb Normal file → Executable file
Просмотреть файл

@ -117,9 +117,6 @@ p ip.eval_str("
:padx=>10, :pady=>7)
", bind)
puts "\n---- change the safe slave IP's safe-level ==> 4 ----------"
ip.safe_level = 4
puts "\n---- call 3rd and 4th eval_proc ----------"
p ip.eval_proc{
TkLabel.new(:text=>"3rd and 4th eval_proc : $SAFE == #{$SAFE}").pack

2
ext/tk/sample/tkoptdb-safeTk.rb Normal file → Executable file
Просмотреть файл

@ -31,7 +31,7 @@ file = File.expand_path('tkoptdb.rb', File.dirname(__FILE__))
ip = MultiTkIp.new_safeTk{
# When a block is given to 'new_safeTk' method,
# the block is evaluated on $SAFE==4.
# the block is evaluated on $SAFE==1.
ent.each{|pat, val| Tk.tk_call('option', 'add', pat, val)}
}