ext\ExtUtils\t\Embed.t fails test when upgrading a perl with different core headers.
[p5sagit/p5-mst-13.2.git] / gv.c
diff --git a/gv.c b/gv.c
index 2bb9ccb..f48ef98 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -104,31 +104,39 @@ Perl_gv_IOadd(pTHX_ register GV *gv)
 GV *
 Perl_gv_fetchfile(pTHX_ const char *name)
 {
+    return gv_fetchfile_flags(name, strlen(name), 0);
+}
+
+GV *
+Perl_gv_fetchfile_flags(pTHX_ const char *const name, const STRLEN namelen,
+                       const U32 flags)
+{
     dVAR;
     char smallbuf[128];
     char *tmpbuf;
-    STRLEN tmplen;
+    const STRLEN tmplen = namelen + 2;
     GV *gv;
 
+    PERL_UNUSED_ARG(flags);
+
     if (!PL_defstash)
        return NULL;
 
-    tmplen = strlen(name);
-    if (tmplen + 2 <= sizeof smallbuf)
+    if (tmplen <= sizeof smallbuf)
        tmpbuf = smallbuf;
     else
        Newx(tmpbuf, tmplen, char);
     /* This is where the debugger's %{"::_<$filename"} hash is created */
     tmpbuf[0] = '_';
     tmpbuf[1] = '<';
-    memcpy(tmpbuf + 2, name, tmplen);
-    gv = *(GV**)hv_fetch(PL_defstash, tmpbuf, tmplen + 2, TRUE);
+    memcpy(tmpbuf + 2, name, namelen);
+    gv = *(GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, TRUE);
     if (!isGV(gv)) {
-       gv_init(gv, PL_defstash, tmpbuf, tmplen + 2, FALSE);
+       gv_init(gv, PL_defstash, tmpbuf, tmplen, FALSE);
 #ifdef PERL_DONT_CREATE_GVSV
-       GvSV(gv) = newSVpvn(name, tmplen);
+       GvSV(gv) = newSVpvn(name, namelen);
 #else
-       sv_setpvn(GvSV(gv), name, tmplen);
+       sv_setpvn(GvSV(gv), name, namelen);
 #endif
        if (PERLDB_LINE)
            hv_magic(GvHVn(gv_AVadd(gv)), NULL, PERL_MAGIC_dbfile);
@@ -247,7 +255,6 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
            if (exported_constant)
                GvIMPORTED_CV_on(gv);
        } else {
-           /* XXX unsafe for threads if eval_owner isn't held */
            (void) start_subparse(0,0); /* Create empty CV in compcv. */
            GvCV(gv) = PL_compcv;
        }
@@ -361,7 +368,7 @@ Perl_gv_fetchmeth(pTHX_ HV *stash, const char *name, STRLEN len, I32 level)
     }
 
     gvp = (GV**)hv_fetchs(stash, "ISA", FALSE);
