git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 04/12] mark unused parameters in trivial compat functions

From
Jeff King <peff@peff.net>
Date
Oct 18, 2022, 01:05 UTC
Message-ID
<Y037yNWgnAEhsL+k@coredump.intra.peff.net>
In-Reply-To
<Y036whEorZV0rOgB@coredump.intra.peff.net>

When a platform feature isn't available or in use, we sometimes conditionally compile empty or trivial functions to turn these into noops. We need to annotate their parameters so that -Wunused-parameters won't complain about them.

Note that there are many more of these in compat/mingw.h, but we'll leave them for now, as there's some trickery required to get the UNUSED macro available there.

Signed-off-by: Jeff King <peff@peff.net>
---
 compat/nonblock.c |  2 +-
 exec-cmd.c        |  2 +-
 git-compat-util.h | 16 ++++++++++------
 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/compat/nonblock.c b/compat/nonblock.c
index 9694ebdb1d..5b51195c32 100644
--- a/compat/nonblock.c
+++ b/compat/nonblock.c
@@ -41,7 +41,7 @@ int enable_pipe_nonblock(int fd)
 
 #else
 
-int enable_pipe_nonblock(int fd)
+int enable_pipe_nonblock(int fd UNUSED)
 {
 	errno = ENOSYS;
 	return -1;
diff --git a/exec-cmd.c b/exec-cmd.c
index eeb2ee52b8..0232bbc990 100644
--- a/exec-cmd.c
+++ b/exec-cmd.c
@@ -252,7 +252,7 @@ static const char *system_prefix(void)
  * This is called during initialization, but No work needs to be done here when
  * runtime prefix is not being used.
  */
-void git_resolve_executable_dir(const char *argv0)
+void git_resolve_executable_dir(const char *argv0 UNUSED)
 {
 }
 
diff --git a/git-compat-util.h b/git-compat-util.h
index ea53ea4a78..a76d0526f7 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -314,7 +314,9 @@ typedef unsigned long uintptr_t;
 #ifdef PRECOMPOSE_UNICODE
 #include "compat/precompose_utf8.h"
 #else
-static inline const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix)
+static inline const char *precompose_argv_prefix(int argc UNUSED,
+						 const char **argv UNUSED,
+						 const char *prefix)
 {
 	return prefix;
 }
@@ -339,7 +341,9 @@ struct itimerval {
 #endif
 
 #ifdef NO_SETITIMER
-static inline int setitimer(int which, const struct itimerval *value, struct itimerval *newvalue) {
+static inline int setitimer(int which UNUSED,
+			    const struct itimerval *value UNUSED,
+			    struct itimerval *newvalue UNUSED) {
 	return 0; /* pretend success */
 }
 #endif
@@ -424,15 +428,15 @@ int lstat_cache_aware_rmdir(const char *path);
 #endif
 
 #ifndef has_dos_drive_prefix
-static inline int git_has_dos_drive_prefix(const char *path)
+static inline int git_has_dos_drive_prefix(const char *path UNUSED)
 {
 	return 0;
 }
 #define has_dos_drive_prefix git_has_dos_drive_prefix
 #endif
 
 #ifndef skip_dos_drive_prefix
-static inline int git_skip_dos_drive_prefix(char **path)
+static inline int git_skip_dos_drive_prefix(char **path UNUSED)
 {
 	return 0;
 }
@@ -1467,11 +1471,11 @@ int open_nofollow(const char *path, int flags);
 #endif
 
 #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
-static inline void flockfile(FILE *fh)
+static inline void flockfile(FILE *fh UNUSED)
 {
 	; /* nothing */
 }
-static inline void funlockfile(FILE *fh)
+static inline void funlockfile(FILE *fh UNUSED)
 {
 	; /* nothing */
 }
-- 
2.38.0.371.g300879f34e
Previous: Jeff KingNext: Jeff King
Message 5 of 13 in “more unused-parameter fixes / annotations”
  1. 0/12 more unused-parameter fixes / annotationsJeff King, Oct 18, 2022
  2. 01/12 diffstat_consume(): assert non-zero lengthJeff King, Oct 18, 2022
  3. 02/12 submodule--helper: drop unused argc from module_list_compute()Jeff King, Oct 18, 2022
  4. 03/12 update-index: drop unused argc from do_reupdate()Jeff King, Oct 18, 2022
  5. 04/12 mark unused parameters in trivial compat functionsJeff King, Oct 18, 2022
  6. 05/12 object-file: mark unused parameters in hash_unknown functionsJeff King, Oct 18, 2022
  7. 06/12 string-list: mark unused callback parametersJeff King, Oct 18, 2022
  8. 07/12 date: mark unused parameters in handler functionsJeff King, Oct 18, 2022
  9. 08/12 apply: mark unused parameters in handlersJeff King, Oct 18, 2022
  10. 09/12 apply: mark unused parameters in noop error/warning routineJeff King, Oct 18, 2022
  11. 11/12 diffcore-pickaxe: mark unused parameters in pickaxe functionsJeff King, Oct 18, 2022
  12. 10/12 convert: mark unused parameter in null stream filterJeff King, Oct 18, 2022
  13. 12/12 ll-merge: mark unused parameters in callbacksJeff King, Oct 18, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.