Re: [PATCH lib/Cwd.pm] fixing proto mismatch warning
[p5sagit/p5-mst-13.2.git] / scope.c
diff --git a/scope.c b/scope.c
index da5fa6b..d0646bc 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1,6 +1,6 @@
 /*    scope.c
  *
- *    Copyright (c) 1991-2001, Larry Wall
+ *    Copyright (c) 1991-2002, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -254,6 +254,18 @@ Perl_save_generic_pvref(pTHX_ char **str)
     SSPUSHINT(SAVEt_GENERIC_PVREF);
 }
 
+/* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree().
+ * Can be used to restore a shared global char* to its prior
+ * contents, freeing new value. */
+void
+Perl_save_shared_pvref(pTHX_ char **str)
+{
+    SSCHECK(3);
+    SSPUSHPTR(str);
+    SSPUSHPTR(*str);
+    SSPUSHINT(SAVEt_SHARED_PVREF);
+}
+
 void
 Perl_save_gp(pTHX_ GV *gv, I32 empty)
 {
@@ -657,6 +669,14 @@ Perl_leave_scope(pTHX_ I32 base)
                *(char**)ptr = str;
            }
            break;
+       case SAVEt_SHARED_PVREF:                /* shared pv */
+           str = (char*)SSPOPPTR;
+           ptr = SSPOPPTR;
+           if (*(char**)ptr != str) {
+               PerlMemShared_free(*(char**)ptr);
+               *(char**)ptr = str;
+           }
+           break;
        case SAVEt_GENERIC_SVREF:               /* generic sv */
            value = (SV*)SSPOPPTR;
            ptr = SSPOPPTR;
@@ -827,9 +847,8 @@ Perl_leave_scope(pTHX_ I32 base)
                 * if a my variable that was made readonly is going out of
                 * scope, we want to remove the readonlyness so that it can
                 * go out of scope quietly
-                * Disabled as I don't see need yet NI-S 2001/12/18
                 */
-               if (0 && SvPADMY(sv) && ! SvFAKE(sv))
+               if (SvPADMY(sv) && !SvFAKE(sv))
                    SvREADONLY_off(sv);
 
                if (SvTHINKFIRST(sv))