Handle NUL characters in Perl strings properly.
[perl4caml.git] / perl_c.c
index 06b69b6..11d1cc6 100644 (file)
--- a/perl_c.c
+++ b/perl_c.c
@@ -1,6 +1,6 @@
 /* Interface to Perl from OCaml.
  * Copyright (C) 2003 Merjis Ltd.
- * $Id: perl_c.c,v 1.21 2005-01-29 12:22:49 rich Exp $
+ * $Id: perl_c.c,v 1.22 2005-02-13 16:33:27 rich Exp $
  */
 
 #include <stdio.h>
@@ -129,8 +129,8 @@ perl4caml_string_of_sv (value svv)
   STRLEN len;
   CAMLlocal1 (strv);
   str = SvPV (sv, len);
-  /* XXX This won't work if the string contains NUL. */
-  strv = caml_copy_string (str);
+  strv = caml_alloc_string (len);
+  memcpy (String_val (strv), str, len);
   CAMLreturn (strv);
 }