[cffi-devel] Safe errno collection

John Fremlin jf at msi.co.jp
Mon Jan 19 08:34:52 UTC 2009


I think in summary, most Lisps are quite unsafe with regard to errno.

Suppose we had a (defmacro with-returning-errno (&body body) ...)

What can be permitted inside BODY? Certainly not anything that does IO,
because that will almost certainly change errno. That means that no
trace'd function can be called, for example. GC is probably not safe.

It is difficult to think of anything useful that can be safely allowed
in with-returning-errno. The BODY can only be the call to the defcfun'd
function ;-)

In the case of Allegro, Duane points out that when a Lisp thread calls a
foreign function, the wrapper may release the heap. If it releases the
heap then it has to reacquire it before returning to normal Lisp
code. And reacquiring the heap may actually require calling a C library
function that resets errno.

This is platform specific, and as I understand does not occur generally
on x86/AMD64 Linux.

Duane is having a look to see if there is a way to implement the
with-returning-errno after all, but it is unlikely.





More information about the cffi-devel mailing list