CopSTASH_eq again
Andy Lester [Tue, 14 Jun 2005 23:49:26 +0000 (18:49 -0500)]
Message-ID: <20050615044926.GA29087@petdance.com>

p4raw-id: //depot/perl@24847

cop.h
embed.fnc
embed.h
global.sym
proto.h
util.c

diff --git a/cop.h b/cop.h
index b6f900c..c874872 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -178,20 +178,13 @@ struct cop {
 #  define CopSTASH(c)          (CopSTASHPV(c) \
                                 ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv)
 #  define CopSTASH_set(c,hv)   CopSTASHPV_set(c, (hv) ? HvNAME_get(hv) : Nullch)
-#  define CopSTASH_eq(c,hv)    ((hv)                                   \
-                                && (CopSTASHPV(c) == HvNAME_get(hv)    \
-                                    || (CopSTASHPV(c) && HvNAME_get(hv)\
-                                        && strEQ(CopSTASHPV(c), HvNAME_get(hv)))))
+#  define CopSTASH_eq(c,hv)    ((hv) && stashpv_hvname_match(c,hv))
 #  ifdef NETWARE
 #    define CopSTASH_free(c) SAVECOPSTASH_FREE(c)
-#  else
-#    define CopSTASH_free(c)   PerlMemShared_free(CopSTASHPV(c))      
-#  endif
-
-#  ifdef NETWARE
 #    define CopFILE_free(c) SAVECOPFILE_FREE(c)
 #  else
-#    define CopFILE_free(c)    (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = Nullch))      
+#    define CopSTASH_free(c)   PerlMemShared_free(CopSTASHPV(c))
+#    define CopFILE_free(c)    (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = Nullch))
 #  endif
 #else
 #  define CopFILEGV(c)         ((c)->cop_filegv)
index 1a4a8fe..0f9fa96 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1533,6 +1533,7 @@ Ap        |GV*    |gv_fetchsv|SV *name|I32 flags|I32 sv_type
 dpR    |bool   |is_gv_magical_sv|SV *name|U32 flags
 
 Apd    |char*  |savesvpv       |SV* sv
+ApR    |bool   |stashpv_hvname_match|NN const COP *cop|NN const HV *hv
 
 END_EXTERN_C
 /*
diff --git a/embed.h b/embed.h
index 238bda9..b609f77 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define is_gv_magical_sv       Perl_is_gv_magical_sv
 #endif
 #define savesvpv               Perl_savesvpv
+#define stashpv_hvname_match   Perl_stashpv_hvname_match
 #define ck_anoncode            Perl_ck_anoncode
 #define ck_bitop               Perl_ck_bitop
 #define ck_concat              Perl_ck_concat
 #define is_gv_magical_sv(a,b)  Perl_is_gv_magical_sv(aTHX_ a,b)
 #endif
 #define savesvpv(a)            Perl_savesvpv(aTHX_ a)
+#define stashpv_hvname_match(a,b)      Perl_stashpv_hvname_match(aTHX_ a,b)
 #define ck_anoncode(a)         Perl_ck_anoncode(aTHX_ a)
 #define ck_bitop(a)            Perl_ck_bitop(aTHX_ a)
 #define ck_concat(a)           Perl_ck_concat(aTHX_ a)
index 208bd2d..90ee9a6 100644 (file)
@@ -690,4 +690,5 @@ Perl_hv_placeholders_set
 Perl_gv_fetchpvn_flags
 Perl_gv_fetchsv
 Perl_savesvpv
+Perl_stashpv_hvname_match
 # ex: set ro:
diff --git a/proto.h b/proto.h
index 9c9e911..30e2c15 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -2820,6 +2820,11 @@ PERL_CALLCONV bool       Perl_is_gv_magical_sv(pTHX_ SV *name, U32 flags)
 
 
 PERL_CALLCONV char*    Perl_savesvpv(pTHX_ SV* sv);
+PERL_CALLCONV bool     Perl_stashpv_hvname_match(pTHX_ const COP *cop, const HV *hv)
+                       __attribute__warn_unused_result__
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
+
 
 END_EXTERN_C
 /*
diff --git a/util.c b/util.c
index a3dcd47..e7cc539 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4812,6 +4812,23 @@ Perl_get_hash_seed(pTHX)
      return myseed;
 }
 
+#ifdef USE_ITHREADS
+bool
+Perl_stashpv_hvname_match(pTHX_ const COP *c, const HV *hv)
+{
+    const char * const stashpv = CopSTASHPV(c);
+    const char * const name = HvNAME_get(hv);
+
+    if (stashpv == name)
+       return TRUE;
+    if (stashpv && name)
+       if (strEQ(stashpv, name))
+           return TRUE;
+    return FALSE;
+}
+#endif
+
+
 #ifdef PERL_GLOBAL_STRUCT
 
 struct perl_vars *