|
infix
A JIT-Powered FFI Library for C
|
Regression test for layout recalculation of structs inside function signatures. More...
#include "common/compat_c23.h"#include "common/double_tap.h"#include <infix/infix.h>#include <stddef.h>#include <stdint.h>Classes | |
| struct | signature_layout_image |
Macros | |
| #define | DBLTAP_IMPLEMENTATION |
Functions | |
| subtest ("layout recalc descends into function args") | |
Variables | |
| TEST | |
Regression test for layout recalculation of structs inside function signatures.
Regression test for a bug where the Layout stage (_infix_type_recalculate_layout) did not descend into INFIX_TYPE_REVERSE_TRAMPOLINE roots. A struct declared inline in a function signature whose members reference named types (e.g. @png_uint_32) kept the member offsets computed at parse time, while its members were still unresolved named references (size 0, alignment 1). Once the Resolve stage replaced the references with concrete types, the offsets were never recomputed, so every scalar member collapsed to the same offset.
That produced wrong field reads and writes through FFI bindings that use struct-typed arguments, e.g. libpng's png_image_write_to_file read back version == 0 because version was written at the wrong byte.
The struct below mirrors png_image's shape: a leading pointer member that pushes the scalar fields off offset 0, and scalar fields typed through a named type so they are unresolved until the Resolve stage.
| #define DBLTAP_IMPLEMENTATION |
| subtest | ( | "layout recalc descends into function args" | ) |