1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/lib/multi-tk.rb: MultiTkIp.new_master and new_slave accept

safe-level value argument


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2004-09-13 07:25:02 +00:00
parent 977eb1bae7
commit 7945cd5978
3 changed files with 81 additions and 21 deletions

View file

@ -1,3 +1,8 @@
Mon Sep 13 16:23:27 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: MultiTkIp.new_master and new_slave accept
safe-level value argument
Mon Sep 13 10:48:37 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getpid): don't need to use _getpid() on

View file

@ -934,7 +934,20 @@ class << MultiTkIp
private :__new
def new_master(keys={})
def new_master(safe=nil, keys={})
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
if !keys.key?(:safe) && !keys.key?('safe')
keys[:safe] = safe
end
elsif safe == nil
# do nothing
else
raise ArgumentError, "unexpected argument(s)"
end
ip = __new(__getip, nil, keys)
ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call) if block_given?
ip
@ -942,7 +955,20 @@ class << MultiTkIp
alias new new_master
def new_slave(keys={})
def new_slave(safe=nil, keys={})
if safe.kind_of?(Hash)
keys = safe
elsif safe.kind_of?(Integer)
raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
if !keys.key?(:safe) && !keys.key?('safe')
keys[:safe] = safe
end
elsif safe == nil
# do nothing
else
raise ArgumentError, "unexpected argument(s)"
end
ip = __new(__getip, false, keys)
ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call) if block_given?
ip
@ -1242,21 +1268,43 @@ class MultiTkIp
end
private :eval_proc_core
def eval_callback(cmd = proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
eval_proc_core(false, cmd, *args)
#def eval_callback(cmd = proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
# eval_proc_core(false, cmd, *args)
#end
def eval_callback(*args)
if block_given?
eval_proc_core(false, proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
else
eval_proc_core(false, *args)
end
end
def eval_proc(cmd = proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
eval_proc_core(true, cmd, *args)
#def eval_proc(cmd = proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
# eval_proc_core(true, cmd, *args)
#end
def eval_proc(*args)
if block_given?
eval_proc_core(true, proc{$SAFE=@safe_level[0]; Proc.new}.call, *args)
else
eval_proc_core(true, *args)
end
end
alias call eval_proc
alias eval_string eval_proc
end
class << MultiTkIp
# class method
def eval_proc(cmd = proc{$SAFE=__getip.safe_level; Proc.new}.call, *args)
# def eval_proc(cmd = proc{$SAFE=__getip.safe_level; Proc.new}.call, *args)
# # class ==> interp object
# __getip.eval_proc(cmd, *args)
# end
def eval_proc(*args)
# class ==> interp object
__getip.eval_proc(cmd, *args)
if block_given?
__getip.eval_proc(proc{$SAFE=__getip.safe_level; Proc.new}.call, *args)
else
__getip.eval_proc(*args)
end
end
alias call eval_proc
alias eval_string eval_proc

View file

@ -4,15 +4,16 @@ require 'multi-tk'
TkMessage.new(:text => <<EOM).pack
This is a sample of the safe-Tk slave interpreter. \
On the slave interpreter, 'tkoptdb.rb' demo is running.
( Attention:: a safe-Tk interpreter can't read options \
On the slave interpreter, 'tkoptdb.rb' demo is running.
( NOTE:: a safe-Tk interpreter can't read options \
from a file. Options are given by the master interpreter \
in this script. )
The window shown this message is a root widget of \
the default master interpreter. The other window \
is a toplevel widget of the master interpreter, and it \
has a container frame of the safe-Tk slave interpreter. \
You can delete the slave by the button on the toplevel widget.
has a container frame of the safe-Tk slave interpreter.
'exit' on the slave interpreter exits the slave only. \
You can also delete the slave by the button on the toplevel widget.
EOM
if ENV['LANG'] =~ /^ja/
@ -33,21 +34,27 @@ ip = MultiTkIp.new_safeTk{
ent.each{|pat, val| Tk.tk_call('option', 'add', pat, val)}
}
=begin
ip.eval_proc{
print "ip.eval_proc{$SAFE} ==> ", ip.eval_proc{$SAFE}, "\n"
ret = ip.eval_proc{
# When a block is given to 'eval_proc' method,
# the block is evaluated on the IP's current safe level.
# So, the followings raises exceptions.
# So, the followings raises an exception.
# An Exception object of the exception is returned as a
# return value of this method.
load file
}
=end
print "ip.eval_proc{}, which includes insecure operiation in the given block, returns an exception object: ", ret.inspect, "\n"
ip.eval_proc(proc{
# When a Procedure object is given to 'eval_proc' method as an argument,
# the proc is evaluated on the proc's binding.
# So, the followings are evaluated on $SAFE==0
print "If a proc object is given, the proc is evaluated on the safe-level which is kept on the proc :: ip.eval_proc( proc{$SAFE} ) ==> ", ip.eval_proc(proc{$SAFE}), "\n"
safe0_cmd = Proc.new{
# This proc object keeps current safe-level ($SAFE==0).
load file
})
}
ip.eval_proc(safe0_cmd)
# Tk.mainloop is ignored on the slave-IP