[cffi-devel] Re: Returning errno as a second value

Felix Filozov ffilozov at gmail.com
Tue Jan 28 14:33:34 UTC 2014


Hi Luís,

I am hoping to resurrect this thread. Did you by any chance take a look at
the pull request <https://github.com/cffi/cffi/pull/31> I made a few months
ago relating to this feature?

Thanks,
Felix


On Wed, Aug 14, 2013 at 6:26 PM, Felix Filozov <ffilozov at gmail.com> wrote:

> I have a with-errno <https://github.com/ffilozov/cffi/tree/with-errno>implementation.
>
>
> On Wed, Aug 14, 2013 at 5:23 PM, Felix Filozov <ffilozov at gmail.com> wrote:
>
>> 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/20140128/b14a4c8a/attachment.html>


More information about the cffi-devel mailing list