Extract bindings for LibC errno to src/lib_c/#15565
Extract bindings for LibC errno to src/lib_c/#15565straight-shoota merged 3 commits intocrystal-lang:masterfrom
src/lib_c/#15565Conversation
Harmonizes the POSIX definitions to use `LibC.__errno_location` so we avoid each target having its own naming. Doesn't harmonize as `LibC.errno` because it's supposed to be a value, not a pointer to the errno value, and `__errno_location` makes the pointer explicit.
|
Moving the fun declarations to the libc bindings is a no-brainer. But I'm not sure if harmonizing the alias is a good idea. It seems nice at first, cleaning up the shared interface. However, I believe there's great value in keeping the lib bindings as close to the original as possible. Yes, we can alias lib symbols to arbitrary names in the Crystal bindings. But that should be used with care, basically only when the original name doesn't work or doesn't make sense. Inventing a fake Btw. Zig collects clowns on this platform difference: https://github.com/ziglang/zig/blob/2a4e06bcb30f71e83b14026bcbade6aac3aece84/lib/std/c.zig#L11201-L11209 🤡 |
|
I'd usually agree with you. I prefer to use the actual symbols when possible, but this particular case screams to just alias this damn symbol 🙀 I can iterate the symbol names until one is defined, twice (getter and setter) if you really insist (but again, that's really a job for the alias feature). |
|
I'd probably prefer to just keep the current implementation of I'd just move the fun declarations to |
src/lib_c/
I noticed multiple times that we define the LibC errno bindings right in
src/errno.crinstead of doing in the per-targetsrc/lib_c/*/c/errno.crbindings.I also harmonized the POSIX funs to be aliased as
LibC.__errno_locationso we avoid each target having its own name. I didn't harmonize asLibC.errnobecauseerrnois supposed to be the value, not a pointer to the value.