File tree 1 file changed +15
-8
lines changed
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)
45
45
static inline char *
46
46
sv2cstr (SV * sv )
47
47
{
48
- char * val ;
48
+ char * val , * res ;
49
49
STRLEN len ;
50
+ SV * nsv ;
50
51
51
52
/*
52
53
* get a utf8 encoded char * out of perl. *note* it may not be valid utf8!
53
54
*
54
55
* 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 .
59
60
*/
60
- val = SvPVutf8 (sv_mortalcopy (sv ), len );
61
+ nsv = newSVsv (sv );
62
+ val = SvPVutf8 (nsv , len );
61
63
62
64
/*
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
64
66
* we error out properly
65
67
*/
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 ;
67
74
}
68
75
69
76
/*
You can’t perform that action at this time.
0 commit comments