File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -45,25 +45,32 @@ utf_e2u(const char *str)
4545static inline char *
4646sv2cstr (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/*
You can’t perform that action at this time.
0 commit comments