@@ -45,25 +45,32 @@ utf_e2u(const char *str)
4545static inline char *
4646sv2cstr (SV * sv )
4747{
48- char * val ;
48+ char * val , * res ;
4949STRLEN 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- * readonlyobject such as $^V. That's a perl bug - it's not supposed to
56- * happen. To avoid crashing the backend, we make amortal copy of the
57- * sv before passing it to SvPVutf8(). The copywill be garbage collected
58- *very soon (see perldoc perlguts) .
56+ * readonlyobjects 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 copyis 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 useperls length in the event we had an embedded null byte to ensure
65+ * we useperl'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/*