From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= Date: Thu, 13 Nov 2014 12:12:32 -0500 Message-ID: <87ioijf2in.fsf@yeeloong.lan> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87wq71ixtw.fsf@yeeloong.lan> <87k331v73n.fsf@ft.bewatermyfriend.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1415898867 25417 80.91.229.3 (13 Nov 2014 17:14:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Nov 2014 17:14:27 +0000 (UTC) Cc: 18592@debbugs.gnu.org To: Frank Terbeck Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Nov 13 18:14:19 2014 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XoxyN-00085k-6g for guile-bugs@m.gmane.org; Thu, 13 Nov 2014 18:14:19 +0100 Original-Received: from localhost ([::1]:33039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoxyM-0006jG-O2 for guile-bugs@m.gmane.org; Thu, 13 Nov 2014 12:14:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoxyC-0006ip-W4 for bug-guile@gnu.org; Thu, 13 Nov 2014 12:14:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xoxy6-0005ok-NE for bug-guile@gnu.org; Thu, 13 Nov 2014 12:14:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xoxy6-0005og-Ky for bug-guile@gnu.org; Thu, 13 Nov 2014 12:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Xoxy6-0002Tp-BX for bug-guile@gnu.org; Thu, 13 Nov 2014 12:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 13 Nov 2014 17:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18592 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 18592-submit@debbugs.gnu.org id=B18592.14158988359513 (code B ref 18592); Thu, 13 Nov 2014 17:14:02 +0000 Original-Received: (at 18592) by debbugs.gnu.org; 13 Nov 2014 17:13:55 +0000 Original-Received: from localhost ([127.0.0.1]:59616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xoxxz-0002TM-3o for submit@debbugs.gnu.org; Thu, 13 Nov 2014 12:13:55 -0500 Original-Received: from world.peace.net ([96.39.62.75]:47814) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xoxxx-0002TC-7b for 18592@debbugs.gnu.org; Thu, 13 Nov 2014 12:13:53 -0500 Original-Received: from c-24-62-95-23.hsd1.ma.comcast.net ([24.62.95.23] helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Xoxxq-0002OC-98; Thu, 13 Nov 2014 12:13:46 -0500 In-Reply-To: <87k331v73n.fsf@ft.bewatermyfriend.org> (Frank Terbeck's message of "Tue, 11 Nov 2014 21:02:20 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7639 Archived-At: Frank Terbeck writes: > Mark H. Weaver wrote: >> Frank Terbeck writes: > [...] >>> Mark Weaver on IRC thought it would be a good idea to add portable >>> access to the contents of =E2=80=98errno=E2=80=99 (however it's actuall= y implemented) to >>> Guile's FFI. And now the idea has entered the bug tracker. :) >> >> Indeed, thanks for filing this ticket. >> >> I see a problem with this idea: something (e.g. a system async) might >> change 'errno' before the Scheme code fetches the 'errno' value. > > Yes. Ludovic hinted at the use of =E2=80=98call-with-blocked-asyncs=E2=80= =99 to avoid > this. To deal with that, I wrote a macro for guile-termios=C2=B9: > > (define-syntax-rule (call-with-errno (errno exp) fail0 fail1 ...) > (let-values (((failed? errno) (call-with-blocked-asyncs > (lambda () > (let* ((f? (termios-failure? exp)) > (err (if f? (get-errno) 0))) > (values f? err)))))) > (if failed? > (begin fail0 fail1 ...) > #t))) > > That seems to work fine, unless I'm missing something. I looked at guile-termios, and I can see that you've done about as good a job as could be expected from pure Guile Scheme code today, but even so, it's neither portable nor future-proof, and might not even work reliably today. One potential problem is that memory allocation might modify 'errno', and in Guile 2.2 even calling a Scheme procedure can cause memory allocation if the stack needs to be expanded. With current versions of Guile, I see no good way to check 'errno' using the Dynamic FFI. I think the only proper solution today is to write a C extension that wraps each library function that might set 'errno', and to have those wrappers check 'errno' immediately after the wrapped function returns, without using any libguile functions in between. I intend to have a better solution for this in Guile 2.0.12. Regards, Mark