curl/lib/memdebug.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

212 lines
8.0 KiB
C
Raw Normal View History

#ifndef HEADER_CURL_MEMDEBUG_H
#define HEADER_CURL_MEMDEBUG_H
#ifdef CURLDEBUG
2002-09-03 19:52:59 +08:00
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
2002-03-19 15:54:55 +08:00
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
2002-03-19 15:54:55 +08:00
*
2002-09-03 19:52:59 +08:00
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
2020-11-04 21:02:01 +08:00
* are also available at https://curl.se/docs/copyright.html.
*
2002-03-19 15:54:55 +08:00
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
2002-09-03 19:52:59 +08:00
* furnished to do so, under the terms of the COPYING file.
2002-03-19 15:54:55 +08:00
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
2002-09-03 19:52:59 +08:00
***************************************************************************/
/*
* CAUTION: this header is designed to work when included by the app-side
* as well as the library. Do not mix with library internals!
*/
#include <curl/curl.h>
#include "functypes.h"
#if defined(__GNUC__) && __GNUC__ >= 3
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
# define ALLOC_FUNC __attribute__((__malloc__))
# define ALLOC_SIZE(s) __attribute__((__alloc_size__(s)))
# define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s)))
#elif defined(_MSC_VER)
# define ALLOC_FUNC __declspec(restrict)
# define ALLOC_SIZE(s)
# define ALLOC_SIZE2(n, s)
#else
# define ALLOC_FUNC
# define ALLOC_SIZE(s)
# define ALLOC_SIZE2(n, s)
#endif
#define CURL_MT_LOGFNAME_BUFSIZE 512
extern FILE *curl_dbg_logfile;
2001-10-04 21:25:12 +08:00
/* memory functions */
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1) void *curl_dbg_malloc(size_t size,
int line,
const char *source);
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2) void *curl_dbg_calloc(size_t elements,
size_t size, int line, const char *source);
CURL_EXTERN ALLOC_SIZE(2) void *curl_dbg_realloc(void *ptr,
size_t size,
int line,
const char *source);
CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
CURL_EXTERN ALLOC_FUNC char *curl_dbg_strdup(const char *str, int line,
const char *src);
#if defined(_WIN32) && defined(UNICODE)
CURL_EXTERN ALLOC_FUNC wchar_t *curl_dbg_wcsdup(const wchar_t *str,
int line,
const char *source);
#endif
CURL_EXTERN void curl_dbg_memdebug(const char *logname);
CURL_EXTERN void curl_dbg_memlimit(long limit);
build: enable missing OpenSSF-recommended warnings, with fixes https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html as of 2023-11-29 [1]. Enable new recommended warnings (except `-Wsign-conversion`): - enable `-Wformat=2` for clang (in both cmake and autotools). - add `CURL_PRINTF()` internal attribute and mark functions accepting printf arguments with it. This is a copy of existing `CURL_TEMP_PRINTF()` but using `__printf__` to make it compatible with redefinting the `printf` symbol: https://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_5.html#SEC94 - fix `CURL_PRINTF()` and existing `CURL_TEMP_PRINTF()` for mingw-w64 and enable it on this platform. - enable `-Wimplicit-fallthrough`. - enable `-Wtrampolines`. - add `-Wsign-conversion` commented with a FIXME. - cmake: enable `-pedantic-errors` the way we do it with autotools. Follow-up to d5c0351055d5709da8f3e16c91348092fdb481aa #2747 - lib/curl_trc.h: use `CURL_FORMAT()`, this also fixes it to enable format checks. Previously it was always disabled due to the internal `printf` macro. Fix them: - fix bug where an `set_ipv6_v6only()` call was missed in builds with `--disable-verbose` / `CURL_DISABLE_VERBOSE_STRINGS=ON`. - add internal `FALLTHROUGH()` macro. - replace obsolete fall-through comments with `FALLTHROUGH()`. - fix fallthrough markups: Delete redundant ones (showing up as warnings in most cases). Add missing ones. Fix indentation. - silence `-Wformat-nonliteral` warnings with llvm/clang. - fix one `-Wformat-nonliteral` warning. - fix new `-Wformat` and `-Wformat-security` warnings. - fix `CURL_FORMAT_SOCKET_T` value for mingw-w64. Also move its definition to `lib/curl_setup.h` allowing use in `tests/server`. - lib: fix two wrongly passed string arguments in log outputs. Co-authored-by: Jay Satiro - fix new `-Wformat` warnings on mingw-w64. [1] https://github.com/ossf/wg-best-practices-os-developers/blob/56c0fde3895bfc55c8a973ef49a2572c507b2ae1/docs/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C%2B%2B.md Closes #12489
2023-12-08 21:05:09 +08:00
CURL_EXTERN void curl_dbg_log(const char *format, ...) CURL_PRINTF(1, 2);
2000-10-09 19:11:43 +08:00
/* file descriptor manipulators */
CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
int line, const char *source);
CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
2016-04-04 02:28:34 +08:00
int line, const char *source);
CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
2016-04-04 02:28:34 +08:00
int line, const char *source);
CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s, void *a, void *alen,
int line, const char *source);
#ifdef HAVE_SOCKETPAIR
CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
curl_socket_t socket_vector[2],
int line, const char *source);
#endif
/* send/receive sockets */
CURL_EXTERN SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
SEND_TYPE_ARG3 len,
SEND_TYPE_ARG4 flags, int line,
const char *source);
CURL_EXTERN RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd,
RECV_TYPE_ARG2 buf,
RECV_TYPE_ARG3 len,
RECV_TYPE_ARG4 flags, int line,
const char *source);
/* FILE functions */
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode,
int line, const char *source);
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
int line, const char *source);
CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
#ifndef MEMDEBUG_NODEFINES
2000-10-09 19:11:43 +08:00
/* Set this symbol on the command-line, recompile all lib-sources */
2002-10-29 03:20:59 +08:00
#undef strdup
#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef malloc
#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef calloc
#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef realloc
#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef free
#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef send
#define send(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__)
lib: fix AIX build issues - memdebug: replace keyword `malloc` with `__malloc__` to not interfere with envs where `malloc` is redefined. Also apply the fix to `alloc_size`. Fixes: ``` lib/memdebug.h:107:13: warning: unknown attribute 'vec_malloc' ignored [-Wunknown-attributes] CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, ^~~~~~~~~~ lib/memdebug.h:37:37: note: expanded from macro 'ALLOC_FUNC' # define ALLOC_FUNC __attribute__((malloc)) ^~~~~~ /usr/include/stdlib.h:753:16: note: expanded from macro 'malloc' #define malloc vec_malloc ^~~~~~~~~~ ``` - memdebug: always undef before defining. Also do this for the rest of functions redefined in the same block. Avoids warning on AIX: ``` lib/memdebug.h:117:9: warning: 'malloc' macro redefined [-Wmacro-redefined] #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) ^ /usr/include/stdlib.h:753:9: note: previous definition is here #define malloc vec_malloc ^ ``` - easy: fix `-Wformat` warning on AIX by adding a cast. ``` lib/easy.c:608:47: warning: format specifies type 'int' but the argument has type 'long' [-Wformat] "%" CURL_FORMAT_SOCKET_T ")", fds[i].fd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~ ``` - if2ip: silence compiler warning inside AIX system header. ``` /lib/if2ip.c:219:19: warning: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Wshift-sign-overflow] if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { ^~~~~~~~~~~ /usr/include/sys/ioctl.h:401:26: note: expanded from macro 'SIOCGIFADDR' #define SIOCGIFADDR (int)_IOWR('i',33, struct oifreq) /* get ifnet address */ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/sys/ioctl.h:174:23: note: expanded from macro '_IOWR' #define _IOWR(x,y,t) (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y) ^~~~~~~~~ /usr/include/sys/ioctl.h:168:20: note: expanded from macro 'IOC_INOUT' #define IOC_INOUT (IOC_IN|IOC_OUT) ^~~~~~ /usr/include/sys/ioctl.h:167:28: note: expanded from macro 'IOC_IN' #define IOC_IN (0x40000000<<1) /* copy in parameters */ ~~~~~~~~~~^ ~ ``` Ref: https://curl.se/dev/log.cgi?id=20240808180420-3809007 Assisted-by: Dan Fandrich Closes #14464
2024-08-09 04:31:24 +08:00
#undef recv
#define recv(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__)
#ifdef _WIN32
# ifdef UNICODE
# undef wcsdup
# define wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _wcsdup
# define _wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _tcsdup
# define _tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# else
# undef _tcsdup
# define _tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
# endif
#endif
#undef socket
#define socket(domain,type,protocol)\
curl_dbg_socket((int)domain, type, protocol, __LINE__, __FILE__)
#undef accept /* for those with accept as a macro */
2000-12-19 00:13:37 +08:00
#define accept(sock,addr,len)\
curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
#ifdef HAVE_SOCKETPAIR
#define socketpair(domain,type,protocol,socket_vector)\
curl_dbg_socketpair((int)domain, type, protocol, socket_vector, \
__LINE__, __FILE__)
#endif
cmake: allow building tests in unity mode Makes building tests noticeably faster. Apply changes/fixes/workarounds to make Unity work: - rename test variables to avoid collisions or shadowing each other when combined into single units. - add workaround to avoid applying `lib/memdebug.h` overrides to system headers declaring/defining `getaddrinfo()`/`freeaddrinfo()` for `tests/server/resolve.c`. This replaces a previous workaround that worked for that specific source. - rename test macro `CTRL` clashing with Cygwin `sys/ioctl.h`. - add include guard to `test.h`. Also: - exclude `tests/http/clients` which are all single-source. (like `docs/examples`.) Build time improvements for tests: - AppVeyor CI: - MSVC 2008, 2010: 1 minute faster (4m8s -> 2m56s, 3m19s -> 2m24s) - MSVC 2022 arm64: 3.5 minutes faster (10m18s -> 6m48s) before: https://ci.appveyor.com/project/curlorg/curl/builds/50522785 after: https://ci.appveyor.com/project/curlorg/curl/builds/50522942 - GHA: - Cygwin: 1.5 minutes faster (3m13s -> 1m43s) before: https://github.com/curl/curl/actions/runs/10681535327/job/29605384398 after: https://github.com/curl/curl/actions/runs/10680818726/job/29603130637 - Windows: before: https://github.com/curl/curl/actions/runs/10680818713 after: https://github.com/curl/curl/actions/runs/10683850187 - MSYS2, mingw-w64: 1 minute faster - MSVC: 30 seconds faster (3m17s -> 2m48s) - macOS: double speed (39s -> 18s) before: https://github.com/curl/curl/actions/runs/10680818753/job/29603133447 after: https://github.com/curl/curl/actions/runs/10683850174/job/29612914515 - Linux: almost double speed (30/31s -> 18s) before: https://github.com/curl/curl/actions/runs/10681535311/job/29605387156 after: https://github.com/curl/curl/actions/runs/10680818721/job/29603133976 - non-native: no obvious effect. before: https://github.com/curl/curl/actions/runs/10680818722 after: https://github.com/curl/curl/actions/runs/10683850187 - Old Linux: Unity mode not supported by old CMake, no effect. Closes #14765
2024-09-03 06:26:26 +08:00
#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
2005-11-14 07:53:14 +08:00
#undef getaddrinfo
2001-10-04 21:25:12 +08:00
#define getaddrinfo(host,serv,hint,res) \
curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
#endif
#endif /* HAVE_GETADDRINFO */
#ifdef HAVE_FREEADDRINFO
2005-11-14 07:53:14 +08:00
#undef freeaddrinfo
2001-10-04 21:25:12 +08:00
#define freeaddrinfo(data) \
curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
#endif /* HAVE_FREEADDRINFO */
#endif /* !CURL_NO_GETADDRINFO_OVERRIDE */
2001-10-04 21:25:12 +08:00
/* sclose is probably already defined, redefine it! */
#undef sclose
#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd,__LINE__,__FILE__)
#undef fopen
#define fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
#undef fdopen
#define fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
#define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
#endif /* MEMDEBUG_NODEFINES */
#endif /* CURLDEBUG */
/*
** Following section applies even when CURLDEBUG is not defined.
*/
#ifndef fake_sclose
2011-09-03 22:06:10 +08:00
#define fake_sclose(x) Curl_nop_stmt
#endif
/*
* Curl_safefree defined as a macro to allow MemoryTracking feature
* to log free() calls at same location where Curl_safefree is used.
* This macro also assigns NULL to given pointer when free'd.
*/
#define Curl_safefree(ptr) \
do { free((ptr)); (ptr) = NULL;} while(0)
#endif /* HEADER_CURL_MEMDEBUG_H */