Fix refcounts for lock/magic_mutexfree. Make OP_LOCK auto-ref
Malcolm Beattie [Thu, 23 Oct 1997 09:22:40 +0000 (09:22 +0000)]
its argument using ck_rfun as OP_DEFINED. Make pp_lock return
a ref to its argument for AV, HV, CV.

p4raw-id: //depot/perl@170

mg.c
op.c
opcode.h
opcode.pl
pp.c
pp_hot.c

diff --git a/mg.c b/mg.c
index dedf381..7f49f68 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1723,6 +1723,7 @@ MAGIC *mg;
        croak("panic: magic_mutexfree");
     MUTEX_DESTROY(MgMUTEXP(mg));
     COND_DESTROY(MgCONDP(mg));
+    SvREFCNT_dec(sv);
     return 0;
 }
 #endif /* USE_THREADS */
diff --git a/op.c b/op.c
index 680b825..f9449f5 100644 (file)
--- a/op.c
+++ b/op.c
@@ -1288,7 +1288,7 @@ I32 type;
 
     switch (o->op_type) {
     case OP_ENTERSUB:
-       if ((type == OP_DEFINED) &&
+       if ((type == OP_DEFINED || type == OP_LOCK) &&
            !(o->op_flags & OPf_STACKED)) {
            o->op_type = OP_RV2CV;             /* entersub => rv2cv */
            o->op_ppaddr = ppaddr[OP_RV2CV];
index 7cf7f66..1b465dd 100644 (file)
--- a/opcode.h
+++ b/opcode.h
@@ -2137,7 +2137,7 @@ EXT OP * (*check[]) _((OP *op)) = {
        ck_null,        /* egrent */
        ck_null,        /* getlogin */
        ck_fun,         /* syscall */
-       ck_null,        /* lock */
+       ck_rfun,        /* lock */
 };
 #endif
 
index fb3accc..f8a7bb7 100755 (executable)
--- a/opcode.pl
+++ b/opcode.pl
@@ -654,4 +654,4 @@ getlogin    getlogin                ck_null         st
 syscall                syscall                 ck_fun          imst    S L
 
 # For multi-threading
-lock           lock                    ck_null         s       S
+lock           lock                    ck_rfun         s       S
diff --git a/pp.c b/pp.c
index d002a1f..649506f 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4266,8 +4266,9 @@ void *svv;
 PP(pp_lock)
 {
     dSP;
-#ifdef USE_THREADS
     dTOPss;
+    SV *retsv = sv;
+#ifdef USE_THREADS
     MAGIC *mg;
     
     if (SvROK(sv))
@@ -4284,8 +4285,14 @@ PP(pp_lock)
        DEBUG_L(PerlIO_printf(PerlIO_stderr(), "0x%lx: pp_lock lock 0x%lx\n",
                              (unsigned long)thr, (unsigned long)sv);)
        MUTEX_UNLOCK(MgMUTEXP(mg));
+       SvREFCNT_inc(sv);       /* keep alive until magic_mutexfree */
        save_destructor(unlock_condpair, sv);
     }
 #endif /* USE_THREADS */
+    if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV
+       || SvTYPE(retsv) == SVt_PVCV) {
+       retsv = refto(retsv);
+    }
+    SETs(retsv);
     RETURN;
 }
index c19e928..bc46cca 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1866,6 +1866,7 @@ PP(pp_entersub)
            DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
                                  thr, sv);)
            MUTEX_UNLOCK(MgMUTEXP(mg));
+           SvREFCNT_inc(sv);   /* Keep alive until magic_mutexfree */
            save_destructor(unlock_condpair, sv);
        }
        MUTEX_LOCK(CvMUTEXP(cv));