Repository navigation
c_import: full SDL.h imports — zero-parameter macro return types, D42 math builtins unwrapped, per-import overflow helpers, local anonymous unions (#1876 #1877 #1878 #1879) - #1896
Merged
Conversation
added 4 commits
September 29, 2026 14:40
…type from its body (#1879) `#define SDL_Unsupported() SDL_SetError("...")` translated as `unsafe fn SDL_Unsupported() -> i32`: ci_translate_macros ran ci_infer_macro_return_type_from_expr only for a macro with parameters (CImport.w, the `else if param_count > 0` arm), so a zero-parameter macro kept the `i32` placeholder and the raw variadic's `bool` result failed "return type mismatch". The inference is the same for both. Fixes #1879
…ed in unsafe (#1876) MSVC's <corecrt_math.h> inline wrappers (acosf: `return (float)acos((double)x)`) translated as `return unsafe { acos(x as f64) }` and were refused as a block with no unsafe operation: ci_migrate_preamble_extern_call_requires_unsafe (CImport.w) counted every modeled libc name, libm included, as an unsafe extern call. Since D42 those names are the compiler's math builtins — Sema types the call itself and an `extern fn` of the name yields to it (SemaCheck math_extern_yields) — so the call is never an unsafe operation. One owner: ci_is_libm_fn now reads the MathBuiltins table Sema reads (math_fn_lookup) instead of its own list, and the unsafe rule answers false for any row. Fixes #1876
…erflow names (#1877) SDL_size_mul_check_overflow's `__builtin_mul_overflow(a, b, ret)` lowered to a call of `__with_builtin_mul_overflow_u64` that nothing defined ("undefined variable"): build_overflow_builtin_call (CImport.w) named the migrator's preamble helper, which only a migrated module's defs.w defines; a header import has no preamble. The import now records each helper an inline body names and defines it once, at the end of its own translation (ci_render_overflow_helpers_needed, the CiMigrate renderers parametrized on the helper's name). The import's spelling is `__c_import_<op>_overflow_<ty>` / `__c_import_u128_mul_would_overflow`, distinct from the bundles' `__with_builtin_*` / `u128_mul_would_overflow`: a c_import-origin name is global and the .wo bundles' shared defs (lib/std/re/defs.w) reach every compilation, so a c_import definition of the bundle's name captured the bundle's own calls (MIR "body index map mismatch"; filed as #1882). Fixes #1877
…s a With type beside the function (#1878) SDL_SwapFloat's `union { float f; Uint32 ui32; } swapper;` translated as `var __local_swapper: c_void` and every field access failed: the bridge names a record with no tag only at file scope, as a member, or behind a parameter/return (name_file_scope_anon_records, ClangBridge.w), so a body-local one had no name and translate_type_recursive printed `c_void`; lower_decl_stmt_structural (CImport.w) then skipped the record declaration sitting beside the VarDecl in the DeclStmt. The bridge now walks every function definition's locals (name_local_anon_records) and names the record `<fn>_<var>_anon` under the same session table, so the local's type and the record agree. The body lowering translates that record declaration with ci_translate_anon_record_cursor and hoists it to module level beside the function (ci_take_body_hoisted_decls, read by ci_translate_function and the migrator's emission); a record With has no layout for is a loud omission of the function, never an opaque local. Fixes #1878
ehartford
force-pushed
the
fix-sdl-import
branch
from
September 29, 2026 18:56
a746207 to
4378844
Compare
ehartford
marked this pull request as ready for review
September 29, 2026 18:57
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.
Stack #1898, layer 12. Closes #1876, #1877, #1878, #1879. With these,
use c_import("SDL3/SDL.h")(SDL 3.4.14) checks ok on Darwin. Found and filed on the way: #1882 (a c_import-origin function name captures a std bundle's own calls). Not yet verified on Windows: #1876 against the real<corecrt_math.h>. Gate green on the layer before folding. Draft until the stack battery is green and posted.