diff options
author | David Mitchell <davem@iabyn.com> | 2015-03-04 15:30:00 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-03-11 14:31:04 +0000 |
commit | 3dc78631ef832e5b64aa86228917984dc5b14f5e (patch) | |
tree | e37e85fcd00d8f5ba8cd2710615e720ccb63c44b /proto.h | |
parent | 1835335041e939eb53f98ca39ac99981b211887d (diff) | |
download | perl-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 'proto.h')
-rw-r--r-- | proto.h | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -986,10 +986,9 @@ PERL_CALLCONV void Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp) assert(sv); assert(delim); assert(mark); assert(sp) PERL_CALLCONV void Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) - __attribute__nonnull__(pTHX_2) - __attribute__nonnull__(pTHX_3); + __attribute__nonnull__(pTHX_2); #define PERL_ARGS_ASSERT_DO_MAGIC_DUMP \ - assert(file); assert(mg) + assert(file) PERL_CALLCONV I32 Perl_do_ncmp(pTHX_ SV *const left, SV *const right) __attribute__warn_unused_result__ @@ -1427,11 +1426,7 @@ PERL_CALLCONV SV* Perl_gv_const_sv(pTHX_ GV* gv) #define PERL_ARGS_ASSERT_GV_CONST_SV \ assert(gv) -PERL_CALLCONV void Perl_gv_dump(pTHX_ GV* gv) - __attribute__nonnull__(pTHX_1); -#define PERL_ARGS_ASSERT_GV_DUMP \ - assert(gv) - +PERL_CALLCONV void Perl_gv_dump(pTHX_ GV* gv); PERL_CALLCONV void Perl_gv_efullname(pTHX_ SV* sv, const GV* gv) __attribute__nonnull__(pTHX_1) __attribute__nonnull__(pTHX_2); |