Repository navigation
Conversation
As it is ridiculous that we only have convenient APIs to add types for HashTables wrapped in zvals but not HashTables directly. But now that we require C11 it means we can rely on _Generic to exist. However C's _Generic is an infuriating mess to use as every single branch must be semantically valid even if it is discarded. Not at all confusing behaviour with terrible compiler errors, it took me a while to understand why the "obvious" ways of writing the generics did not work. Until I managed to stumble upon [1] (thank Kagi as Google/DDG have been useless) that explains the observed behaviour. It is possible for us to have parametric genericity because we are branching on pointers. The trick is to create dummy functions that take void* arguments and return a HashTable* rather than trying to use a macro. The C++ side is simple function overloading. [1] https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/#bigbug
devnexen
reviewed
Oct 24, 2026
| * [1] https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/#bigbug | ||
| */ | ||
|
|
||
| static inline HashTable *htid(void *ptr) { return ptr; } |
Member
There was a problem hiding this comment.
it might be best for symbols clarity for these little helpers to have a zend_ prefix wdyt ?
Member
Author
There was a problem hiding this comment.
Yeah, I was trying to get it to work first :) I also need to update the header define too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As it is ridiculous that we only have convenient APIs to add types for HashTables wrapped in zvals but not HashTables directly.
But now that we require C11 it means we can rely on _Generic to exist.
However C's _Generic is an infuriating mess to use as every single branch must be semantically valid even if it is discarded.
Not at all confusing behaviour with terrible compiler errors, it took me a while to understand why the "obvious" ways of writing the generics did not work.
Until I managed to stumble upon [1] (thank Kagi as Google/DDG have been useless) that explains the observed behaviour.
It is possible for us to have parametric genericity because we are branching on pointers.
The trick is to create dummy functions that take void* arguments and return a HashTable* rather than trying to use a macro.
The C++ side is simple function overloading.
[1] https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/#bigbug