mirror of
https://github.com/curl/curl.git
synced 2026-04-13 00:31:41 +08:00
Fixing:
- HTTPS-RR builds with c-ares and Linux MUSL.
- curl-for-win minimal builds with Linux MUSL.
It should fix all other kinds of entaglement between curl's redefintions
of system symbols and system (or 3rd-party) headers sensitive to that.
It also syncs memory override behavior between unity & non-unity builds,
thus reducing build variations.
The idea is to define and declare everything once in `curl_setup.h`,
without overriding any system symbols with curl ones yet. Then, like
before this patch, override them, if necessary, in each source file via
`curl_memory.h` and `memdebug.h`, after including system headers.
To ensure a clean slate with no overrides at the beginning of each
source file, reset all of them unconditionally at the end of
`curl_setup.h`, by including `curl_mem_undef.h`. (This assumes
`curl_setup.h` is always included first, which is already the case
throughout the codebase.)
`curl_mem_undef.h` can also be included explicitly wherever overrides
are causing problems. E.g. in tests which use unity-style builds and
a previously included `curl_memory.h`/`memdebug.h` can be spilling into
other source files.
The simplified role of the two override headers:
- `curl_memory.h`: overrides system memory allocator functions to
libcurl ones, when memory tracing (aka `CURLDEBUG`) is disabled.
- `memdebug.h`: overrides system memory allocator and some other
functions to curl debug functions, when memory tracing is enabled.
Changed made in this patch, step-by-step:
- curl_memory.h: move allocator typedefs and protos to `curl_setup.h`.
- memdebug.h: move `ALLOC_*` macros to `curl_setup.h`.
- memdebug.h: move allocator protos to `curl_setup.h`.
- memdebug.h: move `Curl_safefree()` macro to `curl_setup.h`.
(it's a regular macro, with a one-time, global, definition.)
- curl_memory.h: move system symbol undefs to a new, separate header:
`curl_mem_undef.h`.
- curl_setup.h: include `curl_mem_undef.h` at the end, unconditionally,
to reset system symbol macros after each inclusion.
- handle `sclose()` and `fake_sclose()` in `curl_setup.h`. They are not
system symbols, a one-time definition does the job.
Also:
- GHA/linux: enable unity mode for the HTTP-RR c-ares MUSL job.
Follow-up to 17ab4d62e6 #16413
That said, I'd still find it better to avoid redefining system macros.
To communicate clearly the fact that they are not the original system
calls and they do behave differently. And, it would allow dropping the
undef/redef dance in each source file, and maintaining the logic with
it. The "last #include files should be in this order" comments in each
source would also become unnecessary. Also the trick of using
`(func)` (or interim macros) to call the non-overridden function where
required. This method works for printf and most everything else already.
For `_tcsdup`, socket and fopen functions this could work without
disturbing the codebase much.
Ref: #16428 (clean reboot of)
Closes #17827
85 lines
3.0 KiB
C
85 lines
3.0 KiB
C
#ifndef HEADER_CURL_MEMDEBUG_H
|
|
#define HEADER_CURL_MEMDEBUG_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* 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
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
|
|
/*
|
|
* CAUTION: this header is designed to work when included by the app-side
|
|
* as well as the library. Do not mix with library internals!
|
|
*/
|
|
|
|
#ifdef CURLDEBUG
|
|
|
|
/* Set this symbol on the command-line, recompile all lib-sources */
|
|
#undef strdup
|
|
#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
|
|
#undef malloc
|
|
#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
|
|
#undef calloc
|
|
#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
|
|
#undef realloc
|
|
#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
|
|
#undef free
|
|
#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
|
|
#undef send
|
|
#define send(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__)
|
|
#undef recv
|
|
#define recv(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__)
|
|
|
|
#ifdef _WIN32
|
|
#undef _tcsdup
|
|
#ifdef UNICODE
|
|
#define _tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
|
|
#else
|
|
#define _tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
|
|
#endif
|
|
#endif /* _WIN32 */
|
|
|
|
#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 */
|
|
#define accept(sock,addr,len) \
|
|
curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
|
|
#ifdef HAVE_ACCEPT4
|
|
#undef accept4 /* for those with accept4 as a macro */
|
|
#define accept4(sock,addr,len,flags) \
|
|
curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__)
|
|
#endif
|
|
#ifdef HAVE_SOCKETPAIR
|
|
#define socketpair(domain,type,protocol,socket_vector) \
|
|
curl_dbg_socketpair((int)domain, type, protocol, socket_vector, \
|
|
__LINE__, __FILE__)
|
|
#endif
|
|
|
|
#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__)
|
|
#undef fclose
|
|
#define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
|
|
|
|
#endif /* CURLDEBUG */
|
|
#endif /* HEADER_CURL_MEMDEBUG_H */
|