Returning errno as a second value
Felix Filozov
ffilozov at gmail.com
Wed Aug 14 15:23:23 UTC 2013
Ah, I understand why it has to be dynamic now. I'll start working on
with-errno then.
The consing problem is clearer now, but I wonder how much overhead it adds
compared to the cost of making a foreign call. According to the Allegro CL
documentation, a foreign call which returns errno is less efficient. For
other Lisps, an additional foreign call would have to be made to get errno.
Maybe consing is negligible?
On Wed, Aug 14, 2013 at 3:04 PM, Luís Oliveira <luismbo at gmail.com> wrote:
> Felix Filozov <ffilozov at gmail.com> writes:
>
> > Maybe we can even do this using lexical binding, since GET-ERRNO could
> > be a macro that expands to a lexical variable introduced by
> > WITH-ERRNO.
>
> The issue there is that foreign-funcall will be setting errno.
>
>
> > Could you elaborate where there's a consing issue, if errno is
> > returned as the last, or first, value?
>
> So, the pseudo-code for the implementation in foreign-funcall would be
> something like:
>
> (multiple-value-bind (return-value errno)
> (%foreign-funcal ...)
> (let ((translated-return-values (multiple-value-list
> (translate-from-foreign ...))))
> (values-list (cons errno translated-return-values))
> ;; or (values-list (nconc translated-return-values (list errno)))
> ))
>
> Right now I'm inclined to discard all but the first translated return
> value. (This is your initial solution, isn't it?)
>
> Luís
>
>
>
On Wed, Aug 14, 2013 at 3:04 PM, Luís Oliveira <luismbo at gmail.com> wrote:
> Felix Filozov <ffilozov at gmail.com> writes:
>
> > Maybe we can even do this using lexical binding, since GET-ERRNO could
> > be a macro that expands to a lexical variable introduced by
> > WITH-ERRNO.
>
> The issue there is that foreign-funcall will be setting errno.
>
>
> > Could you elaborate where there's a consing issue, if errno is
> > returned as the last, or first, value?
>
> So, the pseudo-code for the implementation in foreign-funcall would be
> something like:
>
> (multiple-value-bind (return-value errno)
> (%foreign-funcal ...)
> (let ((translated-return-values (multiple-value-list
> (translate-from-foreign ...))))
> (values-list (cons errno translated-return-values))
> ;; or (values-list (nconc translated-return-values (list errno)))
> ))
>
> Right now I'm inclined to discard all but the first translated return
> value. (This is your initial solution, isn't it?)
>
> Luís
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20130814/5a7e07c4/attachment.html>
More information about the cffi-devel
mailing list