std.DynLib corrupts struct passed by value
Zig Version
0.13.0-dev.46+3648d7df1
Steps to Reproduce and Observed Behavior
Env: Windows 11 Version 10.0.22631 Build 22631
Repo: https://github.com/Pyrolistical/dynlib-struct-pass-by-value-repo
Run zig build run
Outputs:
main main.SomeStruct{ .x = 11 }
viaStructDynLib root.SomeStruct{ .x = 147 }
viaStruct root.SomeStruct{ .x = 11 }
Expected Behavior
Expected DynLib to be the same as extern:
main main.SomeStruct{ .x = 11 }
viaStructDynLib root.SomeStruct{ .x = 11 }
viaStruct root.SomeStruct{ .x = 11 }
Passing the struct as pointer works, and replacing the struct with a u8 also works. So it has something to do with copy by value.
im getting some (unrelated) weird build errors from this but i believe the problem is this line
https://github.com/Pyrolistical/dynlib-struct-pass-by-value-repo/blob/ace0ec3aff2613a43b84b0b12e26c21cec2bbc07/src/main.zig#L18
you need to add callconv(.C). this should probably be checked in the DynLib functions
@xdBronch yep! that is issue. but can DynLib assert something for function pointers missing callconv? maybe assert callconv is not the default .Unspecified?
that might work, i wouldve asserted that its specifically the C callconv idk what happens with any of the others