Returning errno as a second value
Daniel Herring
dherring at tentpost.com
Thu Aug 8 02:29:07 UTC 2013
Hi Felix,
Errno is a particularly tricky beast. It is a thread-local "global" that
is modified by a large number of system calls and library functions.
Code must be careful to check it before another such call is made. I
could easily imagine a stop-the-world GC accidentally modifying errno if
errno is not checked "atomically" with the function call.
Also errno is very lightweight. An extra foreign call to check it could
easily dwarf the cost of the check. Errno is a "hidden" return parameter,
much like the second position in a multiple-value return.
Thus the Allegro semantics of returning errno as a second value seem
reasonable to me.
As you suggested, CFFI could provide a default errno implementation for
CLs that have different native semantics.
- Daniel
More information about the cffi-devel
mailing list