mirror of
https://github.com/curl/curl.git
synced 2025-04-24 16:40:32 +08:00
addrinfo: add curl macro to avoid redefining foreign symbols
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
This commit is contained in:
parent
7241953ba5
commit
de0693f249
4
.github/workflows/windows.yml
vendored
4
.github/workflows/windows.yml
vendored
@ -86,7 +86,7 @@ jobs:
|
|||||||
if [ '${{ matrix.build }}' = 'cmake' ]; then
|
if [ '${{ matrix.build }}' = 'cmake' ]; then
|
||||||
PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32"
|
PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32"
|
||||||
cmake -B bld -G Ninja ${options} \
|
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 \
|
-DCURL_WERROR=ON \
|
||||||
${{ matrix.config }}
|
${{ matrix.config }}
|
||||||
else
|
else
|
||||||
@ -252,7 +252,7 @@ jobs:
|
|||||||
cmake -B bld -G Ninja ${options} \
|
cmake -B bld -G Ninja ${options} \
|
||||||
-DCMAKE_C_FLAGS="${{ matrix.cflags }} ${CFLAGS_CMAKE} ${CPPFLAGS}" \
|
-DCMAKE_C_FLAGS="${{ matrix.cflags }} ${CFLAGS_CMAKE} ${CPPFLAGS}" \
|
||||||
-DCMAKE_BUILD_TYPE='${{ matrix.type }}' \
|
-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 \
|
-DCURL_WERROR=ON \
|
||||||
${{ matrix.config }}
|
${{ matrix.config }}
|
||||||
else
|
else
|
||||||
|
@ -118,7 +118,7 @@ Curl_getaddrinfo_ex(const char *nodename,
|
|||||||
|
|
||||||
*result = NULL; /* assume failure */
|
*result = NULL; /* assume failure */
|
||||||
|
|
||||||
error = getaddrinfo(nodename, servname, hints, &aihead);
|
error = CURL_GETADDRINFO(nodename, servname, hints, &aihead);
|
||||||
if(error)
|
if(error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ Curl_getaddrinfo_ex(const char *nodename,
|
|||||||
|
|
||||||
/* destroy the addrinfo list */
|
/* destroy the addrinfo list */
|
||||||
if(aihead)
|
if(aihead)
|
||||||
freeaddrinfo(aihead);
|
CURL_FREEADDRINFO(aihead);
|
||||||
|
|
||||||
/* if we failed, also destroy the Curl_addrinfo list */
|
/* if we failed, also destroy the Curl_addrinfo list */
|
||||||
if(error) {
|
if(error) {
|
||||||
@ -509,7 +509,7 @@ curl_dbg_freeaddrinfo(struct addrinfo *freethis,
|
|||||||
#ifdef USE_LWIPSOCK
|
#ifdef USE_LWIPSOCK
|
||||||
lwip_freeaddrinfo(freethis);
|
lwip_freeaddrinfo(freethis);
|
||||||
#else
|
#else
|
||||||
(freeaddrinfo)(freethis);
|
freeaddrinfo(freethis);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
|
#endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
|
||||||
@ -534,7 +534,7 @@ curl_dbg_getaddrinfo(const char *hostname,
|
|||||||
#ifdef USE_LWIPSOCK
|
#ifdef USE_LWIPSOCK
|
||||||
int res = lwip_getaddrinfo(hostname, service, hints, result);
|
int res = lwip_getaddrinfo(hostname, service, hints, result);
|
||||||
#else
|
#else
|
||||||
int res = (getaddrinfo)(hostname, service, hints, result);
|
int res = getaddrinfo(hostname, service, hints, result);
|
||||||
#endif
|
#endif
|
||||||
if(0 == res)
|
if(0 == res)
|
||||||
/* success */
|
/* success */
|
||||||
|
@ -84,20 +84,6 @@
|
|||||||
#undef socketpair
|
#undef socketpair
|
||||||
#endif
|
#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! */
|
/* sclose is probably already defined, redefine it! */
|
||||||
#undef sclose
|
#undef sclose
|
||||||
#undef fopen
|
#undef fopen
|
||||||
|
@ -935,6 +935,16 @@ endings either CRLF or LF so 't' is appropriate.
|
|||||||
|
|
||||||
#define CURL_ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
#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 */
|
/* Some versions of the Android NDK is missing the declaration */
|
||||||
#if defined(HAVE_GETPWUID_R) && \
|
#if defined(HAVE_GETPWUID_R) && \
|
||||||
defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
|
defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
|
||||||
|
@ -153,28 +153,6 @@ CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
|
|||||||
__LINE__, __FILE__)
|
__LINE__, __FILE__)
|
||||||
#endif
|
#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! */
|
/* sclose is probably already defined, redefine it! */
|
||||||
#undef sclose
|
#undef sclose
|
||||||
#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
|
#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
|
||||||
|
@ -50,12 +50,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UV_H
|
#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 */
|
/* this is for libuv-enabled debug builds only */
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,7 +81,6 @@ foreach(_target IN LISTS LIBTESTPROGS)
|
|||||||
if(NOT CURL_TEST_BUNDLES)
|
if(NOT CURL_TEST_BUNDLES)
|
||||||
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target})
|
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target})
|
||||||
endif()
|
endif()
|
||||||
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE")
|
|
||||||
set_target_properties(${_target_name} PROPERTIES
|
set_target_properties(${_target_name} PROPERTIES
|
||||||
OUTPUT_NAME "${_target}"
|
OUTPUT_NAME "${_target}"
|
||||||
PROJECT_LABEL "Test libtest ${_target}")
|
PROJECT_LABEL "Test libtest ${_target}")
|
||||||
|
@ -90,8 +90,6 @@ libstubgss_la_DEPENDENCIES =
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_TEST_BUNDLES
|
if USE_TEST_BUNDLES
|
||||||
AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE
|
|
||||||
|
|
||||||
libtest_bundle.c: $(top_srcdir)/tests/mk-bundle.pl lib1521.c
|
libtest_bundle.c: $(top_srcdir)/tests/mk-bundle.pl lib1521.c
|
||||||
@PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > libtest_bundle.c
|
@PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > libtest_bundle.c
|
||||||
|
|
||||||
|
@ -47,10 +47,6 @@ foreach(_target IN LISTS noinst_PROGRAMS)
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
|
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_STATICLIB")
|
||||||
endif()
|
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
|
set_target_properties(${_target_name} PROPERTIES
|
||||||
OUTPUT_NAME "${_target}"
|
OUTPUT_NAME "${_target}"
|
||||||
PROJECT_LABEL "Test server ${_target}")
|
PROJECT_LABEL "Test server ${_target}")
|
||||||
|
@ -43,7 +43,6 @@ LIBS = $(BLANK_AT_MAKETIME)
|
|||||||
if DOING_NATIVE_WINDOWS
|
if DOING_NATIVE_WINDOWS
|
||||||
AM_CPPFLAGS += -DCURL_STATICLIB
|
AM_CPPFLAGS += -DCURL_STATICLIB
|
||||||
endif
|
endif
|
||||||
AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE
|
|
||||||
|
|
||||||
# Makefile.inc provides neat definitions
|
# Makefile.inc provides neat definitions
|
||||||
include Makefile.inc
|
include Makefile.inc
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
* SPDX-License-Identifier: curl
|
* SPDX-License-Identifier: curl
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#ifndef CURL_NO_GETADDRINFO_OVERRIDE
|
|
||||||
#define CURL_NO_GETADDRINFO_OVERRIDE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "server_setup.h"
|
#include "server_setup.h"
|
||||||
|
|
||||||
/* Purpose
|
/* Purpose
|
||||||
|
Loading…
x
Reference in New Issue
Block a user