1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

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.
This commit is contained in:
Andrew Dunstan
2012-01-05 17:59:19 -05:00
parent 7e53515480
commit bd0e74a9ce

View File

@ -45,25 +45,32 @@ utf_e2u(const char *str)
static inline char * static inline char *
sv2cstr(SV *sv) sv2cstr(SV *sv)
{ {
char *val; char *val, *res;
STRLEN len; STRLEN len;
SV *nsv;
/* /*
* get a utf8 encoded char * out of perl. *note* it may not be valid utf8! * get a utf8 encoded char * out of perl. *note* it may not be valid utf8!
* *
* SvPVutf8() croaks nastily on certain things, like typeglobs and * SvPVutf8() croaks nastily on certain things, like typeglobs and
* readonly object such as $^V. That's a perl bug - it's not supposed to * readonly objects 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 * happen. To avoid crashing the backend, we make a copy of the
* sv before passing it to SvPVutf8(). The copy will be garbage collected * sv before passing it to SvPVutf8(). The copy is garbage collected
* very soon (see perldoc perlguts). * 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 * 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;
} }
/* /*