On Fri, Aug 5, 2011 at 08:53, Andrew Dunstan <[email protected]> wrote:
>
>
> On 08/04/2011 11:23 PM, Alex Hunsaker wrote:
>>
>> [ ... don't let people set signal handlers postgres sets ]
>
> This whole thing is a massive over-reaction to a problem we almost certainly
> know how to fix fairly simply and relatively painlessly, and attempts
> (unsuccessfully, at least insofar as comprehensiveness is concerned) to fix
> a problem nobody's actually reported having AFAIK.
*shrug* OK.
Find attached a version that does the equivalent of local %SIG for
each pl/perl(u) call. I was only able to test on 5.14.1, but I looked
at 5.8.9 to make sure it looks like it works.
Its a tad slower (something like 0.00037ms per call), but uhh thats
quite acceptable IMHO (best of 5 runs):
=> create or replace function simple() returns void as $$ $$ language plperl;
CREATE FUNCTION
-- pre patch
=> select count(simple()) from generate_series(1, 10000000);
Time: 10219.149 ms
-- patched
=> select count(simple()) from generate_series(1, 10000000);
Time: 13924.025 ms
Thoughts?
*** a/src/pl/plperl/expected/plperl.out
--- b/src/pl/plperl/expected/plperl.out
***************
*** 639,641 **** CONTEXT: PL/Perl anonymous code block
--- 639,643 ----
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
ERROR: Useless use of sort in scalar context at line 1.
CONTEXT: PL/Perl anonymous code block
+ DO $do$ die "$SIG{'ALARM'} set!" if($SIG{'ALARM'}); $SIG{'ALARM'} = sub { print "alarm!\n"}; $do$ LANGUAGE plperl;
+ DO $do$ die "$SIG{'ALARM'} set!" if($SIG{'ALARM'}); $do$ LANGUAGE plperl;
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 1895,1906 **** plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
--- 1895,1912 ----
{
dSP;
SV *retval;
+ GV *gv;
int i;
int count;
ENTER;
SAVETMPS;
+ gv = gv_fetchpv("SIG", 0, SVt_PVHV);
+ if (!gv)
+ elog(ERROR, "couldn't fetch %%SIG");
+ save_hash(gv); /* local %SIG */
+
PUSHMARK(SP);
EXTEND(sp, desc->nargs);
***************
*** 1976,1981 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
--- 1982,1988 ----
dSP;
SV *retval,
*TDsv;
+ GV *gv;
int i,
count;
Trigger *tg_trigger = ((TriggerData *) fcinfo->context)->tg_trigger;
***************
*** 1986,1995 **** plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
TDsv = get_sv("_TD", 0);
if (!TDsv)
elog(ERROR, "couldn't fetch $_TD");
-
save_item(TDsv); /* local $_TD */
sv_setsv(TDsv, td);
PUSHMARK(sp);
EXTEND(sp, tg_trigger->tgnargs);
--- 1993,2006 ----
TDsv = get_sv("_TD", 0);
if (!TDsv)
elog(ERROR, "couldn't fetch $_TD");
save_item(TDsv); /* local $_TD */
sv_setsv(TDsv, td);
+ gv = gv_fetchpv("SIG", 0, SVt_PVHV);
+ if (!gv)
+ elog(ERROR, "couldn't fetch %%SIG");
+ save_hash(gv); /* local %SIG */
+
PUSHMARK(sp);
EXTEND(sp, tg_trigger->tgnargs);
*** a/src/pl/plperl/sql/plperl.sql
--- b/src/pl/plperl/sql/plperl.sql
***************
*** 415,417 **** DO $do$ use strict; my $name = "foo"; my $ref = $$name; $do$ LANGUAGE plperl;
--- 415,420 ----
-- check that we can "use warnings" (in this case to turn a warn into an error)
-- yields "ERROR: Useless use of sort in scalar context."
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
+
+ DO $do$ die "$SIG{'ALARM'} set!" if($SIG{'ALARM'}); $SIG{'ALARM'} = sub { print "alarm!\n"}; $do$ LANGUAGE plperl;
+ DO $do$ die "$SIG{'ALARM'} set!" if($SIG{'ALARM'}); $do$ LANGUAGE plperl;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers