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@gmail.com> wrote:Felix Filozov <ffilozov@gmail.com> writes:The issue there is that foreign-funcall will be setting errno.
> 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.So, the pseudo-code for the implementation in foreign-funcall would be
> Could you elaborate where there's a consing issue, if errno is
> returned as the last, or first, value?
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ísOn Wed, Aug 14, 2013 at 3:04 PM, Luís Oliveira <luismbo@gmail.com> wrote:
Felix Filozov <ffilozov@gmail.com> writes:The issue there is that foreign-funcall will be setting errno.
> 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.
So, the pseudo-code for the implementation in foreign-funcall would be
> Could you elaborate where there's a consing issue, if errno is
> returned as the last, or first, value?
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