]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
memdebug.h: avoid `-Wredundant-decls` with an extra guard
authorViktor Szakats <commit@vsz.me>
Wed, 12 Mar 2025 21:59:53 +0000 (22:59 +0100)
committerViktor Szakats <commit@vsz.me>
Thu, 13 Mar 2025 10:36:53 +0000 (11:36 +0100)
Add an extra guard for the function and variable declarations to avoid
redundant redeclaration warnings when including this header multiple
times. This can happen in unity builds when including it again after
`curl_memory.h`.

Fixes:
```
bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c
In file included from lib/mprintf.c:32,
                 from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:7:
lib/memdebug.h:52:14: error: redundant redeclaration of ‘curl_dbg_logfile’ [-Werror=redundant-decls]
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
In file included from tests/server/resolve.c:50,
                 from bld/tests/server/server_bundle.c:7,
                 from bld/tests/server/CMakeFiles/servers.dir/Unity/unity_0_c.c:4:
lib/memdebug.h:52:14: note: previous declaration of ‘curl_dbg_logfile’ with type ‘FILE *’
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
[...]
lib/memdebug.h:110:17: error: redundant redeclaration of ‘curl_dbg_fclose’ [-Werror=redundant-decls]
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
lib/memdebug.h:110:17: note: previous declaration of ‘curl_dbg_fclose’ with type ‘int(FILE *, int,  const char *)’
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
```
Ref: https://github.com/curl/curl/actions/runs/13822010778/job/38669360980#step:39:55

Cherry-picked from #15000
Closes #16696

lib/memdebug.h

index f45d4925f655a9de80c20e18ed9f25705ec3de1c..acc17a1d5617a0003750e27116506d4f21b57fd0 100644 (file)
 
 #define CURL_MT_LOGFNAME_BUFSIZE 512
 
+/* Avoid redundant redeclaration warnings with modern compilers, when including
+   this header multiple times. */
+#ifndef HEADER_CURL_MEMDEBUG_H_EXTERNS
+#define HEADER_CURL_MEMDEBUG_H_EXTERNS
 extern FILE *curl_dbg_logfile;
 
 /* memory functions */
@@ -108,6 +112,7 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
                                              int line, const char *source);
 
 CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
+#endif /* HEADER_CURL_MEMDEBUG_H_EXTERNS */
 
 #ifndef MEMDEBUG_NODEFINES