lib/wasi-types: add Socktype::Unused shim value #3878
Closed
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.
Description
In wasix-libc we derive the value of the C macro
SOCK_DGRAM
andSOCK_STREAM
from thesock_type
enum in wasix-witx. Thissock_type
witx enum corresponds roughly to the Wasmersocktype
enum.The problem with these corresponding enums as-written is that they result in a
SOCK_DGRAM
value of 0. This doesn't work for cpython (and potentially other programs depending on libc) because the value0
is used for a cpython-specific macro that is used in a switch case arm alongsideSOCK_DGRAM
:GAI_ANY
macro defined as 0GAI_ANY
used next toSOCK_DGRAM
in a switch blockThis cpython hack seems likely to me to be replicated elsewhere in the open source world and implies that most libc implementations likely don't have any
SOCK_*
macros with the value0
.This PR is paired with a corresponding wasix-witx PR. Both PRs utilize the same hack: introduce a shim enum variant to ensure that none of the other variants take the value
0
.