GNU bug report logs -
#18592
FFI should have portable access to ‘errno’
Previous Next
Full log
Message #13 received at 18592 <at> debbugs.gnu.org (full text, mbox):
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.