<div dir="ltr"><div><div>Hi Luís,<br><br></div>I am hoping to resurrect this thread. Did you by any chance take a look at the <a href="https://github.com/cffi/cffi/pull/31">pull request</a> I made a few months ago relating to this feature?<br>
<br></div>Thanks,<br>Felix<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 6:26 PM, Felix Filozov <span dir="ltr"><<a href="mailto:ffilozov@gmail.com" target="_blank">ffilozov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have a <a href="https://github.com/ffilozov/cffi/tree/with-errno" target="_blank">with-errno</a> implementation.</div>
<div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 5:23 PM, Felix Filozov <span dir="ltr"><<a href="mailto:ffilozov@gmail.com" target="_blank">ffilozov@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ah, I understand why it has to be dynamic now. I'll start working on with-errno then.<div><br></div>

<div>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?</div>


<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 3:04 PM, Luís Oliveira <span dir="ltr"><<a href="mailto:luismbo@gmail.com" target="_blank">luismbo@gmail.com</a>></span> wrote:<div>

<div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>Felix Filozov <<a href="mailto:ffilozov@gmail.com" target="_blank">ffilozov@gmail.com</a>> writes:<br><br>> Maybe we can even do this using lexical binding, since GET-ERRNO could<br>> be a macro that expands to a lexical variable introduced by<br>


> WITH-ERRNO.<br><br></div>The issue there is that foreign-funcall will be setting errno.<br><div><br><br>> Could you elaborate where there's a consing issue, if errno is<br>> returned as the last, or first, value?<br>


<br></div>So, the pseudo-code for the implementation in foreign-funcall would be<br>something like:<br><br>  (multiple-value-bind (return-value errno)<br>      (%foreign-funcal ...)<br>    (let ((translated-return-values (multiple-value-list (translate-from-foreign ...))))<br>


      (values-list (cons errno translated-return-values))<br>      ;; or (values-list (nconc translated-return-values (list errno)))<br>      ))<br><br>Right now I'm inclined to discard all but the first translated return<br>


value. (This is your initial solution, isn't it?)<br><span><font color="#888888"><br>Luís<br><br><br></font></span></blockquote></div></div></div></div></div><div><div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Aug 14, 2013 at 3:04 PM, Luís Oliveira <span dir="ltr"><<a href="mailto:luismbo@gmail.com" target="_blank">luismbo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Felix Filozov <<a href="mailto:ffilozov@gmail.com" target="_blank">ffilozov@gmail.com</a>> writes:<br>
<br>
> Maybe we can even do this using lexical binding, since GET-ERRNO could<br>
> be a macro that expands to a lexical variable introduced by<br>
> WITH-ERRNO.<br>
<br>
</div>The issue there is that foreign-funcall will be setting errno.<br>
<div><br>
<br>
> Could you elaborate where there's a consing issue, if errno is<br>
> returned as the last, or first, value?<br>
<br>
</div>So, the pseudo-code for the implementation in foreign-funcall would be<br>
something like:<br>
<br>
  (multiple-value-bind (return-value errno)<br>
      (%foreign-funcal ...)<br>
    (let ((translated-return-values (multiple-value-list (translate-from-foreign ...))))<br>
      (values-list (cons errno translated-return-values))<br>
      ;; or (values-list (nconc translated-return-values (list errno)))<br>
      ))<br>
<br>
Right now I'm inclined to discard all but the first translated return<br>
value. (This is your initial solution, isn't it?)<br>
<span><font color="#888888"><br>
Luís<br>
<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>