Skip to content

Commit bd0e74a

Browse files
committed
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.
1 parent 7e53515 commit bd0e74a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/pl/plperl/plperl_helpers.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,32 @@ utf_e2u(const char *str)
4545
static inline char *
4646
sv2cstr(SV *sv)
4747
{
48-
char *val;
48+
char *val, *res;
4949
STRLEN len;
50+
SV *nsv;
5051

5152
/*
5253
* get a utf8 encoded char * out of perl. *note* it may not be valid utf8!
5354
*
5455
* SvPVutf8() croaks nastily on certain things, like typeglobs and
55-
* readonly object such as $^V. That's a perl bug - it's not supposed to
56-
* happen. To avoid crashing the backend, we make a mortal copy of the
57-
* sv before passing it to SvPVutf8(). The copy will be garbage collected
58-
* very soon (see perldoc perlguts).
56+
* readonly objects such as $^V. That's a perl bug - it's not supposed to
57+
* happen. To avoid crashing the backend, we make a copy of the
58+
* sv before passing it to SvPVutf8(). The copy is garbage collected
59+
* when we're done with it.
5960
*/
60-
val = SvPVutf8(sv_mortalcopy(sv), len);
61+
nsv = newSVsv(sv);
62+
val = SvPVutf8(nsv, len);
6163

6264
/*
63-
* we use perls length in the event we had an embedded null byte to ensure
65+
* we use perl's length in the event we had an embedded null byte to ensure
6466
* we error out properly
6567
*/
66-
return utf_u2e(val, len);
68+
res = utf_u2e(val, len);
69+
70+
/* safe now to garbage collect the new SV */
71+
SvREFCNT_dec(nsv);
72+
73+
return res;
6774
}
6875

6976
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy