In perl.git, the branch smueller/hash_vtable has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/ec076b5594db75c679eb4306c7ea6df0f23dcbb7?hp=ba7be2bfe62c02392748088fe3d95609aff8e0df>

- Log -----------------------------------------------------------------
commit ec076b5594db75c679eb4306c7ea6df0f23dcbb7
Author: Steffen Mueller <smuel...@cpan.org>
Date:   Sat Jan 28 18:45:46 2017 +0100

    Hash vtables: Use macros for access to vtables

M       hv.c

commit 251be222da958dba1bf9d1c825acc4ac3aeef286
Author: Steffen Mueller <smuel...@cpan.org>
Date:   Sat Jan 28 17:46:10 2017 +0100

    Hash vtables: Add simple accessor macros

M       hv_vtbl.h
-----------------------------------------------------------------------

Summary of changes:
 hv.c      | 8 ++++----
 hv_vtbl.h | 7 +++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/hv.c b/hv.c
index 5d71556989..2e0531e923 100644
--- a/hv.c
+++ b/hv.c
@@ -388,9 +388,9 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, 
STRLEN klen,
 
     /* TODO: Figure out where exactly we should be dispatching to the vtbl
      *       implementation. */
-    if (xhv->xhv_vtbl != NULL) {
+    if (HvBODYHASVTBL(xhv)) {
         /* Have a vtbl-implemented hash, go and dispatch to the right action: 
*/
-        HV_VTBL *vtable = xhv->xhv_vtbl;
+        HV_VTBL *vtable = HvBODYVTBL(xhv);
         if (action & HV_DELETE) {
            return (void *)vtable->hvt_delete(hv, keysv, key, klen,
                                              flags, action, hash);
@@ -1776,8 +1776,8 @@ Perl_hv_clear(pTHX_ HV *hv)
 
     xhv = (XPVHV*)SvANY(hv);
 
-    if (xhv->xhv_vtbl != NULL) {
-        xhv->xhv_vtbl->hvt_clear(aTHX_ hv);
+    if (HvBODYHASVTBL(xhv)) {
+        HvBODYVTBL(xhv)->hvt_clear(aTHX_ hv);
     }
 
     /* avoid hv being freed when calling destructors below */
diff --git a/hv_vtbl.h b/hv_vtbl.h
index 30c3dbe2d2..ddf27ddc79 100644
--- a/hv_vtbl.h
+++ b/hv_vtbl.h
@@ -32,6 +32,13 @@ typedef struct hv_vtbl HV_VTBL;
 
 extern HV_VTBL PL_mock_std_vtable;
 
+/* TODO add apidoc */
+#define HvVTBL(hv)      (((XPVHV*)SvANY((hv)))->xhv_vtbl)
+#define HvBODYVTBL(xhv) ((xhv)->xhv_vtbl)
+
+#define HvHASVTBL(hv)       (HvVTBL(hv) != NULL)
+#define HvBODYHASVTBL(xhv)  (HvBODYVTBL(xhv) != NULL)
+
 
 /*
  * ex: set ts=8 sts=4 sw=4 et:

--
Perl5 Master Repository

Reply via email to