Skip to content
Snippets Groups Projects
Commit af4535c5 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

utils: Make 'errno' procedure more robust.

Partially fixes <http://bugs.gnu.org/17212>.

* guix/utils.scm (errno): Move definition of 'bv' outside of the
  procedure.  Use 'bytevector-s32-native-ref' or
  'bytevector-s64-native-ref' instead of 'bytevector-sint-ref'.
parent 68ec0450
No related branches found
No related tags found
No related merge requests found
...@@ -377,14 +377,30 @@ (define %libc-errno-pointer ...@@ -377,14 +377,30 @@ (define %libc-errno-pointer
(let ((proc (pointer->procedure '* errno-loc '()))) (let ((proc (pointer->procedure '* errno-loc '())))
(proc))))) (proc)))))
(define (errno) (define errno
"Return the current errno."
;; XXX: We assume that nothing changes 'errno' while we're doing all this.
;; In particular, that means that no async must be running here.
(if %libc-errno-pointer (if %libc-errno-pointer
(let ((bv (pointer->bytevector %libc-errno-pointer (sizeof int)))) (let ((bv (pointer->bytevector %libc-errno-pointer (sizeof int))))
(bytevector-sint-ref bv 0 (native-endianness) (sizeof int))) (lambda ()
0)) "Return the current errno."
;; XXX: We assume that nothing changes 'errno' while we're doing all this.
;; In particular, that means that no async must be running here.
;; Use one of the fixed-size native-ref procedures because they are
;; optimized down to a single VM instruction, which reduces the risk
;; that we fiddle with 'errno' (needed on Guile 2.0.5, libc 2.11.)
(let-syntax ((ref (lambda (s)
(syntax-case s ()
((_ bv)
(case (sizeof int)
((4)
#'(bytevector-s32-native-ref bv 0))
((8)
#'(bytevector-s64-native-ref bv 0))
(else
(error "unsupported 'int' size"
(sizeof int)))))))))
(ref bv))))
(lambda () 0)))
(define fcntl-flock (define fcntl-flock
(let* ((ptr (dynamic-func "fcntl" (dynamic-link))) (let* ((ptr (dynamic-func "fcntl" (dynamic-link)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment