Returning errno as a second value

Felix Filozov ffilozov at gmail.com
Tue Aug 13 13:48:09 UTC 2013


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?

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. So
something like this:

(defmacro with-errno (&body body)
  (let ((exprs-before-ffc ...)
        (ffc-expression ..)
        (exprs-after-ffc ..))
    `, at exprs-before-ffc
     (let ((errno ,ffc-expression))
       ,@(exprs-after-ffc))))

There's some complications such as, how to determine which expression is a
foreign function call since defcfun can assign any arbitrary name. There's
also the issue of what should the foreign function call return? It seems
like it would have to return errno as the last value.

To mitigate the first concern, perhaps a more explicit interface would help:

(with-foreign-funcall-errno (result errno (foreign-funcall "strlen" ...))
  ...)

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

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

On Mon, Aug 12, 2013 at 10:54 PM, Luís Oliveira <luismbo at gmail.com> wrote:

> Felix Filozov <ffilozov at gmail.com> writes:
>
> > The implementation uses locking, so its efficiency could improved. I'm
> > interested in your suggestions on how to do that.
>
> Indeed, this interface is much better from the user's point of view. I
> feel a bit uneasy about the implementation though.
>
> I found this message from Duane Rettig
> (<
> https://groups.google.com/forum/#!msg/comp.lang.lisp/7rhuvXaiR_g/AQ2-i6-74s4J
> >)
> that suggests that the nearest ACL gets to thread-local variables is by
> defining a special variable then adding it to the list of default
> bindings.
>
> How about an interface like this?
>
>   (with-errno
>     (some-foreign-function-with-the-errno-option-on)
>     (get-errno))
>
> or perhaps
>
>   (with-errno (errno)
>     (some-foreign-function-with-the-errno-option-on)
>     errno)
>
> Cheers,
>
> --
> Luís Oliveira
> http://kerno.org/~luis
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20130813/ccbe644a/attachment.html>


More information about the cffi-devel mailing list