GNU bug report logs - #18592
FFI should have portable access to ‘errno’

Previous Next

Package: guile;

Reported by: Frank Terbeck <ft <at> bewatermyfriend.org>

Date: Tue, 30 Sep 2014 20:21:01 UTC

Severity: wishlist

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

Full log


Message #13 received at 18592 <at> debbugs.gnu.org (full text, mbox):

From: Frank Terbeck <ft <at> bewatermyfriend.org>
To: Mark H Weaver <mhw <at> netris.org>
Cc: 18592 <at> debbugs.gnu.org
Subject: Re: bug#18592: FFI should have portable access to ‘errno’
Date: Tue, 11 Nov 2014 21:02:20 +0100
Mark H. Weaver wrote:
> Frank Terbeck <ft <at> bewatermyfriend.org> writes:
[...]
>> Mark Weaver on IRC thought it would be a good idea to add portable
>> access to the contents of ‘errno’ (however it's actually 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 ‘call-with-blocked-asyncs’ to avoid
this. To deal with that, I wrote a macro for guile-termios¹:

(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.


Regards, Frank

 ¹ https://github.com/ft/guile-termios




This bug report was last modified 8 years and 338 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.