curl-curl/scripts
Viktor Szakats 193cb00ce9
build: stop overriding standard memory allocation functions
Before this patch curl used the C preprocessor to override standard
memory allocation symbols: malloc, calloc, strdup, realloc, free.
The goal of these is to replace them with curl's debug wrappers in
`CURLDEBUG` builds, another was to replace them with the wrappers
calling user-defined allocators in libcurl. This solution needed a bunch
of workarounds to avoid breaking external headers: it relied on include
order to do the overriding last. For "unity" builds it needed to reset
overrides before external includes. Also in test apps, which are always
built as single source files. It also needed the `(symbol)` trick
to avoid overrides in some places. This would still not fix cases where
the standard symbols were macros. It was also fragile and difficult
to figure out which was the actual function behind an alloc or free call
in a specific piece of code. This in turn caused bugs where the wrong
allocator was accidentally called.

To avoid these problems, this patch replaces this solution with
`curlx_`-prefixed allocator macros, and mapping them _once_ to either
the libcurl wrappers, the debug wrappers or the standard ones, matching
the rest of the code in libtests.

This concludes the long journey to avoid redefining standard functions
in the curl codebase.

Note: I did not update `packages/OS400/*.c` sources. They did not
`#include` `curl_setup.h`, `curl_memory.h` or `memdebug.h`, meaning
the overrides were never applied to them. This may or may not have been
correct. For now I suppressed the direct use of standard allocators
via a local `.checksrc`. Probably they (except for `curlcl.c`) should be
updated to include `curl_setup.h` and use the `curlx_` macros.

This patch changes mappings in two places:
- `lib/curl_threads.c` in libtests: Before this patch it mapped to
  libcurl allocators. After, it maps to standard allocators, like
  the rest of libtests code.
- `units`: before this patch it mapped to standard allocators. After, it
  maps to libcurl allocators.

Also:
- drop all position-dependent `curl_memory.h` and `memdebug.h` includes,
  and delete the now unnecessary headers.
- rename `Curl_tcsdup` macro to `curlx_tcsdup` and define like the other
  allocators.
- map `curlx_strdup()` to `_strdup()` on Windows (was: `strdup()`).
  To fix warnings silenced via `_CRT_NONSTDC_NO_DEPRECATE`.
- multibyte: map `curlx_convert_*()` to `_strdup()` on Windows
  (was: `strdup()`).
- src: do not reuse the `strdup` name for the local replacement.
- lib509: call `_strdup()` on Windows (was: `strdup()`).
- test1132: delete test obsoleted by this patch.
- CHECKSRC.md: update text for `SNPRINTF`.
- checksrc: ban standard allocator symbols.

Follow-up to b12da22db1 #18866
Follow-up to db98daab05 #18844
Follow-up to 4deea9396b #18814
Follow-up to 9678ff5b1b #18776
Follow-up to 10bac43b87 #18774
Follow-up to 20142f5d06 #18634
Follow-up to bf7375ecc5 #18503
Follow-up to 9863599d69 #18502
Follow-up to 3bb5e58c10 #17827

Closes #19626
2025-11-28 10:44:26 +01:00
..
.checksrc REUSE: move copyright headers to .checksrc 2025-10-13 11:54:22 +02:00
cd2cd REUSE: bump reuse to v6, add more fences to fix issues 2025-10-06 20:54:26 +02:00
cd2nroff docs: spell it Rustls with a capital R 2025-11-26 09:41:09 +01:00
cdall badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
checksrc-all.pl checksrc-all: rewrite in Perl, remove checksrc.bat 2025-07-11 12:28:46 +02:00
checksrc.pl build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
ciconfig.pl badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
cijobs.pl scripts: enable strict warnings in Perl where missing, fix fallouts 2025-07-27 22:35:18 +02:00
cmakelint.sh badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
CMakeLists.txt cmake: install shell completions for cross-builds 2025-04-24 10:04:17 +02:00
completion.pl badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
contributors.sh contributors.sh: lowercase 'github' for consistency 2025-02-24 08:05:06 +01:00
contrithanks.sh contrithanks: fix for BSD sed tool 2025-07-28 17:29:26 +02:00
coverage.sh GHA: add shellcheck job and fix warnings, shell tidy-ups 2024-04-08 09:37:24 +00:00
delta delta: fix counters 2025-07-29 09:45:07 +02:00
dmaketgz dmaketgz: use --no-cache when building docker image 2024-12-05 15:41:53 +01:00
extract-unit-protos scripts: enable strict warnings in Perl where missing, fix fallouts 2025-07-27 22:35:18 +02:00
firefox-db2pem.sh firefox-db2pem.sh: add macOS support, tidy-ups 2025-10-16 20:53:28 +02:00
installcheck.sh GHA: add shellcheck job and fix warnings, shell tidy-ups 2024-04-08 09:37:24 +00:00
Makefile.am lib: stop overriding system printf symbols 2025-10-06 20:57:59 +02:00
maketgz scripts: use end-of-options marker in find -exec commands 2025-11-10 18:52:29 +01:00
managen manage: expand the 'libcurl support required' message 2025-11-24 23:35:00 +01:00
mdlinkcheck mk-ca-bundle.pl: use open() with argument list to replace backticks 2025-11-12 00:53:43 +01:00
mk-ca-bundle.pl badwords: add more contractions, fix fallouts 2025-11-17 19:29:15 +01:00
mk-unity.pl cmake: replace the way clang-tidy verifies tests, fix issues found 2025-06-22 23:08:46 +02:00
nroff2cd scripts: enable strict warnings in Perl where missing, fix fallouts 2025-07-27 22:35:18 +02:00
perlcheck.sh badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
pythonlint.sh scripts: move the ruff linter command into a script 2025-05-13 16:41:32 -07:00
randdisable spelling: file system 2025-08-22 15:53:41 +02:00
release-notes.pl badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
release-tools.sh badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
schemetable.c vssh: drop support for wolfSSH 2025-09-24 22:59:33 +02:00
singleuse.pl singleuse.pl: fix string warning 2025-10-28 11:34:19 +01:00
top-complexity badwords: fix issues found in scripts and other files 2025-11-17 17:18:07 +01:00
verify-release verify-release: update to avoid shellcheck warning SC2034 2025-11-10 16:06:48 +01:00
wcurl wcurl: import v2025.11.09 2025-11-10 08:52:55 +01:00