Returning errno as a second value

Luís Oliveira luismbo at gmail.com
Tue Aug 13 22:15:03 UTC 2013


Felix Filozov <ffilozov at gmail.com> writes:

> If I understood Duane Rettig's response correctly, when a thread binds
> a special variable using a let, that binding is only visible for that
> particular thread. Is this how other Lisps behave?

All CLs I'm aware of behave like that, yes.


> With that in mind, in order to make with-errno work, the foreign
> function call expression would have to be identified and bound with a
> let.

Why is that? I was thinking that the interface could work as follows:

  1. WITH-ERRNO establishes a dynamic binding (cffi-sys:*errno* for
     instance)
  2. FOREIGN-FUNCALL does something like
       (when (boundp '*errno*) (setf *errno* <errno>))
  3. GET-ERRNO simply returns the value of *errno*


> You mentioned that a foreign function call could return errno as the
> first value, how about returning it as the last?

That would be much simpler wouldn't it? I wonder if we can avoid
consing, at least for the single return value case... If all else fails,
simply documenting that grabbing errno entails discarding all but the
first return value might be a solution.


> Another alternative is to optimize the way synchronization is done, so
> that we could improve the thread-local code I wrote before.

I don't have any good ideas on that front.

Luís




More information about the cffi-devel mailing list