$SAFE reset when proc called (1.8.4)


#1

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


#2

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.


#3

From: “Daniel S.” removed_email_address@domain.invalid

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. :slight_smile:

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

Thanks,

Bill