Skip to content

We need safer function pointer casts #1223

@IntegratedQuantum

Description

@IntegratedQuantum

The problem:
Generic functions often have an interface involving an anyopaque pointer *const fn(self: *anyopaque, ...) void
However in practive we often have functions with specific pointers: pub fn generate(self: *Stalagmite, ...)
Now to convert them it is convenient to use a @ptrCast, however this is completely unsafe, since the arguments are not checked at all.

So ideally we could make a safer cast using reflection to first check if the arguments match in length and size and alignment, and then again do the ptrCast in the end.
This would make the access a bit more annoying because we'd explicitly have to supply the result type, but the improvements to safety would be definitely worth it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlythis issue is limited in scope and/or knowledge of Cubyz internals, good for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions