tidy-up: avoid (()), clang-format fixes and more

- drop redundant parentheses from macro definitions.
- apply clang-format in some places missed earlier.
- wolfssl: fix a macro guard comment.
- curl_setup.h: drop empty lines
- FAQ: fix C formatting.

Closes #19854
This commit is contained in:
Viktor Szakats 2025-12-04 22:48:20 +01:00
parent 4e051ff550
commit af5def0738
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
13 changed files with 404 additions and 374 deletions

View file

@ -1157,7 +1157,7 @@ FAQ
struct MemoryStruct *mem = (struct MemoryStruct *)data;
mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
if(mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;

View file

@ -48,9 +48,9 @@
#define CPOOL_IS_LOCKED(c) ((c) && (c)->locked)
#define CPOOL_LOCK(c,d) \
#define CPOOL_LOCK(c, d) \
do { \
if((c)) { \
if(c) { \
if(CURL_SHARE_KEEP_CONNECT((c)->share)) \
Curl_share_lock((d), CURL_LOCK_DATA_CONNECT, \
CURL_LOCK_ACCESS_SINGLE); \
@ -61,7 +61,7 @@
#define CPOOL_UNLOCK(c,d) \
do { \
if((c)) { \
if(c) { \
DEBUGASSERT((c)->locked); \
(c)->locked = FALSE; \
if(CURL_SHARE_KEEP_CONNECT((c)->share)) \

View file

@ -180,7 +180,6 @@
* AIX 4.3 and newer needs _THREAD_SAFE defined to build
* proper reentrant code. Others may also need it.
*/
#ifdef NEED_THREAD_SAFE
# ifndef _THREAD_SAFE
# define _THREAD_SAFE
@ -192,7 +191,6 @@
* things to appear in the system header files. Unixware needs it
* to build proper reentrant code. Others may also need it.
*/
#ifdef NEED_REENTRANT
# ifndef _REENTRANT
# define _REENTRANT
@ -219,7 +217,6 @@
/*
* Disable other protocols when http is the only one desired.
*/
#ifdef HTTP_ONLY
# ifndef CURL_DISABLE_DICT
# define CURL_DISABLE_DICT
@ -268,7 +265,6 @@
/*
* When http is disabled rtsp is not supported.
*/
#if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
# define CURL_DISABLE_RTSP
#endif
@ -276,7 +272,6 @@
/*
* When HTTP is disabled, disable HTTP-only features
*/
#ifdef CURL_DISABLE_HTTP
# define CURL_DISABLE_ALTSVC 1
# define CURL_DISABLE_COOKIES 1
@ -298,7 +293,6 @@
/*
* OS/400 setup file includes some system headers.
*/
#ifdef __OS400__
# include "setup-os400.h"
#endif
@ -306,7 +300,6 @@
/*
* VMS setup file includes some system headers.
*/
#ifdef __VMS
# include "setup-vms.h"
#endif
@ -314,7 +307,6 @@
/*
* Windows setup file includes some system headers.
*/
#ifdef _WIN32
# include "setup-win32.h"
#endif
@ -340,7 +332,6 @@
#endif
/* based on logic in "curl/mprintf.h" */
#if (defined(__GNUC__) || defined(__clang__) || \
defined(__IAR_SYSTEMS_ICC__)) && \
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
@ -612,10 +603,10 @@
#if SIZEOF_LONG > SIZEOF_SIZE_T
#error "unexpected: 'long' is larger than 'size_t'"
#endif
/*
* Arg 2 type for gethostname in case it has not been defined in config file.
*/
#ifndef GETHOSTNAME_TYPE_ARG2
# ifdef USE_WINSOCK
# define GETHOSTNAME_TYPE_ARG2 int
@ -625,10 +616,9 @@
#endif
/* Below we define some functions. They should
4. set the SIGALRM signal timeout
5. set dir/file naming defines
*/
*/
#ifdef _WIN32
@ -664,7 +654,6 @@
/*
* Mutually exclusive CURLRES_* definitions.
*/
#if defined(USE_IPV6) && defined(HAVE_GETADDRINFO)
# define CURLRES_IPV6
#elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
@ -792,7 +781,6 @@
/*
* Include macros and defines that should only be processed once.
*/
#ifndef HEADER_CURL_SETUP_ONCE_H
#include "curl_setup_once.h"
#endif
@ -800,7 +788,6 @@
/*
* Definition of our NOP statement Object-like macro
*/
#ifndef Curl_nop_stmt
#define Curl_nop_stmt do { } while(0)
#endif
@ -808,7 +795,6 @@
/*
* Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
*/
#if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
# if defined(SOCKET) || defined(USE_WINSOCK)
# error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
@ -818,7 +804,6 @@
/*
* shutdown() flags for systems that do not define them
*/
#ifndef SHUT_RD
#define SHUT_RD 0x00
#endif

View file

@ -181,15 +181,15 @@ struct timeval {
* Function-like macro definition used to close a socket.
*/
#ifdef HAVE_CLOSESOCKET
# define CURL_SCLOSE(x) closesocket((x))
# define CURL_SCLOSE(x) closesocket(x)
#elif defined(HAVE_CLOSESOCKET_CAMEL)
# define CURL_SCLOSE(x) CloseSocket((x))
# define CURL_SCLOSE(x) CloseSocket(x)
#elif defined(MSDOS) /* Watt-32 */
# define CURL_SCLOSE(x) close_s((x))
# define CURL_SCLOSE(x) close_s(x)
#elif defined(USE_LWIPSOCK)
# define CURL_SCLOSE(x) lwip_close((x))
# define CURL_SCLOSE(x) lwip_close(x)
#else
# define CURL_SCLOSE(x) close((x))
# define CURL_SCLOSE(x) close(x)
#endif
/*

View file

@ -39,12 +39,13 @@ const char Curl_base64encdec[] =
static const char base64url[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
static const unsigned char decodetable[] =
{ 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255,
255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51 };
static const unsigned char decodetable[] = {
62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255,
255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
};
/*
* curlx_base64_decode()
*

View file

@ -45,8 +45,8 @@
wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8);
char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w);
#define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr))
#define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr))
#define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar(ptr)
#define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8(ptr)
typedef union {
unsigned short *tchar_ptr;

View file

@ -45,7 +45,7 @@ struct Curl_str {
void curlx_str_init(struct Curl_str *out);
void curlx_str_assign(struct Curl_str *out, const char *str, size_t len);
#define curlx_str(x) ((x)->str)
#define curlx_str(x) ((x)->str)
#define curlx_strlen(x) ((x)->len)
/* Get a word until the first space

View file

@ -1515,7 +1515,7 @@ static CURLcode wssl_connect_step1(struct Curl_cfilter *cf,
wolfSSL_BIO_set_data(bio, cf);
wolfSSL_set_bio(wssl->ssl, bio, bio);
}
#else /* USE_BIO_CHAIN */
#else /* !USE_BIO_CHAIN */
curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data);
if(sockfd > INT_MAX) {
failf(data, "SSL: socket value too large");
@ -1526,7 +1526,7 @@ static CURLcode wssl_connect_step1(struct Curl_cfilter *cf,
failf(data, "SSL: wolfSSL_set_fd failed");
return CURLE_SSL_CONNECT_ERROR;
}
#endif /* !USE_BIO_CHAIN */
#endif /* USE_BIO_CHAIN */
return CURLE_OK;
}

View file

@ -29,7 +29,7 @@
char *tool_basename(char *path);
#define basename(x) tool_basename((x))
#define basename(x) tool_basename(x)
#endif /* HAVE_BASENAME */

View file

@ -31,7 +31,7 @@
#include "tool_msgs.h"
#if defined(_WIN32) || (defined(MSDOS) && !defined(__DJGPP__))
# define mkdir(x, y) (mkdir)((x))
# define mkdir(x, y) (mkdir)(x)
# ifndef F_OK
# define F_OK 0
# endif

View file

@ -381,15 +381,15 @@ ParameterError parse_args(int argc, argv_item_t argv[]);
#if defined(UNICODE) && defined(_WIN32)
#define convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr))
#define convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr))
#define convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar(ptr)
#define convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8(ptr)
#define unicodefree(ptr) curlx_free(ptr)
#else
#define convert_UTF8_to_tchar(ptr) (const char *)(ptr)
#define convert_tchar_to_UTF8(ptr) (const char *)(ptr)
#define unicodefree(ptr) do {} while(0)
#define unicodefree(ptr) do {} while(0)
#endif

View file

@ -59,12 +59,12 @@ extern int unitfail; /* for unittests */
#define CURL_GNUC_DIAG
#endif
#define test_setopt(A, B, C) \
if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) \
#define test_setopt(A, B, C) \
if((res = curl_easy_setopt(A, B, C)) != CURLE_OK) \
goto test_cleanup
#define test_multi_setopt(A, B, C) \
if((res = curl_multi_setopt((A), (B), (C))) != CURLE_OK) \
#define test_multi_setopt(A, B, C) \
if((res = curl_multi_setopt(A, B, C)) != CURLE_OK) \
goto test_cleanup
extern const char *libtest_arg2; /* set by first.c to the argv[2] or NULL */
@ -144,376 +144,419 @@ void ws_close(CURL *curl);
/* ---------------------------------------------------------------- */
#define exe_easy_init(A, Y, Z) do { \
if(((A) = curl_easy_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
res = TEST_ERR_EASY_INIT; \
} \
} while(0)
#define exe_easy_init(A, Y, Z) \
do { \
if(((A) = curl_easy_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_easy_init() failed\n", Y, Z); \
res = TEST_ERR_EASY_INIT; \
} \
} while(0)
#define res_easy_init(A) \
exe_easy_init((A), (__FILE__), (__LINE__))
exe_easy_init(A, __FILE__, __LINE__)
#define chk_easy_init(A, Y, Z) do { \
exe_easy_init((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define chk_easy_init(A, Y, Z) \
do { \
exe_easy_init(A, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define easy_init(A) \
chk_easy_init((A), (__FILE__), (__LINE__))
chk_easy_init(A, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_init(A, Y, Z) do { \
if(((A) = curl_multi_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define exe_multi_init(A, Y, Z) \
do { \
if(((A) = curl_multi_init()) == NULL) { \
curl_mfprintf(stderr, "%s:%d curl_multi_init() failed\n", Y, Z); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_init(A) \
exe_multi_init((A), (__FILE__), (__LINE__))
exe_multi_init(A, __FILE__, __LINE__)
#define chk_multi_init(A, Y, Z) do { \
exe_multi_init((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define chk_multi_init(A, Y, Z) \
do { \
exe_multi_init(A, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_init(A) \
chk_multi_init((A), (__FILE__), (__LINE__))
chk_multi_init(A, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_easy_setopt(A, B, C, Y, Z) do { \
CURLcode ec; \
if((ec = curl_easy_setopt((A), (B), (C))) != CURLE_OK) { \
curl_mfprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define exe_easy_setopt(A, B, C, Y, Z) \
do { \
CURLcode ec; \
if((ec = curl_easy_setopt(A, B, C)) != CURLE_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_easy_setopt() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define res_easy_setopt(A, B, C) \
exe_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
exe_easy_setopt(A, B, C, __FILE__, __LINE__)
#define chk_easy_setopt(A, B, C, Y, Z) do { \
exe_easy_setopt((A), (B), (C), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define chk_easy_setopt(A, B, C, Y, Z) \
do { \
exe_easy_setopt(A, B, C, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define easy_setopt(A, B, C) \
chk_easy_setopt((A), (B), (C), (__FILE__), (__LINE__))
chk_easy_setopt(A, B, C, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_setopt(A, B, C, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_setopt((A), (B), (C))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define exe_multi_setopt(A, B, C, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_setopt(A, B, C)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_setopt() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_setopt(A, B, C) \
exe_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
exe_multi_setopt(A, B, C, __FILE__, __LINE__)
#define chk_multi_setopt(A, B, C, Y, Z) do { \
exe_multi_setopt((A), (B), (C), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_setopt(A, B, C) \
chk_multi_setopt((A), (B), (C), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_add_handle(A, B, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_add_handle((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_add_handle(A, B) \
exe_multi_add_handle((A), (B), (__FILE__), (__LINE__))
#define chk_multi_add_handle(A, B, Y, Z) do { \
exe_multi_add_handle((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_add_handle(A, B) \
chk_multi_add_handle((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_remove_handle(A, B, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_remove_handle((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_remove_handle() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_remove_handle(A, B) \
exe_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
#define chk_multi_remove_handle(A, B, Y, Z) do { \
exe_multi_remove_handle((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_remove_handle(A, B) \
chk_multi_remove_handle((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_perform(A, B, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_perform((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_perform() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((B)) < 0) { \
curl_mfprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \
"but returned invalid running_handles value (%d)\n", \
(Y), (Z), (int)*((B))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_perform(A, B) \
exe_multi_perform((A), (B), (__FILE__), (__LINE__))
#define chk_multi_perform(A, B, Y, Z) do { \
exe_multi_perform((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_perform(A, B) \
chk_multi_perform((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_fdset(A, B, C, D, E, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_fdset((A), (B), (C), (D), (E))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_fdset() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((E)) < -1) { \
curl_mfprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \
"but returned invalid max_fd value (%d)\n", \
(Y), (Z), (int)*((E))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_fdset(A, B, C, D, E) \
exe_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_multi_fdset(A, B, C, D, E, Y, Z) do { \
exe_multi_fdset((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_fdset(A, B, C, D, E) \
chk_multi_fdset((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_timeout(A, B, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_timeout((A), (B))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_timeout() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
else if(*((B)) < -1L) { \
curl_mfprintf(stderr, "%s:%d curl_multi_timeout() succeeded, " \
"but returned invalid timeout value (%ld)\n", \
(Y), (Z), (long)*((B))); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
} while(0)
#define res_multi_timeout(A, B) \
exe_multi_timeout((A), (B), (__FILE__), (__LINE__))
#define chk_multi_timeout(A, B, Y, Z) do { \
exe_multi_timeout((A), (B), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_timeout(A, B) \
chk_multi_timeout((A), (B), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_poll(A, B, C, D, E, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_poll((A), (B), (C), (D), (E))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_poll() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*((E)) < 0) { \
curl_mfprintf(stderr, "%s:%d curl_multi_poll() succeeded, " \
"but returned invalid numfds value (%d)\n", \
(Y), (Z), (int)*((E))); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_poll(A, B, C, D, E) \
exe_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_multi_poll(A, B, C, D, E, Y, Z) do { \
exe_multi_poll((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_poll(A, B, C, D, E) \
chk_multi_poll((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_multi_wakeup(A, Y, Z) do { \
CURLMcode ec; \
if((ec = curl_multi_wakeup((A))) != CURLM_OK) { \
curl_mfprintf(stderr, "%s:%d curl_multi_wakeup() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_wakeup(A) \
exe_multi_wakeup((A), (__FILE__), (__LINE__))
#define chk_multi_wakeup(A, Y, Z) do { \
exe_multi_wakeup((A), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_wakeup(A) \
chk_multi_wakeup((A), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define exe_select_test(A, B, C, D, E, Y, Z) do { \
int ec; \
if(select_wrapper((A), (B), (C), (D), (E)) == -1) { \
char ecbuf[STRERROR_LEN]; \
ec = SOCKERRNO; \
curl_mfprintf(stderr, "%s:%d select() failed, with " \
"errno %d (%s)\n", \
(Y), (Z), \
ec, curlx_strerror(ec, ecbuf, sizeof(ecbuf))); \
res = TEST_ERR_SELECT; \
} \
} while(0)
#define res_select_test(A, B, C, D, E) \
exe_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
#define chk_select_test(A, B, C, D, E, Y, Z) do { \
exe_select_test((A), (B), (C), (D), (E), (Y), (Z)); \
if(res) \
goto test_cleanup; \
} while(0)
#define select_test(A, B, C, D, E) \
chk_select_test((A), (B), (C), (D), (E), (__FILE__), (__LINE__))
/* ---------------------------------------------------------------- */
#define start_test_timing() do { \
tv_test_start = curlx_now(); \
} while(0)
#define TEST_HANG_TIMEOUT 60 * 1000 /* global default */
#define exe_test_timedout(T, Y, Z) do { \
timediff_t timediff = curlx_timediff_ms(curlx_now(), tv_test_start); \
if(timediff > (T)) { \
curl_mfprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
"that it would have run forever (%ld ms > %ld ms)\n", \
(Y), (Z), (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
res = TEST_ERR_RUNS_FOREVER; \
} \
} while(0)
#define res_test_timedout() \
exe_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
#define res_test_timedout_custom(T) \
exe_test_timedout((T), (__FILE__), (__LINE__))
#define chk_test_timedout(T, Y, Z) do { \
exe_test_timedout(T, Y, Z); \
#define chk_multi_setopt(A, B, C, Y, Z) \
do { \
exe_multi_setopt(A, B, C, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define abort_on_test_timeout() \
chk_test_timedout(TEST_HANG_TIMEOUT, (__FILE__), (__LINE__))
#define abort_on_test_timeout_custom(T) \
chk_test_timedout((T), (__FILE__), (__LINE__))
#define multi_setopt(A, B, C) \
chk_multi_setopt(A, B, C, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_global_init(A, Y, Z) do { \
CURLcode ec; \
if((ec = curl_global_init((A))) != CURLE_OK) { \
curl_mfprintf(stderr, "%s:%d curl_global_init() failed, " \
"with code %d (%s)\n", \
(Y), (Z), ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define exe_multi_add_handle(A, B, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_add_handle(A, B)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_add_handle() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_add_handle(A, B) \
exe_multi_add_handle(A, B, __FILE__, __LINE__)
#define chk_multi_add_handle(A, B, Y, Z) \
do { \
exe_multi_add_handle(A, B, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_add_handle(A, B) \
chk_multi_add_handle(A, B, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_remove_handle(A, B, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_remove_handle(A, B)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_remove_handle() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_remove_handle(A, B) \
exe_multi_remove_handle(A, B, __FILE__, __LINE__)
#define chk_multi_remove_handle(A, B, Y, Z) \
do { \
exe_multi_remove_handle(A, B, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_remove_handle(A, B) \
chk_multi_remove_handle(A, B, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_perform(A, B, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_perform(A, B)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_perform() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*(B) < 0) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_perform() succeeded, " \
"but returned invalid running_handles value (%d)\n", \
Y, Z, (int)*(B)); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_perform(A, B) \
exe_multi_perform(A, B, __FILE__, __LINE__)
#define chk_multi_perform(A, B, Y, Z) \
do { \
exe_multi_perform(A, B, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_perform(A, B) \
chk_multi_perform(A, B, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_fdset(A, B, C, D, E, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_fdset(A, B, C, D, E)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_fdset() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*(E) < -1) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_fdset() succeeded, " \
"but returned invalid max_fd value (%d)\n", \
Y, Z, (int)*(E)); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_fdset(A, B, C, D, E) \
exe_multi_fdset(A, B, C, D, E, __FILE__, __LINE__)
#define chk_multi_fdset(A, B, C, D, E, Y, Z) \
do { \
exe_multi_fdset(A, B, C, D, E, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_fdset(A, B, C, D, E) \
chk_multi_fdset(A, B, C, D, E, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_timeout(A, B, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_timeout(A, B)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_timeout() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
else if(*(B) < -1L) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_timeout() succeeded, " \
"but returned invalid timeout value (%ld)\n", \
Y, Z, (long)*(B)); \
res = TEST_ERR_BAD_TIMEOUT; \
} \
} while(0)
#define res_multi_timeout(A, B) \
exe_multi_timeout(A, B, __FILE__, __LINE__)
#define chk_multi_timeout(A, B, Y, Z) \
do { \
exe_multi_timeout(A, B, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_timeout(A, B) \
chk_multi_timeout(A, B, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_poll(A, B, C, D, E, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_poll(A, B, C, D, E)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_poll() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
else if(*(E) < 0) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_poll() succeeded, " \
"but returned invalid numfds value (%d)\n", \
Y, Z, (int)*(E)); \
res = TEST_ERR_NUM_HANDLES; \
} \
} while(0)
#define res_multi_poll(A, B, C, D, E) \
exe_multi_poll(A, B, C, D, E, __FILE__, __LINE__)
#define chk_multi_poll(A, B, C, D, E, Y, Z) \
do { \
exe_multi_poll(A, B, C, D, E, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_poll(A, B, C, D, E) \
chk_multi_poll(A, B, C, D, E, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_multi_wakeup(A, Y, Z) \
do { \
CURLMcode ec; \
if((ec = curl_multi_wakeup(A)) != CURLM_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_multi_wakeup() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_multi_strerror(ec)); \
res = TEST_ERR_MULTI; \
} \
} while(0)
#define res_multi_wakeup(A) \
exe_multi_wakeup(A, __FILE__, __LINE__)
#define chk_multi_wakeup(A, Y, Z) \
do { \
exe_multi_wakeup(A, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define multi_wakeup(A) \
chk_multi_wakeup(A, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_select_test(A, B, C, D, E, Y, Z) \
do { \
int ec; \
if(select_wrapper(A, B, C, D, E) == -1) { \
char ecbuf[STRERROR_LEN]; \
ec = SOCKERRNO; \
curl_mfprintf(stderr, \
"%s:%d select() failed, with " \
"errno %d (%s)\n", \
Y, Z, ec, curlx_strerror(ec, ecbuf, sizeof(ecbuf))); \
res = TEST_ERR_SELECT; \
} \
} while(0)
#define res_select_test(A, B, C, D, E) \
exe_select_test(A, B, C, D, E, __FILE__, __LINE__)
#define chk_select_test(A, B, C, D, E, Y, Z) \
do { \
exe_select_test(A, B, C, D, E, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define select_test(A, B, C, D, E) \
chk_select_test(A, B, C, D, E, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define start_test_timing() \
do { \
tv_test_start = curlx_now(); \
} while(0)
#define TEST_HANG_TIMEOUT 60 * 1000 /* global default */
#define exe_test_timedout(T, Y, Z) \
do { \
timediff_t timediff = curlx_timediff_ms(curlx_now(), tv_test_start); \
if(timediff > (T)) { \
curl_mfprintf(stderr, \
"%s:%d ABORTING TEST, since it seems " \
"that it would have run forever (%ld ms > %ld ms)\n", \
Y, Z, (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
res = TEST_ERR_RUNS_FOREVER; \
} \
} while(0)
#define res_test_timedout() \
exe_test_timedout(TEST_HANG_TIMEOUT, __FILE__, __LINE__)
#define res_test_timedout_custom(T) \
exe_test_timedout(T, __FILE__, __LINE__)
#define chk_test_timedout(T, Y, Z) \
do { \
exe_test_timedout(T, Y, Z); \
if(res) \
goto test_cleanup; \
} while(0)
#define abort_on_test_timeout() \
chk_test_timedout(TEST_HANG_TIMEOUT, __FILE__, __LINE__)
#define abort_on_test_timeout_custom(T) \
chk_test_timedout(T, __FILE__, __LINE__)
/* ---------------------------------------------------------------- */
#define exe_global_init(A, Y, Z) \
do { \
CURLcode ec; \
if((ec = curl_global_init(A)) != CURLE_OK) { \
curl_mfprintf(stderr, \
"%s:%d curl_global_init() failed, " \
"with code %d (%s)\n", \
Y, Z, ec, curl_easy_strerror(ec)); \
res = ec; \
} \
} while(0)
#define res_global_init(A) \
exe_global_init((A), (__FILE__), (__LINE__))
exe_global_init(A, __FILE__, __LINE__)
#define chk_global_init(A, Y, Z) do { \
exe_global_init((A), (Y), (Z)); \
if(res) \
return res; \
#define chk_global_init(A, Y, Z) \
do { \
exe_global_init(A, Y, Z); \
if(res) \
return res; \
} while(0)
/* global_init() is different than other macros. In case of
failure it 'return's instead of going to 'test_cleanup'. */
#define global_init(A) \
chk_global_init((A), (__FILE__), (__LINE__))
chk_global_init(A, __FILE__, __LINE__)
#define NO_SUPPORT_BUILT_IN \
{ \

View file

@ -56,7 +56,8 @@
/* fail() is for when the test case figured out by itself that a check
proved a failure */
#define fail(msg) do { \
#define fail(msg) \
do { \
curl_mfprintf(stderr, "%s:%d test FAILED: '%s'\n", \
__FILE__, __LINE__, msg); \
unitfail++; \