Change 32676 by [EMAIL PROTECTED] on 2007/12/20 20:23:45

        Similiarly Perl_newHV() can become a mathom by making newHV() a
        wrapper around newSV_type() and tweaking Perl_sv_upgrade().

Affected files ...

... //depot/perl/embed.fnc#540 edit
... //depot/perl/hv.c#367 edit
... //depot/perl/hv.h#116 edit
... //depot/perl/mathoms.c#82 edit
... //depot/perl/proto.h#876 edit
... //depot/perl/sv.c#1445 edit

Differences ...

==== //depot/perl/embed.fnc#540 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#539~32675~   2007-12-20 11:49:50.000000000 -0800
+++ perl/embed.fnc      2007-12-20 12:23:45.000000000 -0800
@@ -573,7 +573,7 @@
 Apa    |GV*    |newGVgen       |NN const char* pack
 Apa    |OP*    |newGVREF       |I32 type|NULLOK OP* o
 ApaR   |OP*    |newHVREF       |NN OP* o
-ApdaR  |HV*    |newHV
+AmdbaR |HV*    |newHV
 ApaR   |HV*    |newHVhv        |NULLOK HV* hv
 Apa    |IO*    |newIO
 Apa    |OP*    |newLISTOP      |I32 type|I32 flags|NULLOK OP* first|NULLOK OP* 
last

==== //depot/perl/hv.c#367 (text) ====
Index: perl/hv.c
--- perl/hv.c#366~32119~        2007-10-17 01:08:04.000000000 -0700
+++ perl/hv.c   2007-12-20 12:23:45.000000000 -0800
@@ -1305,30 +1305,6 @@
     }
 }
 
-/*
-=for apidoc newHV
-
-Creates a new HV.  The reference count is set to 1.
-
-=cut
-*/
-
-HV *
-Perl_newHV(pTHX)
-{
-    register XPVHV* xhv;
-    HV * const hv = (HV*)newSV_type(SVt_PVHV);
-    xhv = (XPVHV*)SvANY(hv);
-    assert(!SvOK(hv));
-#ifndef NODEFAULT_SHAREKEYS
-    HvSHAREKEYS_on(hv);         /* key-sharing on by default */
-#endif
-
-    xhv->xhv_max    = 7;       /* HvMAX(hv) = 7 (start with 8 buckets) */
-    xhv->xhv_fill   = 0;       /* HvFILL(hv) = 0 */
-    return hv;
-}
-
 HV *
 Perl_newHVhv(pTHX_ HV *ohv)
 {

==== //depot/perl/hv.h#116 (text) ====
Index: perl/hv.h
--- perl/hv.h#115~31977~        2007-09-26 03:21:50.000000000 -0700
+++ perl/hv.h   2007-12-20 12:23:45.000000000 -0800
@@ -528,6 +528,16 @@
 #define HV_DELETE              0x40
 
 /*
+=for apidoc newHV
+
+Creates a new HV.  The reference count is set to 1.
+
+=cut
+*/
+
+#define newHV()        ((HV*)newSV_type(SVt_PVHV))
+
+/*
  * Local variables:
  * c-indentation-style: bsd
  * c-basic-offset: 4

==== //depot/perl/mathoms.c#82 (text) ====
Index: perl/mathoms.c
--- perl/mathoms.c#81~32675~    2007-12-20 11:49:50.000000000 -0800
+++ perl/mathoms.c      2007-12-20 12:23:45.000000000 -0800
@@ -67,6 +67,7 @@
 PERL_CALLCONV int Perl_printf_nocontext(const char *format, ...);
 PERL_CALLCONV int Perl_magic_setglob(pTHX_ SV* sv, MAGIC* mg);
 PERL_CALLCONV AV * Perl_newAV(pTHX);
+PERL_CALLCONV HV * Perl_newHV(pTHX);
 
 /* ref() is now a macro using Perl_doref;
  * this version provided for binary compatibility only.
@@ -1338,6 +1339,15 @@
     AvMAX(av) = AvFILLp(av) = -1; */
 }
 
+HV *
+Perl_newHV(pTHX)
+{
+    HV * const hv = (HV*)newSV_type(SVt_PVHV);
+    assert(!SvOK(hv));
+
+    return hv;
+}
+
 #endif /* NO_MATHOMS */
 
 /*

==== //depot/perl/proto.h#876 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#875~32675~     2007-12-20 11:49:50.000000000 -0800
+++ perl/proto.h        2007-12-20 12:23:45.000000000 -0800
@@ -1544,9 +1544,9 @@
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
 
-PERL_CALLCONV HV*      Perl_newHV(pTHX)
+/* PERL_CALLCONV HV*   Perl_newHV(pTHX)
                        __attribute__malloc__
-                       __attribute__warn_unused_result__;
+                       __attribute__warn_unused_result__; */
 
 PERL_CALLCONV HV*      Perl_newHVhv(pTHX_ HV* hv)
                        __attribute__malloc__

==== //depot/perl/sv.c#1445 (text) ====
Index: perl/sv.c
--- perl/sv.c#1444~32675~       2007-12-20 11:49:50.000000000 -0800
+++ perl/sv.c   2007-12-20 12:23:45.000000000 -0800
@@ -1260,6 +1260,20 @@
                   Lets not write to it, in case it confuses a write-back
                   cache.  */
            }
+       } else {
+           assert(!SvOK(sv));
+           SvOK_off(sv);
+#ifndef NODEFAULT_SHAREKEYS
+           HvSHAREKEYS_on(sv);         /* key-sharing on by default */
+#endif
+           HvMAX(sv) = 7; /* (start with 8 buckets) */
+           if (old_type >= SVt_RV) {
+               HvFILL(sv) = 0;
+           } else {
+               /* It will have been zeroed when the new body was allocated.
+                  Lets not write to it, in case it confuses a write-back
+                  cache.  */
+           }
        }
 
        /* SVt_NULL isn't the only thing upgraded to AV or HV.
End of Patch.

Reply via email to