diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2012-01-05 18:01:52 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2012-01-05 18:01:52 -0500 |
commit | d1d836f92c0798f4bc4138dc6b87279199c4f49a (patch) | |
tree | a82b62cbf2e8db6fcd3287715d683ea6d346b0be /src | |
parent | d496384d6771c276a0253758418e7933b6f31167 (diff) | |
download | postgresql-d1d836f92c0798f4bc4138dc6b87279199c4f49a.tar.gz postgresql-d1d836f92c0798f4bc4138dc6b87279199c4f49a.zip |
Fix breakage from earlier plperl fix.
Apparently the perl garbage collector was a bit too eager, so here
we control when the new SV is garbage collected.
Diffstat (limited to 'src')
-rw-r--r-- | src/pl/plperl/plperl_helpers.h | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/pl/plperl/plperl_helpers.h b/src/pl/plperl/plperl_helpers.h index c671820468a..800a408ac4c 100644 --- a/src/pl/plperl/plperl_helpers.h +++ b/src/pl/plperl/plperl_helpers.h @@ -45,25 +45,32 @@ utf_e2u(const char *str) static inline char * sv2cstr(SV *sv) { - char *val; + char *val, *res; STRLEN len; + SV *nsv; /* * get a utf8 encoded char * out of perl. *note* it may not be valid utf8! * * SvPVutf8() croaks nastily on certain things, like typeglobs and - * readonly object such as $^V. That's a perl bug - it's not supposed to - * happen. To avoid crashing the backend, we make a mortal copy of the - * sv before passing it to SvPVutf8(). The copy will be garbage collected - * very soon (see perldoc perlguts). + * readonly objects such as $^V. That's a perl bug - it's not supposed to + * happen. To avoid crashing the backend, we make a copy of the + * sv before passing it to SvPVutf8(). The copy is garbage collected + * when we're done with it. */ - val = SvPVutf8(sv_mortalcopy(sv), len); + nsv = newSVsv(sv); + val = SvPVutf8(nsv, len); /* - * we use perls length in the event we had an embedded null byte to ensure + * we use perl's length in the event we had an embedded null byte to ensure * we error out properly */ - return utf_u2e(val, len); + res = utf_u2e(val, len); + + /* safe now to garbage collect the new SV */ + SvREFCNT_dec(nsv); + + return res; } /* |