This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handy.h, hv.h: fixup hash s suffix macro definitions, move to hv.h
authorYves Orton <demerphq@gmail.com>
Wed, 19 Oct 2016 08:36:14 +0000 (10:36 +0200)
committerYves Orton <demerphq@gmail.com>
Wed, 19 Oct 2016 11:27:59 +0000 (13:27 +0200)
For some reason s suffix macro definitions intended for handling
constant string arguments were put into handy.h and not into hv.h.

I think this is wrong, especially as the macro defintions have
"drifted" and are not properly defined in terms the right base
macros.

Also we want to have such wrappers for the main hash functions,
so move them all to hv.h, recode them properly in terms of the
right base macros, and add support for the missing functions.

handy.h
hv.h

diff --git a/handy.h b/handy.h
index d44a226..5e31d1e 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -417,14 +417,7 @@ a string/length pair.
     Perl_gv_fetchpvn_flags(aTHX_ namebeg, len, add, sv_type)
 #define sv_catxmlpvs(dsv, str, utf8) \
     Perl_sv_catxmlpvn(aTHX_ dsv, STR_WITH_LEN(str), utf8)
-#define hv_fetchs(hv,key,lval)                                         \
-  ((SV **)Perl_hv_common(aTHX_ (hv), NULL, STR_WITH_LEN(key), 0,       \
-                        (lval) ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE)  \
-                        : HV_FETCH_JUST_SV, NULL, 0))
-
-#define hv_stores(hv,key,val)                                          \
-  ((SV **)Perl_hv_common(aTHX_ (hv), NULL, STR_WITH_LEN(key), 0,       \
-                        (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), (val), 0))
+
 
 #define lex_stuff_pvs(pv,flags) Perl_lex_stuff_pvn(aTHX_ STR_WITH_LEN(pv), flags)
 
diff --git a/hv.h b/hv.h
index 0e773f2..ee536f0 100644 (file)
--- a/hv.h
+++ b/hv.h
@@ -475,6 +475,8 @@ C<SV*>.
                              (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV),      \
                              (val), (hash)))
 
+
+
 #define hv_exists(hv, key, klen)                                       \
     (hv_common_key_len((hv), (key), (klen), HV_FETCH_ISEXISTS, NULL, 0) \
      ? TRUE : FALSE)
@@ -488,6 +490,24 @@ C<SV*>.
     (MUTABLE_SV(hv_common_key_len((hv), (key), (klen),                 \
                                  (flags) | HV_DELETE, NULL, 0)))
 
+/* Provide 's' suffix subs for constant strings (and avoid needing to count
+ * chars). See STR_WITH_LEN in handy.h - because these are macros we cant use
+ * STR_WITH_LEN to do the work, we have to unroll it. */
+#define hv_existss(hv, key) \
+    hv_exists((hv), ("" key ""), (sizeof(key)-1))
+
+#define hv_fetchs(hv, key, lval) \
+    hv_fetch((hv), ("" key ""), (sizeof(key)-1), (lval))
+
+#define hv_deletes(hv, key, flags) \
+    hv_delete((hv), ("" key ""), (sizeof(key)-1), (flags))
+
+#define hv_name_sets(hv, name, flags) \
+    hv_name_set((hv),("" name ""),(sizeof(name)-1), flags)
+
+#define hv_stores(hv, key, val) \
+    hv_store((hv), ("" key ""), (sizeof(key)-1), (val), 0)
+
 #ifdef PERL_CORE
 # define hv_storehek(hv, hek, val) \
     hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek),   \