Forum: Ruby $SAFE reset when proc called (1.8.4)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2007-03-06 00:38
(Received via mailing list)
Hi,

I'm wondering if this is a bug?  When the proc is called, the
safe_level is reverting to zero:


$ cat safe-test4.rb

pr = lambda{ puts "my_safe_level=#{Thread.current.safe_level}" }

th = Thread.new(pr) do |pr_|
  $SAFE = 4
  pr_.call
end
th.join



$ ruby -v safe-test.rb
ruby 1.8.4 (2005-12-24) [i386-mswin32]
my_safe_level=0



If this isn't a bug, does anyone know why this behavior would
be desirable?


Thanks,

Regards,

Bill
1c1e3bdfe006a22214102fcd6434a012?d=identicon&s=25 Daniel Sheppard (Guest)
on 2007-03-06 00:42
(Received via mailing list)
> my_safe_level=0
>
> If this isn't a bug, does anyone know why this behavior would
> be desirable?

AFAIK, that's the desired behavior - the pr proc was created while
$SAFE=0 and will be executed in that $SAFE=0 context. That allows you to
give a Safe environment access to unsafe things.

Dan.
4feed660d3728526797edeb4f0467384?d=identicon&s=25 Bill Kelly (Guest)
on 2007-03-06 01:10
(Received via mailing list)
From: "Daniel Sheppard" <daniels@pronto.com.au>
>
> AFAIK, that's the desired behavior - the pr proc was created while
> $SAFE=0 and will be executed in that $SAFE=0 context. That allows you to
> give a Safe environment access to unsafe things.

Oh.  I guess that is pretty cool.  :-)

Just inconvenient in my particular situation, but I can work
around it.


Thanks,

Bill
This topic is locked and can not be replied to.