]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
addrinfo: add curl macro to avoid redefining foreign symbols
authorViktor Szakats <commit@vsz.me>
Sun, 9 Feb 2025 04:12:24 +0000 (05:12 +0100)
committerViktor Szakats <commit@vsz.me>
Thu, 13 Feb 2025 11:46:39 +0000 (12:46 +0100)
Before this patch curl code was redefining `getaddrinfo` and
`freeaddrinfo` system symbols to plug in its debug wrappers. This was
causing pains to avoid applying the redefinitions to system headers
defining these functions, and to the local debug wrappers. Especially
in unity builds. It also required workarounds for systems where these
symbols are already macros.

Introduce curl-namespaced macros for these functions and use them.
This allows to drop all workarounds and makes it work in all envs,
local targets and unity/bundle combinations.

Also drop GHA/windows workaround and use the same unity batch across
all jobs. Follow-up to 29e4eda631f46368c2adf833ba3065b1b46c2a7d #16272

Ref: #16272
Ref: 71cf0d1fca9e1f53524e1545ef0c08d174458d80 #14772
Ref: 3efba94f773db5d8ae19e33aa749ab7914cafeea #14765
Ref: f7d5f47059c381502824ef9c1c9a2ca484930c91 #14399

Closes #16274

.github/workflows/windows.yml
lib/curl_addrinfo.c
lib/curl_memory.h
lib/curl_setup.h
lib/memdebug.h
src/tool_operate.c
tests/libtest/CMakeLists.txt
tests/libtest/Makefile.am
tests/server/CMakeLists.txt
tests/server/Makefile.am
tests/server/resolve.c

index 21c2d219dd0b095005be6a14642a6c5e74f44395..29641393352e0fdc927426bbb73c6e1ca953c63f 100644 (file)
@@ -86,7 +86,7 @@ jobs:
           if [ '${{ matrix.build }}' = 'cmake' ]; then
             PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32"
             cmake -B bld -G Ninja ${options} \
-              -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 -DCURL_TEST_BUNDLES=ON \
+              -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30 -DCURL_TEST_BUNDLES=ON \
               -DCURL_WERROR=ON \
               ${{ matrix.config }}
           else
@@ -252,7 +252,7 @@ jobs:
             cmake -B bld -G Ninja ${options} \
               -DCMAKE_C_FLAGS="${{ matrix.cflags }} ${CFLAGS_CMAKE} ${CPPFLAGS}" \
               -DCMAKE_BUILD_TYPE='${{ matrix.type }}' \
-              -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=32 -DCURL_TEST_BUNDLES=ON \
+              -DCMAKE_UNITY_BUILD=ON -DCMAKE_UNITY_BUILD_BATCH_SIZE=30 -DCURL_TEST_BUNDLES=ON \
               -DCURL_WERROR=ON \
               ${{ matrix.config }}
           else
