This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Half way through moving per-thread magicals into per-thread fields
[perl5.git] / op.c
diff --git a/op.c b/op.c
index e7d843d..71f6689 100644 (file)
--- a/op.c
+++ b/op.c
@@ -247,7 +247,7 @@ pad_findlex(char *name, PADOFFSET newoff, U32 seq, CV* startcv, I32 cx_ix)
                            warn("Variable \"%s\" will not stay shared", name);
                    }
                }
-               av_store(comppad, newoff, SvREFCNT_inc(oldsv));
+               av_store(comppad, newoff, oldsv ? SvREFCNT_inc(oldsv) : 0);
                return newoff;
            }
        }
@@ -511,6 +511,33 @@ pad_reset()
     pad_reset_pending = FALSE;
 }
 
+#ifdef USE_THREADS
+PADOFFSET
+find_thread_magical(name)
+char *name;
+{
+    dTHR;
+    char *p;
+    PADOFFSET key;
+    /* We currently only handle single character magicals */
+    p = strchr(per_thread_magicals, *name);
+    if (!p)
+       return NOT_IN_PAD;
+    key = magical_keys[p - per_thread_magicals];
+    if (key == NOT_IN_PAD) {
+       SV *sv;
+       key = magical_keys[p - per_thread_magicals] = key_create();
+       sv = NEWSV(0, 0);
+       av_store(thr->specific, key, sv);
+       sv_magic(sv, 0, 0, name, 1); 
+       DEBUG_L(PerlIO_printf(PerlIO_stderr(),
+                             "find_thread_magical: key %d new SV %p for %d\n",
+                             (int)key, sv, (int)*name));
+    }
+    return key;
+}
+#endif /* USE_THREADS */
+
 /* Destructor */
 
 void
@@ -1152,6 +1179,7 @@ I32 type;
            goto nomod;
        /* FALL THROUGH */
     case OP_PADSV:
+    case OP_SPECIFIC:
        modcount++;
        if (!type)
            croak("Can't localize lexical variable %s",
@@ -1314,6 +1342,10 @@ I32 type;
        }
        break;
       
+    case OP_SPECIFIC:
+       o->op_flags |= OPf_MOD;         /* XXX ??? */
+       break;
+
     case OP_RV2AV:
     case OP_RV2HV:
        o->op_flags |= OPf_REF; 
@@ -2150,7 +2182,8 @@ OP *repl;
                    else if (curop->op_type == OP_PADSV ||
                             curop->op_type == OP_PADAV ||
                             curop->op_type == OP_PADHV ||
-                            curop->op_type == OP_PADANY) {
+                            curop->op_type == OP_PADANY ||
+                            curop->op_type == OP_SPECIFIC) {
                             /* is okay */
                    }
                    else
@@ -3410,8 +3443,8 @@ OP *block;
                    croak(not_safe);
                else {
                    /* force display of errors found but not reported */
-                   sv_catpv(GvSV(errgv), not_safe);
-                   croak("%s", SvPVx(GvSV(errgv), na));
+                   sv_catpv(errsv, not_safe);
+                   croak("%s", SvPV(errsv, na));
                }
            }
        }
@@ -3814,6 +3847,8 @@ OP *o;
        o->op_ppaddr = ppaddr[OP_PADSV];
        return o;
     }
+    else if (o->op_type == OP_SPECIFIC)
+       return o;
     return newUNOP(OP_RV2SV, 0, scalar(o));
 }