Skip to content

windows: fixup fopen() in CURLDEBUG builds #16747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Mar 17, 2025

Introduce an immutable CURL_FOPEN() macro to store the fopen()
mapping on Windows. Then use that instead (fopen) from memdebug.c.
It makes CURLDEBUG builds use the correct fopen wrapper on Windows.
This macro is only defined on Windows, as of this patch.

This is necessary after cde81e4,
which no longer applies the default fopen() override to memdebug.c.

Also:

  • curl_setup.h: de-dupe, simplify Windows file I/O function overrides.
  • curl_memory.h: fix to reset fopen to curlx_win32_fopen() on
    Windows. Before this patch it reset it to stock fopen().

Follow-up to cde81e4 #17631


w/o ws https://github.com/curl/curl/pull/16747/files?w=1

@testclutch

This comment was marked as outdated.

vszakats added a commit that referenced this pull request Jun 16, 2025
Before this patch `memdebug.c` was compiled as a separate source in
unity builds. This was necessary because `memdebug.c` failed to compile
if `memdebug.h` was included before it, in `CURLDEBUG` mode. This patch
fixes this issue and allows to compile `memdebug.c` as part of the unity
source batch. This removes an exception and makes builds perform a notch
better.

- introduce `CURL_SCLOSE()` macro as an immutable synonym of `sclose()`.
- memdebug: replace `sclose()` reference with `CURL_SCLOSE()` to compile
  as expected when `sclose()` is overridden by `memdebug.h`.
- memdebug: make it not break when including `memdebug.h` before it in
  `CURLDEBUG` mode. Do this by calling low-level functions as
  `(function)`.
- autotools, cmake: drop memdebug exception, include it like any other
  source file. This is now possible because `memdebug.c` doesn't break
  if `memdebug.h` was included before it, in `CURLDEBUG` builds.
- mk-unity: drop `--exclude` option. No longer used after this patch.
- drop `MEMDEBUG_NODEFINES` macro hack. No longer necessary.

Ref: #16747
Closes #16746
Closes #16738
Closes #17631
@vszakats vszakats marked this pull request as draft June 16, 2025 07:52
@vszakats vszakats changed the title tidy-up: fopen, sclose, fake_sclose macros tidy-up: fopen, fake_sclose macros Jun 16, 2025
@vszakats vszakats changed the title tidy-up: fopen, fake_sclose macros windows: fix fopen() in Unicode CURLDEBUG builds Jun 16, 2025
@vszakats vszakats added Windows Windows-specific build Unicode Unicode, code page, character encoding labels Jun 16, 2025
@vszakats vszakats changed the title windows: fix fopen() in Unicode CURLDEBUG builds windows: fix fopen() in CURLDEBUG builds Jun 16, 2025
@vszakats vszakats marked this pull request as ready for review June 16, 2025 08:47
@vszakats vszakats changed the title windows: fix fopen() in CURLDEBUG builds windows: fixup fopen() in CURLDEBUG builds Jun 16, 2025
@vszakats vszakats closed this in 6828009 Jun 16, 2025
@vszakats vszakats deleted the platmacros branch June 16, 2025 10:30
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
Before this patch `memdebug.c` was compiled as a separate source in
unity builds. This was necessary because `memdebug.c` failed to compile
if `memdebug.h` was included before it, in `CURLDEBUG` mode. This patch
fixes this issue and allows to compile `memdebug.c` as part of the unity
source batch. This removes an exception and makes builds perform a notch
better.

- introduce `CURL_SCLOSE()` macro as an immutable synonym of `sclose()`.
- memdebug: replace `sclose()` reference with `CURL_SCLOSE()` to compile
  as expected when `sclose()` is overridden by `memdebug.h`.
- memdebug: make it not break when including `memdebug.h` before it in
  `CURLDEBUG` mode. Do this by calling low-level functions as
  `(function)`.
- autotools, cmake: drop memdebug exception, include it like any other
  source file. This is now possible because `memdebug.c` doesn't break
  if `memdebug.h` was included before it, in `CURLDEBUG` builds.
- mk-unity: drop `--exclude` option. No longer used after this patch.
- drop `MEMDEBUG_NODEFINES` macro hack. No longer necessary.

Ref: curl#16747
Closes curl#16746
Closes curl#16738
Closes curl#17631
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
Introduce an immutable `CURL_FOPEN()` macro to store the `fopen()`
mapping on Windows. Then use that instead `(fopen)` from `memdebug.c`.
It makes CURLDEBUG builds use the correct `fopen` wrapper on Windows.
This macro is only defined on Windows, as of this patch.

This is necessary after cde81e4,
which no longer applies the default `fopen()` override to `memdebug.c`.

Also:
- curl_setup.h: de-dupe, simplify Windows file I/O function overrides.
- curl_memory.h: fix to reset `fopen` to `curlx_win32_fopen()` on
  Windows. Before this patch it reset it to stock `fopen()`.

Follow-up to cde81e4 curl#17631

Closes curl#16747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Unicode Unicode, code page, character encoding Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

2 participants