From 211bfefbaa7c709ef8dc368720dd363316982e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 27 May 2021 13:38:21 +0200 Subject: [PATCH] Use UV_VERSION_HEX to decide whether we need libuv shim functions Instead of having a configure check for every missing function that has been added in later version of libuv, we now use UV_VERSION_HEX to decide whether we need the shim or not. --- config.h.win32 | 18 -------------- lib/isc/netmgr/uv-compat.c | 4 ++-- lib/isc/netmgr/uv-compat.h | 48 ++++++++++++++++---------------------- 3 files changed, 22 insertions(+), 48 deletions(-) diff --git a/config.h.win32 b/config.h.win32 index 6ebb165b5c..16aab18194 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -378,24 +378,6 @@ typedef __int64 off_t; /* Define to 1 if you have the `SSL_CTX_up_ref' function. */ #define SSL_CTX_UP_REF 1 -/* Define to 1 if you have the `uv_handle_get_data' function. */ -#define HAVE_UV_HANDLE_GET_DATA 1 - -/* Define to 1 if you have the `uv_handle_set_data' function. */ -#define HAVE_UV_HANDLE_SET_DATA 1 - -/* Define to 1 if you have the `uv_os_getenv' function. */ -#define HAVE_UV_OS_GETENV 1 - -/* Define to 1 if you have the `uv_os_setenv' function. */ -#define HAVE_UV_OS_SETENV 1 - -/* Define to 1 if you have the `uv_req_get_data' function. */ -#define HAVE_UV_REQ_GET_DATA 1 - -/* Define to 1 if you have the `uv_req_set_data' function. */ -#define HAVE_UV_REQ_SET_DATA 1 - /* GSSAPI Related defines */ @HAVE_GSSAPI@ @HAVE_GSSAPI_H@ diff --git a/lib/isc/netmgr/uv-compat.c b/lib/isc/netmgr/uv-compat.c index a0e1add2d7..89d7ac025c 100644 --- a/lib/isc/netmgr/uv-compat.c +++ b/lib/isc/netmgr/uv-compat.c @@ -16,7 +16,7 @@ #include "netmgr-int.h" -#ifndef HAVE_UV_UDP_CONNECT +#if UV_VERSION_HEX < UV_VERSION(1, 27, 0) int isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr) { int err = 0; @@ -46,7 +46,7 @@ isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr) { return (0); } -#endif /* ifndef HAVE_UV_UDP_CONNECT */ +#endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ int isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr, diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/netmgr/uv-compat.h index 2020689c71..c7037353f5 100644 --- a/lib/isc/netmgr/uv-compat.h +++ b/lib/isc/netmgr/uv-compat.h @@ -19,43 +19,49 @@ * library version. */ -#ifndef HAVE_UV_HANDLE_GET_DATA +#define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) + +#if UV_VERSION_HEX < UV_VERSION(1, 19, 0) static inline void * uv_handle_get_data(const uv_handle_t *handle) { return (handle->data); } -#endif /* ifndef HAVE_UV_HANDLE_GET_DATA */ -#ifndef HAVE_UV_HANDLE_SET_DATA static inline void uv_handle_set_data(uv_handle_t *handle, void *data) { handle->data = data; } -#endif /* ifndef HAVE_UV_HANDLE_SET_DATA */ -#ifndef HAVE_UV_REQ_GET_DATA static inline void * uv_req_get_data(const uv_req_t *req) { return (req->data); } -#endif /* ifndef HAVE_UV_REQ_GET_DATA */ -#ifndef HAVE_UV_REQ_SET_DATA static inline void uv_req_set_data(uv_req_t *req, void *data) { req->data = data; } -#endif /* ifndef HAVE_UV_REQ_SET_DATA */ +#endif /* UV_VERSION_HEX < UV_VERSION(1, 19, 0) */ -#ifndef HAVE_UV_SLEEP +#if UV_VERSION_HEX < UV_VERSION(1, 34, 0) #define uv_sleep(msec) usleep(msec * 1000) -#endif +#endif /* UV_VERSION_HEX < UV_VERSION(1, 34, 0) */ -#ifdef HAVE_UV_UDP_CONNECT +#if UV_VERSION_HEX < UV_VERSION(1, 27, 0) +int +isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr); +/*%< + * Associate the UDP handle to a remote address and port, so every message sent + * by this handle is automatically sent to that destination. + * + * NOTE: This is just a limited shim for uv_udp_connect() as it requires the + * handle to be bound. + */ +#else /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ #define isc_uv_udp_connect uv_udp_connect -#else +#endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ -#ifndef HAVE_UV_OS_GETENV +#if UV_VERSION_HEX < UV_VERSION(1, 12, 0) #include #include @@ -79,23 +85,9 @@ uv_os_getenv(const char *name, char *buffer, size_t *size) { return (0); } -#endif /* HAVE_UV_OS_GETENV */ -#ifndef HAVE_UV_OS_SETENV #define uv_os_setenv(name, value) setenv(name, value, 0) -#endif /* HAVE_UV_OS_SETENV */ - -int -isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr); -/*%< - * Associate the UDP handle to a remote address and port, so every message sent - * by this handle is automatically sent to that destination. - * - * NOTE: This is just a limited shim for uv_udp_connect() as it requires the - * handle to be bound. - */ - -#endif +#endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */ int isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr,