This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: CvFILE corruption under ithreads
authorRobin Houston <robin@cpan.org>
Sat, 19 May 2001 16:19:34 +0000 (17:19 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 25 Jun 2001 14:00:06 +0000 (14:00 +0000)
Message-ID: <20010519161934.A12751@puffinry.freeserve.co.uk>

p4raw-id: //depot/perl@10925

cv.h
op.c

diff --git a/cv.h b/cv.h
index 4ade508..7fa9400 100644 (file)
--- a/cv.h
+++ b/cv.h
@@ -55,6 +55,11 @@ Returns the stash of the CV.
 #define CvXSUBANY(sv)  ((XPVCV*)SvANY(sv))->xcv_xsubany
 #define CvGV(sv)       ((XPVCV*)SvANY(sv))->xcv_gv
 #define CvFILE(sv)     ((XPVCV*)SvANY(sv))->xcv_file
+#ifdef USE_ITHREADS
+#  define CvFILE_set_from_cop(sv, cop) (CvFILE(sv) = savepv(CopFILE(cop)))
+#else
+#  define CvFILE_set_from_cop(sv, cop) (CvFILE(sv) = CopFILE(cop))
+#endif
 #define CvFILEGV(sv)   (gv_fetchfile(CvFILE(sv))
 #define CvDEPTH(sv)    ((XPVCV*)SvANY(sv))->xcv_depth
 #define CvPADLIST(sv)  ((XPVCV*)SvANY(sv))->xcv_padlist
diff --git a/op.c b/op.c
index 2228289..913f196 100644 (file)
--- a/op.c
+++ b/op.c
@@ -4153,6 +4153,13 @@ Perl_cv_undef(pTHX_ CV *cv)
     }
 #endif /* USE_THREADS */
 
+#ifdef USE_ITHREADS
+    if (CvFILE(cv) && !CvXSUB(cv)) {
+       Safefree(CvFILE(cv));
+       CvFILE(cv) = 0;
+    }
+#endif
+
     if (!CvXSUB(cv) && CvROOT(cv)) {
 #ifdef USE_THREADS
        if (CvDEPTH(cv) || (CvOWNER(cv) && CvOWNER(cv) != thr))
@@ -4298,7 +4305,12 @@ S_cv_clone2(pTHX_ CV *proto, CV *outside)
     MUTEX_INIT(CvMUTEXP(cv));
     CvOWNER(cv)                = 0;
 #endif /* USE_THREADS */
+#ifdef USE_ITHREADS
+    CvFILE(cv)         = CvXSUB(proto) ? CvFILE(proto)
+                                       : savepv(CvFILE(proto));
+#else
     CvFILE(cv)         = CvFILE(proto);
+#endif
     CvGV(cv)           = CvGV(proto);
     CvSTASH(cv)                = CvSTASH(proto);
     CvROOT(cv)         = OpREFCNT_inc(CvROOT(proto));
@@ -4732,7 +4744,7 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
        }
     }
     CvGV(cv) = gv;
-    CvFILE(cv) = CopFILE(PL_curcop);
+    CvFILE_set_from_cop(cv, PL_curcop);
     CvSTASH(cv) = PL_curstash;
 #ifdef USE_THREADS
     CvOWNER(cv) = 0;
@@ -5110,7 +5122,7 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP *block)
     cv = PL_compcv;
     GvFORM(gv) = cv;
     CvGV(cv) = gv;
-    CvFILE(cv) = CopFILE(PL_curcop);
+    CvFILE_set_from_cop(cv, PL_curcop);
 
     for (ix = AvFILLp(PL_comppad); ix > 0; ix--) {
        if (!SvPADMY(PL_curpad[ix]) && !SvIMMORTAL(PL_curpad[ix]))