-    av = (gvp && (gv = *gvp) && gv != (GV*)&PL_sv_undef) ? GvAV(gv) : NULL;
+    av = (gvp && (gv = *gvp) && isGV_with_GP(gv)) ? GvAV(gv) : NULL;
 
     /* create and re-create @.*::SUPER::ISA on demand */
     if (!av || !SvMAGIC(av)) {
@@ -373,7 +380,7 @@ Perl_gv_fetchmeth(pTHX_ HV *stash, const char *name, STRLEN len, I32 level)
            packlen -= 7;
            basestash = gv_stashpvn(hvname, packlen, GV_ADD);
            gvp = (GV**)hv_fetchs(basestash, "ISA", FALSE);
-           if (gvp && (gv = *gvp) != (GV*)&PL_sv_undef && (av = GvAV(gv))) {
+           if (gvp && (gv = *gvp) && isGV_with_GP(gv) && (av = GvAV(gv))) {
                gvp = (GV**)hv_fetchs(stash, "ISA", TRUE);
                if (!gvp || !(gv = *gvp))
                    Perl_croak(aTHX_ "Cannot create %s::ISA", hvname);
@@ -670,11 +677,11 @@ Perl_gv_autoload4(pTHX_ HV *stash, const char *name, STRLEN len, I32 method)
  * that implements the logic of automatical ties like %! and %-
  *
  * The "gv" parameter should be the glob.
- * "varpv" holds the name of the var, used for error messages
- * "namesv" holds the module name
+ * "varpv" holds the name of the var, used for error messages.
+ * "namesv" holds the module name. Its refcount will be decremented.
  * "methpv" holds the method name to test for to check that things
- *   are working reasonably close to as expected
- * "flags" if flag & 1 then save the scalar before loading.
+ *   are working reasonably close to as expected.
+ * "flags": if flag & 1 then save the scalar before loading.
  * For the protection of $! to work (it is set by this routine)
  * the sv slot must already be magicalized.
  */
@@ -683,25 +690,30 @@ S_require_tie_mod(pTHX_ GV *gv, const char *varpv, SV* namesv, const char *methp
 {
     dVAR;
     HV* stash = gv_stashsv(namesv, 0);
-    
+
     if (!stash || !(gv_fetchmethod(stash, methpv))) {
-        SV *module = newSVsv(namesv);
+       SV *module = newSVsv(namesv);
+       char varname = *varpv; /* varpv might be clobbered by load_module,
+                                 so save it. For the moment it's always
+                                 a single char. */
        dSP;
-       PUTBACK;
        ENTER;
        if ( flags & 1 )
-           save_scalar(gv); 
-        Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, module, NULL);
+           save_scalar(gv);
+       PUSHSTACKi(PERLSI_MAGIC);
+       Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, module, NULL);
+       POPSTACK;
        LEAVE;
        SPAGAIN;
        stash = gv_stashsv(namesv, 0);
        if (!stash)
-           Perl_croak( aTHX_ "panic: Can't use %%%s because %"SVf" is not available", 
-               varpv, SVfARG(module));
-       else if (!gv_fetchmethod(stash, methpv))    
-           Perl_croak( aTHX_ "panic: Can't use %%%s because %"SVf" does not support method %s", 
-               varpv, SVfARG(module), methpv);
+           Perl_croak(aTHX_ "panic: Can't use %%%c because %"SVf" is not available",
+                   varname, SVfARG(namesv));
+       else if (!gv_fetchmethod(stash, methpv))
+           Perl_croak(aTHX_ "panic: Can't use %%%c because %"SVf" does not support method %s",
+                   varname, SVfARG(namesv), methpv);
     }
+    SvREFCNT_dec(namesv);
     return stash;
 }
 
@@ -709,7 +721,7 @@ S_require_tie_mod(pTHX_ GV *gv, const char *varpv, SV* namesv, const char *methp
 =for apidoc gv_stashpv
 
 Returns a pointer to the stash for a specified package.  Uses C<strlen> to
-determine the length of C<name, then calls C<gv_stashpvn()>.
+determine the length of C<name>, then calls C<gv_stashpvn()>.
 
 =cut
 */
@@ -989,14 +1001,12 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
        if (add) {
            GvMULTI_on(gv);
            gv_init_sv(gv, sv_type);
-           if (sv_type == SVt_PVHV && len == 1 ) {
+           if (len == 1 && (sv_type == SVt_PVHV || sv_type == SVt_PVGV)) {
                if (*name == '!')
                    require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
-               else
-               if (*name == '-' || *name == '+') 
-                    require_tie_mod(gv, name, newSVpvs("re::Tie::Hash::NamedCapture"), "FETCH", 0);
-               
-            }              
+               else if (*name == '-' || *name == '+')
+                   require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "FETCH", 0);
+           }
        }
        return gv;
     } else if (no_init) {
@@ -1181,13 +1191,13 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
            goto magicalize;
 
        case '!':
-       GvMULTI_on(gv);    
+           GvMULTI_on(gv);
            /* If %! has been used, automatically load Errno.pm. */
 
            sv_magic(GvSVn(gv), (SV*)gv, PERL_MAGIC_sv, name, len);
 
             /* magicalization must be done before require_tie_mod is called */
-           if (sv_type == SVt_PVHV)
+           if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
                require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
 
            break;
@@ -1195,31 +1205,19 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
        case '+':
        GvMULTI_on(gv); /* no used once warnings here */
         {
-            bool plus = (*name == '+');
-            SV *stashname = newSVpvs("re::Tie::Hash::NamedCapture");
             AV* const av = GvAVn(gv);
-           HV *const hv = GvHVn(gv);
-           HV *const hv_tie = newHV();
-            SV *tie = newRV_noinc((SV*)hv_tie);
+           SV* const avc = (*name == '+') ? (SV*)av : NULL;
 
-            sv_bless(tie, gv_stashsv(stashname,GV_ADD));
-            hv_magic(hv, (GV*)tie, PERL_MAGIC_tied);    
-            sv_magic((SV*)av, (plus ? (SV*)av : NULL), PERL_MAGIC_regdata, NULL, 0);
+           sv_magic((SV*)av, avc, PERL_MAGIC_regdata, NULL, 0);
             sv_magic(GvSVn(gv), (SV*)gv, PERL_MAGIC_sv, name, len);
-
-            if (plus)
+            if (avc)
                 SvREADONLY_on(GvSVn(gv));
-            else
-                Perl_hv_store(aTHX_ hv_tie, STR_WITH_LEN("all"), newSViv(1), 0);
-            
-            SvREADONLY_on(hv);
-            SvREADONLY_on(tie);
             SvREADONLY_on(av);
-                
-            if (sv_type == SVt_PVHV) 
-                require_tie_mod(gv, name, stashname, "FETCH", 0);
 
-           break;
+            if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
+                require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "FETCH", 0);
+
+            break;
        }
        case '*':
        case '#':
@@ -1289,7 +1287,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
        {
            SV * const sv = GvSVn(gv);
            if (!sv_derived_from(PL_patchlevel, "version"))
-               upg_version(PL_patchlevel);
+               upg_version(PL_patchlevel, TRUE);
            GvSV(gv) = vnumify(PL_patchlevel);
            SvREADONLY_on(GvSV(gv));
            SvREFCNT_dec(sv);
@@ -1347,9 +1345,7 @@ Perl_newIO(pTHX)
 {
     dVAR;
     GV *iogv;
-    IO * const io = (IO*)newSV(0);
-
-    sv_upgrade((SV *)io,SVt_PVIO);
+    IO * const io = (IO*)newSV_type(SVt_PVIO);
     /* This used to read SvREFCNT(io) = 1;
        It's not clear why the reference count needed an explicit reset. NWC
     */
@@ -1866,6 +1862,19 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
     } else {
     not_found:                 /* No method found, either report or croak */
       switch (method) {
+        case lt_amg:
+        case le_amg:
+        case gt_amg:
+        case ge_amg:
+        case eq_amg:
+        case ne_amg:
+        case slt_amg:
+        case sle_amg:
+        case sgt_amg:
+        case sge_amg:
+        case seq_amg:
+        case sne_amg:
+          postpr = 0; break;
         case to_sv_amg:
         case to_av_amg:
         case to_hv_amg: