Bill Kelly
2/23/2007 8:33:00 PM
Hi,
I'm dynamically compiling ruby code (in a $SAFE=4 environment),
and because I'm not allowed to re-open classes (even tainted ones),
I'm having trouble reloading previously-compiled script code.
As a temporary workaround, each time I compile, I dynamically
create a new module namespace to compile into.
VER1::DynamicStuff
VER2::DynamicStuff
VER3::DynamicStuff
. . .
Which means all the old versions of the classes created by
previous compiles are hanging around in the system.
What I would like to be able to do (from my $SAFE=0 environment)
is delete (undef) the modules and classes created by the
previous compile.
I can think of a way to sort of accomplish that, by using
reflection, and recursively traversing from the root module,
and telling all contained modules and classes to undef all
their methods, and set all their constants to nil. However,
I am worried about this solution, because I don't know how
to tell whether the value held by a constant refers to a
dynamically compiled class or not. (I guess I could just
delete all the 'tainted' stuff.) ((But even this isn't really
good enough, see below re: SecurityError and re-opening
modules.))
Anyway - am I missing any easy solutions here? Anyone have
any thoughts as to better approaches?
(What I'd *like* to be able to do, is just say,
"undef MyProg::DynamicStuff", which would undef the
DynamicStuff constant and--presumably--leave the
Module referenced by that constant (and all of its
contents) open for garbage collection. Note that
just setting the constant to nil isn't good enough,
because I can't later assign a new module to that
constant--because I'll get a SecurityError eventually
when I try to "reopen" that module the next time I
compile in $SAFE=4 .....)
Thanks,
Bill