This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
don't test non-null args
authorDavid Mitchell <davem@iabyn.com>
Wed, 4 Mar 2015 15:30:00 +0000 (15:30 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 11 Mar 2015 14:31:04 +0000 (14:31 +0000)
commit3dc78631ef832e5b64aa86228917984dc5b14f5e
treee37e85fcd00d8f5ba8cd2710615e720ccb63c44b
parent1835335041e939eb53f98ca39ac99981b211887d
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.
dump.c
embed.fnc
hv.c
mro.c
op.c
perl.c
pp_sys.c
proto.h
regexec.c
sv.c
util.c