Re: PL/Perl Does not Like vstrings

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David E(dot) Wheeler" <david(at)justatheory(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/Perl Does not Like vstrings
Date: 2012-01-05 14:42:58
Message-ID: 4F05B6F2.1000000@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 01/04/2012 08:32 PM, Tom Lane wrote:
> Andrew Dunstan<andrew(at)dunslane(dot)net> writes:
>> Tom said:
>>> 2. A slightly cleaner fix for this should be to duplicate the SV and
>>> then release the copy around the SvPVutf8 call, only if it's readonly.
>>> "Fixing" it in do_util_elog is entirely the wrong thing.
>> How do we tell if it's readonly?
> SvREADONLY(sv) macro.
>
>

OK, so this seems to fix The issue David found:

diff --git a/src/pl/plperl/plperl_helpers.h b/src/pl/plperl/plperl_helpers.h
index ac0a97d..f0e1afa 100644
--- a/src/pl/plperl/plperl_helpers.h
+++ b/src/pl/plperl/plperl_helpers.h
@@ -51,7 +51,10 @@ sv2cstr(SV *sv)
/*
* get a utf8 encoded char * out of perl. *note* it may not be
valid utf8!
*/
- val = SvPVutf8(sv, len);
+ if (SvREADONLY(sv))
+ val = SvPVutf8(sv_mortalcopy(sv), len);
+ else
+ val = SvPVutf8(sv, len);

/*
* we use perls length in the event we had an embedded null byte to
ensure

but it doesn't fix the one I found which passes a typeglob to elog():

do '$foo=1; elog(NOTICE,*foo);' language plperl;

That still crashes, but doesn't if we use sv_mortalcopy unconditionally.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2012-01-05 14:51:07 Re: pg_restore direct to database is broken for --insert dumps
Previous Message Robert Haas 2012-01-05 14:35:45 Re: optimizing repeated MVCC snapshots