From: Viktor Szakats Date: Thu, 30 Jan 2025 11:42:52 +0000 (+0100) Subject: c-ares: fix/tidy-up macro initializations, avoid a deprecated function X-Git-Tag: curl-8_12_0~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=671e83f0b13e92538dd46f5c22b845516a2b58c9;p=thirdparty%2Fcurl.git c-ares: fix/tidy-up macro initializations, avoid a deprecated function - replace deprecated `ares_init()` call with `ares_init_options()`. Follow-up to 0d4fdbf15d8eec908b3e63b606f112b18a63015e #16054 - dedupe `CARES_STATICLIB` initalizations into `curl_setup.h`, to ensure it's defined before the first (and every) `ares.h` include and avoid a potential confusion. - move `CARES_NO_DEPRECATED` from build level to `curl_setup.h`. To work regardless of build system. It is necessary because curl calls `ares_getsock()` from two places, of which one feeds a chain of wrappers: `Curl_ares_getsock()`, `Curl_resolver_getsock()`, `Curl_resolv_getsock()`. Closes #16131 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a81ef41e1..30c0154be7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -352,7 +352,6 @@ if(ENABLE_ARES) if(CARES_CFLAGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CARES_CFLAGS}") endif() - add_definitions("-DCARES_NO_DEPRECATED") # Ignore c-ares deprecation warnings endif() include(CurlSymbolHiding) diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 44e009b11d..38dc729e04 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -62,10 +62,6 @@ #include "httpsrr.h" #include "strdup.h" -#if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \ - defined(_WIN32) -# define CARES_STATICLIB -#endif #include #include /* really old c-ares did not include this by itself */ diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c index 895efbc7b5..b8c304943d 100644 --- a/lib/asyn-thread.c +++ b/lib/asyn-thread.c @@ -429,7 +429,7 @@ static void destroy_async_data(struct Curl_async *async) static CURLcode resolve_httpsrr(struct Curl_easy *data, struct Curl_async *asp) { - int status = ares_init(&asp->tdata->channel); + int status = ares_init_options(&asp->tdata->channel, NULL, 0); if(status != ARES_SUCCESS) return CURLE_FAILED_INIT; diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 71326c35e6..cc1b7e55da 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -377,6 +377,15 @@ # endif #endif +#ifdef USE_ARES +# ifndef CARES_NO_DEPRECATED +# define CARES_NO_DEPRECATED /* for ares_getsock() */ +# endif +# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32) +# define CARES_STATICLIB /* define it before including ares.h */ +# endif +#endif + #ifdef USE_LWIPSOCK # include # include diff --git a/lib/version.c b/lib/version.c index 166fabd79c..6543dcd0bd 100644 --- a/lib/version.c +++ b/lib/version.c @@ -38,10 +38,6 @@ #include "easy_lock.h" #ifdef USE_ARES -# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \ - defined(_WIN32) -# define CARES_STATICLIB -# endif # include #endif diff --git a/m4/curl-confopts.m4 b/m4/curl-confopts.m4 index 7da8cb58be..dd23fc7c07 100644 --- a/m4/curl-confopts.m4 +++ b/m4/curl-confopts.m4 @@ -532,7 +532,6 @@ AC_DEFUN([CURL_CHECK_LIB_ARES], [ if test "$want_ares" = "yes"; then dnl finally c-ares will be used AC_DEFINE(USE_ARES, 1, [Define to enable c-ares support]) - AC_DEFINE(CARES_NO_DEPRECATED, 1, [Ignore c-ares deprecation warnings]) USE_ARES=1 LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE libcares" curl_res_msg="c-ares"