This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use PerlMemShared for CopSTASHPV and CopFILE. MUCH harder than it sounds!
[perl5.git] / util.c
diff --git a/util.c b/util.c
index 6a0ff44..83b9026 100644 (file)
--- a/util.c
+++ b/util.c
@@ -891,10 +891,11 @@ Copy a string to a safe spot.  This does not use an SV.
 char *
 Perl_savepv(pTHX_ const char *sv)
 {
-    register char *newaddr;
-
-    New(902,newaddr,strlen(sv)+1,char);
-    (void)strcpy(newaddr,sv);
+    register char *newaddr = sv;
+    if (sv) {
+       New(902,newaddr,strlen(sv)+1,char);
+       (void)strcpy(newaddr,sv);
+    } 
     return newaddr;
 }
 
@@ -920,6 +921,27 @@ Perl_savepvn(pTHX_ const char *sv, register I32 len)
     return newaddr;
 }
 
+/*
+=for apidoc savesharedpv
+
+Copy a string to a safe spot in memory shared between threads.
+This does not use an SV.
+
+=cut
+*/
+char *
+Perl_savesharedpv(pTHX_ const char *sv)
+{
+    register char *newaddr = sv;
+    if (sv) {
+       newaddr = PerlMemShared_malloc(strlen(sv)+1);
+       (void)strcpy(newaddr,sv);
+    }
+    return newaddr;
+}
+
+
+
 /* the SV for Perl_form() and mess() is not kept in an arena */
 
 STATIC SV *