index 52f0f9125519c8fa2205c5f8b7ae77932be7547e..39cff02f3c66306fc227c26188215ad8fe3d1313 100644 (file)
@@ -118,7 +118,7 @@ Curl_getaddrinfo_ex(const char *nodename,
 
   *result = NULL; /* assume failure */
 
-  error = getaddrinfo(nodename, servname, hints, &aihead);
+  error = CURL_GETADDRINFO(nodename, servname, hints, &aihead);
   if(error)
     return error;
 
@@ -184,7 +184,7 @@ Curl_getaddrinfo_ex(const char *nodename,
 
   /* destroy the addrinfo list */
   if(aihead)
-    freeaddrinfo(aihead);
+    CURL_FREEADDRINFO(aihead);
 
   /* if we failed, also destroy the Curl_addrinfo list */
   if(error) {
@@ -509,7 +509,7 @@ curl_dbg_freeaddrinfo(struct addrinfo *freethis,
 #ifdef USE_LWIPSOCK
   lwip_freeaddrinfo(freethis);
 #else
-  (freeaddrinfo)(freethis);
+  freeaddrinfo(freethis);
 #endif
 }
 #endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
@@ -534,7 +534,7 @@ curl_dbg_getaddrinfo(const char *hostname,
 #ifdef USE_LWIPSOCK
   int res = lwip_getaddrinfo(hostname, service, hints, result);
 #else
-  int res = (getaddrinfo)(hostname, service, hints, result);
+  int res = getaddrinfo(hostname, service, hints, result);
 #endif
   if(0 == res)
     /* success */
index 7f110dab7de8b6df727d8ba516541d8b5a186568..bc3e944fea2c5a52f408f76d77bf6b5566446214 100644 (file)
 #undef socketpair
 #endif
 
-#ifndef CURL_NO_GETADDRINFO_OVERRIDE
-#ifdef HAVE_GETADDRINFO
-#if defined(getaddrinfo) && defined(__osf__)
-#undef ogetaddrinfo
-#else
-#undef getaddrinfo
-#endif
-#endif /* HAVE_GETADDRINFO */
-
-#ifdef HAVE_FREEADDRINFO
-#undef freeaddrinfo
-#endif /* HAVE_FREEADDRINFO */
-#endif /* !CURL_NO_GETADDRINFO_OVERRIDE */
-
 /* sclose is probably already defined, redefine it! */
 #undef sclose
 #undef fopen
index 7a6ef10b2dcbfc98c3b6064c0bb971b998fe016c..3879f5933736dc5237753e5b90856f7733871bc9 100644 (file)
@@ -935,6 +935,16 @@ endings either CRLF or LF so 't' is appropriate.
 
 #define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
 
+#ifdef CURLDEBUG
+#define CURL_GETADDRINFO(host,serv,hint,res) \
+  curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
+#define CURL_FREEADDRINFO(data) \
+  curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
+#else
+#define CURL_GETADDRINFO getaddrinfo
+#define CURL_FREEADDRINFO freeaddrinfo
+#endif
+
 /* Some versions of the Android NDK is missing the declaration */
 #if defined(HAVE_GETPWUID_R) && \
   defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
index 80f3374e52af12567d4d2d579cd54c7513b0ea90..f45d4925f655a9de80c20e18ed9f25705ec3de1c 100644 (file)
@@ -153,28 +153,6 @@ CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
                      __LINE__, __FILE__)
 #endif
 
-#ifndef CURL_NO_GETADDRINFO_OVERRIDE
-#ifdef HAVE_GETADDRINFO
-#if defined(getaddrinfo) && defined(__osf__)
-/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
-   our macro as for other platforms. Instead, we redefine the new name they
-   define getaddrinfo to become! */
-#define ogetaddrinfo(host,serv,hint,res) \
-  curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
-#else
-#undef getaddrinfo
-#define getaddrinfo(host,serv,hint,res) \
-  curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
-#endif
-#endif /* HAVE_GETADDRINFO */
-
-#ifdef HAVE_FREEADDRINFO
-#undef freeaddrinfo
-#define freeaddrinfo(data) \
-  curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
-#endif /* HAVE_FREEADDRINFO */
-#endif /* !CURL_NO_GETADDRINFO_OVERRIDE */
-
 /* sclose is probably already defined, redefine it! */
 #undef sclose
 #define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
index e4b53e21b5cd0bed67cc6de766bfa386bf9e70ce..20a8d87b1a341345f7e974e7e25a7f5c36c1c0c0 100644 (file)
 #endif
 
 #ifdef HAVE_UV_H
-/* Hack for Unity mode */
-#ifdef HEADER_CURL_MEMDEBUG_H
-#undef HEADER_CURL_MEMDEBUG_H
-#undef freeaddrinfo
-#undef getaddrinfo
-#endif
 /* this is for libuv-enabled debug builds only */
 #include <uv.h>
 #endif
index 6c1d8e9323f53de5342f40e74850c784d8d05dea..f5f6a0d10cf189c5ea8d8df00743f10bd11223c1 100644 (file)
@@ -81,7 +81,6 @@ foreach(_target IN LISTS LIBTESTPROGS)
   if(NOT CURL_TEST_BUNDLES)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target})
   endif()
-  set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE")
   set_target_properties(${_target_name} PROPERTIES
     OUTPUT_NAME "${_target}"
     PROJECT_LABEL "Test libtest ${_target}")
index c1363d8dd7c1b92200c3384b183c79593d5d4c5a..cccea6723ed60ab63c21bb471216be662c7b35ae 100644 (file)
@@ -90,8 +90,6 @@ libstubgss_la_DEPENDENCIES =
 endif
 
 if USE_TEST_BUNDLES
-AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE
-
 libtest_bundle.c: $(top_srcdir)/tests/mk-bundle.pl lib1521.c
        @PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > libtest_bundle.c
 
index 2ad8b5eed0d265b3d54254c7f5d16b11d73d1f2e..3b18bba4c3563673e910b811570839daf7c20ca5 100644 (file)
@@ -47,10 +47,6 @@ foreach(_target IN LISTS noinst_PROGRAMS)
   if(WIN32)
     set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
   endif()
-  # getaddrinfo/freeaddrinfo overrides break UNITY build by overriding them
-  # before including system headers. Server code doesn't need these overrides,
-  # so it's safe to disable them globally.
-  set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE")
   set_target_properties(${_target_name} PROPERTIES
     OUTPUT_NAME "${_target}"
     PROJECT_LABEL "Test server ${_target}")
index 40433f8c5c9cba04acb8d6d49b2ff335b3315894..c33532fc7cb6d4cc8736cc2be1d2f5c8e3f625f1 100644 (file)
@@ -43,7 +43,6 @@ LIBS = $(BLANK_AT_MAKETIME)
 if DOING_NATIVE_WINDOWS
 AM_CPPFLAGS += -DCURL_STATICLIB
 endif
-AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE
 
 # Makefile.inc provides neat definitions
 include Makefile.inc
index 0e8166f70ae0e12e3fc3beaef4ebefcc00234e0f..78a76daffcde6d3d98572acfd0517d3353aee212 100644 (file)
  * SPDX-License-Identifier: curl
  *
  ***************************************************************************/
-#ifndef CURL_NO_GETADDRINFO_OVERRIDE
-#define CURL_NO_GETADDRINFO_OVERRIDE
-#endif
-
 #include "server_setup.h"
 
 /* Purpose