]> git.ipfire.org Git - thirdparty/git.git/commit
compat-util: type-check parameters of no-op replacement functions
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 Aug 2020 00:25:37 +0000 (17:25 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Aug 2020 00:25:37 +0000 (17:25 -0700)
commit15b52a44e0c92a0658e891194a5b0610d1f53afc
treeee4cc4a68988ac87484ebb6e3476b5fdd8546f3e
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc
compat-util: type-check parameters of no-op replacement functions

When there is no need to run a specific function on certain platforms,
we often #define an empty function to swallow its parameters and
make it into a no-op, e.g.

    #define precompose_argv(c,v) /* no-op */

While this guarantees that no unneeded code is generated, it also
discards type and other checks on these parameters, e.g. a new code
written with the argv-array API (diff_args is of type "struct
argv_array" that has .argc and .argv members):

    precompose_argv(diff_args.argc, diff_args.argv);

must be updated to use "struct strvec diff_args" with .nr and .v
members, like so:

    precompose_argv(diff_args.nr, diff_args.v);

after the argv-array API has been updated to the strvec API.
However, the "no oop" C preprocessor macro is too aggressive to
discard what is unused, and did not catch such a call that was left
unconverted.

Using a "static inline" function whose body is a no-op should still
result in the same binary with decent compilers yet catch such a
reference to a missing field or passing a value of a wrong type.

While at it, I notice that precompute_str() has never been used
anywhere in the code, since it was introduced at 76759c7d (git on
Mac OS and precomposed unicode, 2012-07-08).  Instead of turning it
into a static inline, just remove it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h