summaryrefslogtreecommitdiff
path: root/hv.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-03-04 15:30:00 +0000
committerDavid Mitchell <davem@iabyn.com>2015-03-11 14:31:04 +0000
commit3dc78631ef832e5b64aa86228917984dc5b14f5e (patch)
treee37e85fcd00d8f5ba8cd2710615e720ccb63c44b /hv.c
parent1835335041e939eb53f98ca39ac99981b211887d (diff)
downloadperl-3dc78631ef832e5b64aa86228917984dc5b14f5e.tar.gz
don't test non-null args
For lots of core functions: if a function parameter has been declared NN in embed.fnc, don't test for nullness at the start of the function, i.e. eliminate code like if (!foo) ... On debugging builds the test is redundant, as the PERL_ARGS_ASSERT_FOO at the start of the function will already have croaked. On optimised builds, it will skip the check (and so be slightly faster), but if actually passed a null arg, will now crash with a null-deref SEGV rather than doing whatever the check used to do (e.g. croak, or silently return and let the caller's code logic to go awry). But hopefully this should never happen as such instances will already have been detected on debugging builds. It also has the advantage of shutting up recent clangs which spew forth lots of stuff like: sv.c:6308:10: warning: nonnull parameter 'bigstr' will evaluate to 'true' on first encounter [-Wpointer-bool-conversion] if (!bigstr) The only exception was in dump.c, where rather than skipping the null test, I instead changed the function def in embed.fnc to allow a null arg, on the basis that dump functions are often used for debugging (where pointers may unexpectedly become NULL) and it's better there to display that this item is null than to SEGV. See the p5p thread starting at 20150224112829.GG28599@iabyn.com.
Diffstat (limited to 'hv.c')
-rw-r--r--hv.c23
1 files changed, 0 insertions, 23 deletions
diff --git a/hv.c b/hv.c
index c11566f62a..8403f0ded2 100644
--- a/hv.c
+++ b/hv.c
@@ -2096,11 +2096,6 @@ Perl_hv_iterinit(pTHX_ HV *hv)
{
PERL_ARGS_ASSERT_HV_ITERINIT;
- /* FIXME: Are we not NULL, or do we croak? Place bets now! */
-
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
if (SvOOK(hv)) {
struct xpvhv_aux * iter = HvAUX(hv);
HE * const entry = iter->xhv_eiter; /* HvEITER(hv) */
@@ -2128,9 +2123,6 @@ Perl_hv_riter_p(pTHX_ HV *hv) {
PERL_ARGS_ASSERT_HV_RITER_P;
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
iter = SvOOK(hv) ? HvAUX(hv) : hv_auxinit(hv);
return &(iter->xhv_riter);
}
@@ -2141,9 +2133,6 @@ Perl_hv_eiter_p(pTHX_ HV *hv) {
PERL_ARGS_ASSERT_HV_EITER_P;
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
iter = SvOOK(hv) ? HvAUX(hv) : hv_auxinit(hv);
return &(iter->xhv_eiter);
}
@@ -2154,9 +2143,6 @@ Perl_hv_riter_set(pTHX_ HV *hv, I32 riter) {
PERL_ARGS_ASSERT_HV_RITER_SET;
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
if (SvOOK(hv)) {
iter = HvAUX(hv);
} else {
@@ -2175,9 +2161,6 @@ Perl_hv_rand_set(pTHX_ HV *hv, U32 new_xhv_rand) {
PERL_ARGS_ASSERT_HV_RAND_SET;
#ifdef PERL_HASH_RANDOMIZE_KEYS
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
if (SvOOK(hv)) {
iter = HvAUX(hv);
} else {
@@ -2195,9 +2178,6 @@ Perl_hv_eiter_set(pTHX_ HV *hv, HE *eiter) {
PERL_ARGS_ASSERT_HV_EITER_SET;
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
if (SvOOK(hv)) {
iter = HvAUX(hv);
} else {
@@ -2515,9 +2495,6 @@ Perl_hv_iternext_flags(pTHX_ HV *hv, I32 flags)
PERL_ARGS_ASSERT_HV_ITERNEXT_FLAGS;
- if (!hv)
- Perl_croak(aTHX_ "Bad hash");
-
xhv = (XPVHV*)SvANY(hv);
if (!SvOOK(hv)) {