<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 6:52 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 1:34 PM, Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi guys,<div><br></div><div>I am using NB FFI and I am calling a function that could answer a NULL* in case of error and that it should have set the number on <i>errno.</i></div><div><i><br></i></div><div>So now I have some questions:</div><div><br></div><div>Say the code is this:</div><div><br></div><div><div>run</div><div><span style="white-space:pre-wrap">        </span>| whatever |</div><div><span style="white-space:pre-wrap">        </span>whatever := self <b>primitiveWhatever</b>.</div><div><span style="white-space:pre-wrap">        </span>^ popenFile ifNil: [ </div><div><span style="white-space:pre-wrap">                </span>self <b>primitivePerror</b>.</div><div><br></div><div>Imagine that the C lib called from #primitiveWhatever was the one setting <i>errno.</i></div><div>My question is... the following #primitivePerror is a DIFFERENT system call. Couldn&#39;t that happened that another error happened before the first system call and time I am executing the second one and so the &quot;last error&quot; (errno) is actually the wrong one I am thinking of?</div></div></div></blockquote><div><br></div><div>Yes, which is why it&#39;s really important that the FFI be able to be told to answer errno on error. See e.g. the VW FFI where IIRC one can specify that if a call answers -1, the FFI call can fail with a primitive error code that includes errno.</div><div> </div></div></div></div></blockquote><div><br></div><div>Yes, that would be very nice. At least for -1 and NULL. It seems Python FFI does this as well. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><br></div><div>Even worst, I may think that the scope of the  &quot;global variable errno&quot; may existed at the scope of the invoked lib only? In this case I don&#39;t have above problem, but then....how can I get such number once the NB primitive finished (so that I can call, for example,  strerror() ?  <br></div></div></div></blockquote><div><br></div><div>Well, there are two issues here.  One is that one should use waterer the underlying platform defines for getting &quot;errno&quot;, for example some platforms will say something like #define errno get_errno(), to get the errno specific to the current thread. </div></div></div></div></blockquote><div><br></div><div>It&#39;s funny there is no standard way (POSIX function?) for it. And there is for example for perror() which basically prints errno in stderr, but none standard function to get last errno of current thread?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> Second, all one&#39;s libraries need to use the same approach so that errno is shared between the VM and the libraries, otherwise your library may not set the errno seen by the VM and the FFI.</div><div><br></div></div></div></div></blockquote><div><br></div><div>I didn&#39;t understand this last sentence. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div></div><div>Thanks in advance, </div><span><font color="#888888"><div><br></div>-- <br><div>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br></div>
</div></div>