Skip to content

non-optional variants of C pointers #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Rageoholic opened this issue Jan 10, 2020 · 6 comments
Open

non-optional variants of C pointers #4127

Rageoholic opened this issue Jan 10, 2020 · 6 comments
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. translate-c C to Zig source translation feature (@cImport)
Milestone

Comments

@Rageoholic
Copy link
Contributor

So in several cases when interacting with C code a function pointer has been typedef'd so that the pointer is part of the type such as typedef void (VKAPI_PTR *PFN_vkVoidFunction)(void);. In usage I would prefer to unwrap these as early as possible and never unwrap them again, however if I do that I have to make my own type aliases for these functions. Would it be possible to take a C typedef'd pointer type and add some syntactic sugar to say that it is not optional and cannot be null.

@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. translate-c C to Zig source translation feature (@cImport) labels Jan 10, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Jan 10, 2020
@JesseRMeyer
Copy link

How would you handle of the case of the vulkan (or GL, say) driver not supplying a function you want, say, because it's an old or broken implementation? Maybe I misunderstand the exact scenario, but isn't unwrapping what you want here at the interface layer between C and Zig?

@Rageoholic
Copy link
Contributor Author

Rageoholic commented Jan 10, 2020 via email

@JesseRMeyer
Copy link

Ah, are you suggesting a function pointer type that automatically unwraps only once only during assignment? I think it's dangerous to assume that the pointer value from C code is valid, even if the source is spec'd to be valid. But if the claim can be demonstrated to be valid (the unwrap in Zig code), then Zig pointer semantics are preserved at the interface boundary without leaks.

@Rageoholic
Copy link
Contributor Author

Rageoholic commented Jan 10, 2020 via email

@kristoff-it
Copy link
Member

Unless I misunderstand, this seems part of what is being discussed in #2457.
If we get @reify (#2907) this should be possible to implement as a library.

@daurnimator
Copy link
Contributor

I think I've mentioned it somewhere before, but I think that [*c] should become non-optional: gaining the meaning "not sure if single or multiple item pointer". A C pointer defined using the nonnull GCC attribute would be able to be converted to this. Most C pointers would end but being translated to ?[*c].

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.10.0 May 19, 2021
@Vexu Vexu added the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

6 participants