[Petal] Repeat object and Safe compartment

Fergal Daly fergal at esatclear.ie
Tue Aug 12 16:25:55 BST 2003


I think to use them all you need to do this somewhere before entering safe 
mode

*Petal::CPT::Petal::Hash_Repeat::CUR = \$Petal::Hash_Repeat::CUR;

because inside the safe mode everything gets prefixed with Petal::CPT so when 
you try to access

$Petal::Hash_Repeat::CUR

you're actually accessing

$Petal::CPT::Petal::Hash_Repeat::CUR

That's what I had to do when Petal::CodePerl wanted to call some Petal 
subroutines.

You have explicitly alias variables into that namespace. If you could just 
access the variables without doing anything special then it wouldn't be safe, 
would it?

Now that you know how to solve it, please don't! I was reluctant to give this 
answer because I still think that using global variables for the repeat 
object is very wrong. It means that there is only 1 repeat object, even 
though you can have many nested repeats, so when you do

<outer repeat="items list1">
	<def define="rep1 repeat">
		<inner repeat="thing items/things">
			outer = <data replace="rep1/index"/>
			inner = <data replace="repeat/index"/>
		</inner>	
	</def>
</outer>

you will see 

outer = 0 inner =0
outer = 1 inner =1
outer = 2 inner =2
outer = 3 inner =3
outer = 0 inner =0
outer = 1 inner =1
outer = 0 inner =0
outer = 1 inner =1

when you should see

outer = 0 inner =0
outer = 0 inner =1
outer = 0 inner =2
outer = 0 inner =3
outer = 1 inner =0
outer = 1 inner =1
outer = 2 inner =0
outer = 2 inner =1

this is because there is only ever 1 repeat counter and always refers to the 
innermost loop. Even if you think you're accessing a different one, you're 
not.

I think I know why Jean-Michel did it. In order to do it with proper objects, 
you need to add some code _after_ the loop, this is not so easy as things 
stand because PIS doesn't have an endfor tag, it just has an end tag. My 
solution was to add an endfor tag but that breaks compatibility with older 
PIS.

Another solution would be to make the code generator smarter so that when it 
sees an end tag it knows what is ending which is also a pain.

Maybe the easiest thing to do is to introduce a new for tag, called "repeat" 
say and a corresponding end tag "endrepeat". It should be possible to do this 
without having to duplicate all the "for" code.

I think I'd favour the last solution and I think we should also add a "def" 
tag that has an "enddef" so that we can have scoped variables too.

F

On Tuesday 12 August 2003 14:52, William McKee wrote:
> A bit more on the Taintmode stuff now that I've had a bit of sleep <g>.
>
> As I said in my original message, I spent quite a bit of time trying to
> get the existing code to work inside the Safe compartment. I tried many
> variations on the share_from format that Jean-Michael had tried but to
> no avail--the $CUR/$MAX variables in Petal::Hash_Repeat were not being
> seen when the code was evaluated.
>
> I then went to messing with how CodeGenerator.pm built the code that was
> being put into the Safe compartment. It appears that there are some
> definite issues with using local inside of a Safe compartment. The only
> way I could get the code to run w/o errs was to change the global
> scalars from $Petal::Hash_Repeat::CUR to $CUR. Of course, this makes
> them no longer global and breaks the ability to set that value from
> other packages.
>
> I did come across an interesting thread about Safe in perl5-porters
> between Tom C., Sarathy and Matt S. dated 8-Mar-2000 and titled "Re: [ID
> 20000308.006] use in Safe compartments" [1]. Tom brings up several
> issues which discuss the brokenness of Safe. Of course this was a couple
> years before the current 2.09 release, but I think some of these issues
> are still hanging around.
>
>
> William
>
> [1] http://groups.yahoo.com/group/perl5-porters/message/64279?source=1



More information about the Petal mailing list