Pointer corrupted when passed as last argument to C function

That’s possible, but I’m not sure how I could be more explicit about the type signature. I’m using @TypeOf and grabbing the argument index of the tuple and I’ve inspected those type signatures multiple times now. The same technique works without fail on all the other kernels. That said, here’s what I’ve done to fix this issue:

I moved all the function pointers away from runtime values to comptime by changing the dispatch arrays to fn types instead of *const fn types. Then, I added a handy little helper that translates our runtime index to a comptime index:

pub inline fn invoke(comptime kernels: anytype, key: usize, args: anytype) void {
    switch (key) {
        0 => @call(.auto, kernels[0], args),
        1 => @call(.auto, kernels[1], args),
        2 => @call(.auto, kernels[2], args),
        else => @panic("Invalid runtime key."),
    }
}

And yeah… that works. I’m too fatigued with this issue to keep looking into it further so I’ll just mark this as the solution but at some point in the future I may try to revisit this when I have more time. I’m only supporting floating point (and maybe I’ll reintroduce complex types again at some point) so enumerating the possibilities is quite trivial.

Anyhow, thanks again for all your help and your suggestions - you too, @LucasSantos91.

1 Like