Re: plperl & sort

From: "Alex Hunsaker" <badalex(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff <threshar(at)threshar(dot)is-a-geek(dot)com>, pgsql-bugs(at)postgresql(dot)org, "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Subject: Re: plperl & sort
Date: 2008-11-04 20:49:24
Message-ID: 34d269d40811041249r46b45702j22ee4fab28716286@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Nov 4, 2008 at 12:43, Alex Hunsaker <badalex(at)gmail(dot)com> wrote:
> It has something to do with anon subs not sure what...

It has to do with us returning the anonymous sub inside of the safe
and then calling the function outside of the safe (or at least in a
different namespace)

we do something eqvilient to this:
my $func_ptr = $safe->reval('sub { ... }');
$func_ptr->();

because safe makes its own namespace from perldoc Safe
The "root" of the namespace (i.e. "main::") is changed to a
different package and code evaluated in the compartment cannot
refer to variables outside this namespace, even with run-time
glob lookups and other tricks.

I only see one way to "fix" this which is to do something groddy like
share a global variable between the safe and the real interpreter.
Something like:

my $_pl_sub;
sub call_pl_sub
{
retrun $_pl_sub;
}

$safe->share(qw(call_pl_sub);

my $sub = $safe->reval('sub { ...}');

$_pl_sub = $sub;
$safe->reval('call_pl_sub();');

Note I tried just sharing $_pl_sub and doing
$safe->reval('$_pl_sub->()'); but I just get 'Undefined subroutine
&main::'

Should I work up a patch? Assuming someone confirm this?

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeff 2008-11-04 20:51:27 Re: plperl & sort
Previous Message Alex Hunsaker 2008-11-04 19:43:52 Re: plperl & sort