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

<http://perl5.git.perl.org/perl.git/commitdiff/0088f930e279eefbb657be8a26be2b3976c41fff?hp=bc0beb4372fab559d95e7a0f71fa87e717cd5064>

- Log -----------------------------------------------------------------
commit 0088f930e279eefbb657be8a26be2b3976c41fff
Author: Steffen Mueller <[email protected]>
Date:   Tue Feb 7 17:29:48 2017 +0100

    Hash vtables: Wrap hv_iterinit
-----------------------------------------------------------------------

Summary of changes:
 hv.c      |  5 +++++
 hv_vtbl.c | 22 +++++++++++++++++++++-
 hv_vtbl.h |  2 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/hv.c b/hv.c
index 164a8e65f2..effb83505b 100644
--- a/hv.c
+++ b/hv.c
@@ -2286,8 +2286,13 @@ value, you can get it through the macro C<HvFILL(hv)>.
 I32
 Perl_hv_iterinit(pTHX_ HV *hv)
 {
+    XPVHV *xhv = (XPVHV*)SvANY(hv);
+
     PERL_ARGS_ASSERT_HV_ITERINIT;
 
+    if (HvBODYHASVTBL(xhv))
+        return HvBODYVTBL(xhv)->hvt_iterinit(aTHX_ hv);
+
     if (SvOOK(hv)) {
        struct xpvhv_aux * iter = HvAUX(hv);
        HE * const entry = iter->xhv_eiter; /* HvEITER(hv) */
diff --git a/hv_vtbl.c b/hv_vtbl.c
index cac97c222b..c056ce3ec0 100644
--- a/hv_vtbl.c
+++ b/hv_vtbl.c
@@ -270,6 +270,25 @@ S_hv_mock_std_vtable_clone(pTHX_ HV *hv)
     return retval;
 }
 
+STATIC I32
+S_hv_mock_std_vtable_iterinit(pTHX_ HV *hv)
+{
+    /* THIS IS PURELY FOR TESTING! */
+    XPVHV* xhv = (XPVHV *)SvANY(hv);
+    I32 retval;
+
+    ENTER;
+    /* localize vtable such that hv_clear takes the normal code path */
+    SAVEPPTR(xhv->xhv_vtbl);
+
+    xhv->xhv_vtbl = NULL;
+    retval = hv_iterinit(hv);
+
+    LEAVE;
+
+    return retval;
+}
+
 HV_VTBL PL_mock_std_vtable = {
         S_hv_mock_std_vtable_init,
         S_hv_mock_std_vtable_destroy,
@@ -283,7 +302,8 @@ HV_VTBL PL_mock_std_vtable = {
         S_hv_mock_std_vtable_undef,
         S_hv_mock_std_vtable_clone,
         S_hv_mock_std_vtable_totalkeys,
-        S_hv_mock_std_vtable_usedkeys
+        S_hv_mock_std_vtable_usedkeys,
+        S_hv_mock_std_vtable_iterinit
 };
 
 /*
diff --git a/hv_vtbl.h b/hv_vtbl.h
index 65d6d7ab05..bca6f0226c 100644
--- a/hv_vtbl.h
+++ b/hv_vtbl.h
@@ -51,6 +51,8 @@ struct hv_vtbl {
     STRLEN     (*hvt_totalkeys)(pTHX_ HV *hv);
     /* Returns the number of keys used (ie. not including placeholders) */
     STRLEN     (*hvt_usedkeys)(pTHX_ HV *hv);
+    /* Wraps hv_iterinit */
+    I32                (*hvt_iterinit)(pTHX_ HV *hv);
 
     /* TODO also wrap all the iteration primitives! */
     /* TODO research what other primitives are missing! */

--
Perl5 Master Repository

Reply via email to