summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2007-12-20 20:23:45 +0000
committerNicholas Clark <nick@ccl4.org>2007-12-20 20:23:45 +0000
commit78ac7dd9596fbc525d458adec628f7d991dfe43a (patch)
tree06c246ec59c74eb07d3f3c531e209c7ff32ed165
parentac572bf4fde55cf563ae338dfe4e12b22ebc6d80 (diff)
downloadperl-78ac7dd9596fbc525d458adec628f7d991dfe43a.tar.gz
Similiarly Perl_newHV() can become a mathom by making newHV() a
wrapper around newSV_type() and tweaking Perl_sv_upgrade(). p4raw-id: //depot/perl@32676
-rw-r--r--embed.fnc2
-rw-r--r--hv.c24
-rw-r--r--hv.h10
-rw-r--r--mathoms.c10
-rw-r--r--proto.h4
-rw-r--r--sv.c14
6 files changed, 37 insertions, 27 deletions
diff --git a/embed.fnc b/embed.fnc
index 256f80f450..a37d54ffbd 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -573,7 +573,7 @@ Apa |OP* |newGVOP |I32 type|I32 flags|NN GV* gv
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
diff --git a/hv.c b/hv.c
index c8279d87be..9523fb0b28 100644
--- a/hv.c
+++ b/hv.c
@@ -1305,30 +1305,6 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
}
}
-/*
-=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)
{
diff --git a/hv.h b/hv.h
index b8d6b7d243..dd35ae58e6 100644
--- a/hv.h
+++ b/hv.h
@@ -528,6 +528,16 @@ struct refcounted_he {
#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
diff --git a/mathoms.c b/mathoms.c
index 3caab1beff..1ea9f346a8 100644
--- a/mathoms.c
+++ b/mathoms.c
@@ -67,6 +67,7 @@ PERL_CALLCONV int Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...
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 @@ Perl_newAV(pTHX)
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 */
/*
diff --git a/proto.h b/proto.h
index 26425128e4..42b4131634 100644
--- a/proto.h
+++ b/proto.h
@@ -1544,9 +1544,9 @@ PERL_CALLCONV OP* Perl_newHVREF(pTHX_ OP* o)
__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__
diff --git a/sv.c b/sv.c
index eaaa7260b9..8dfd3ac0c8 100644
--- a/sv.c
+++ b/sv.c
@@ -1260,6 +1260,20 @@ Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type)
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.