<div dir="ltr"><div dir="ltr">Em seg., 15 de ago. de 2022 às 20:08, David Holmes <<a href="mailto:david.holmes@oracle.com">david.holmes@oracle.com</a>> escreveu:<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> I don't understand what you mean by library in this instance.<br>
> There are three calls, one to write, next to last-error, finally to log;<br>
> the application is doing nothing else in this snippet.<br>
<br>
I started my response with the generalized snippet:<br>
<br>
doSomeNativeAPIStuff();<br>
// <what can go here?><br>
getLastErrorFromDoSomeNativeAPIStuff();<br>
<br>
You claimed libraries don't have to be responsible for preserving <br>
last-error, but other things are. But what do you define as a library here?<br></blockquote><div><br></div><div>I am naming "library" something the application explicitly calls into,</div><div>and therefore falls into the programmer's responsibility to call in the correct order.</div><div>The programmer must not, say, call into the system, then call some NIO method, then try to observe the last result of the first call.</div><div>This is incorrect; NIO is not responsible for saving the programmer from this mistake.</div><div>It doesn't matter that the programmer is calling a Java method that indirectly calls into the system.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">FFI it seems is introducing this problem, but nothing in the existing <br>
Java ecosystem is prepared to handle it: not the VM, not the debugger, <br>
not agents, nothing. It is simply not a problem that has been on <br>
anyone's radar when it comes to the application logic.<br></blockquote><div><br></div><div>It is perfectly understandable that none of this was ever relevant, never a problem, until now.</div><div>As has been observed by Maurizio, most JNI companion libraries "bundle" the two calls in one for convenience, apparently with the effect of obtaining some kind of "atomicity" from the perspective of the rest of the system.</div><div>If we must continue to do companion libraries to achieve correct results, so be it.</div><div>I suppose all there is left to do is document this fact.</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Pedro Lamarão</div></div></div></div>