Native Windows support with Microsoft Windows Visual Studio (MSVC)#5890
Open
SamuelMarks wants to merge 7 commits into
Open
Native Windows support with Microsoft Windows Visual Studio (MSVC)#5890SamuelMarks wants to merge 7 commits into
SamuelMarks wants to merge 7 commits into
Conversation
This was referenced May 23, 2026
boquan-fang
reviewed
May 26, 2026
| * Runs _thecleanup function on _thealloc once _thealloc went out of scope | ||
| */ | ||
| #if defined(_MSC_VER) | ||
| #define DEFER_CLEANUP(_thealloc, _thecleanup) _thealloc |
Contributor
There was a problem hiding this comment.
I don't think disable DEFER_CLEANUP on Windows is the right decision. This macros is used to ensure that s2n-tls won't leak memory and all dynamically allocated memory are properly cleaned up.
Disabling DEFER_CLEANUP via zeroes on MSVC removes critical failsafe memory management that handles early returns across the codebase. Instead of forcing upstream macros to compile as C++ RAII or stripping them entirely, we implement a python AST-rewriting pass.
fix_defer_cleanup.py intercepts DEFER_CLEANUP calls during build setup. It copies the source files, parses the variable initialization and cleanup function, and dynamically wraps the remainder of the scope in a native MSVC \__try { ... } __finally { cleanup_fn(&var); }\ block.
CMakeLists.txt is then patched to source these rewritten C files, ensuring perfect runtime safety without modifying any original code.
Includes fix for conditionally compiled DEFER_CLEANUP scopes and vcpkg.json baseline requirement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Add native Windows support
Why
Windows has many users
How
Shims, mostly.
Callouts
N/A
Testing
It builds! - Can port the test suite too if you want.
Related
Resolve #4018
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.