macOS port: fix errno and libc loading across stdlib
ober
55ee3e5e68b0e91cb136e241ae0559ec9f68de40
--- a/lib/std/misc/process.sls +++ b/lib/std/misc/process.sls @@ -258,7 +258,9 @@ #f (or (guard (e [#t #f]) (load-shared-object "libc.so.7")) (guard (e [#t #f]) (load-shared-object "libc.so.6")) - (load-shared-object "libc.so"))))) + (guard (e [#t #f]) (load-shared-object "libc.so")) + (guard (e [#t #f]) (load-shared-object #f)) ;; macOS: resolve from current process + #f)))) (define c-kill (foreign-procedure "kill" (int int) int)) (define c-isatty (foreign-procedure "isatty" (int) int)) --- a/lib/std/net/repl.sls +++ b/lib/std/net/repl.sls @@ -31,9 +31,17 @@ (define c-getsockname (foreign-procedure "getsockname" (int void* void*) int)) (define c-fcntl (foreign-procedure "fcntl" (int int int) int)) (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) ;; Constants (values differ between Linux and FreeBSD) --- a/lib/std/net/tcp-raw.sls +++ b/lib/std/net/tcp-raw.sls @@ -37,9 +37,17 @@ ;; errno (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define EINTR 4) --- a/lib/std/net/tcp.sls +++ b/lib/std/net/tcp.sls @@ -51,9 +51,12 @@ ;; errno access for EINTR retry (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + (and (>= (string-length mt) 3) + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + (foreign-procedure "__error" () void*) + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define EINTR 4) (define *freebsd?* (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))) --- a/lib/std/os/fcntl.sls +++ b/lib/std/os/fcntl.sls @@ -28,9 +28,17 @@ ;; errno access for error reporting (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) ;; ========== Constants ========== --- a/lib/std/os/flock.sls +++ b/lib/std/os/flock.sls @@ -24,9 +24,17 @@ ;; errno access (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define *freebsd?* (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))) (define EWOULDBLOCK (if *freebsd?* 35 11)) --- a/lib/std/os/posix.sls +++ b/lib/std/os/posix.sls @@ -98,9 +98,17 @@ ;; errno is thread-local via __errno_location on Linux / __error on FreeBSD (define c-errno-location (guard (e [#t #f]) - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*)))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*))))) (define (posix-errno) (if c-errno-location --- a/lib/std/os/signalfd.sls +++ b/lib/std/os/signalfd.sls @@ -56,9 +56,17 @@ ;; errno access (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define EINTR 4) (define EAGAIN (if *freebsd?* 35 11)) --- a/lib/std/security/landlock.sls +++ b/lib/std/security/landlock.sls @@ -56,9 +56,17 @@ (define c-errno (guard (e [#t (lambda () 0)]) - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*)))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*))))) (define (get-errno) (guard (e [#t 0]) --- a/lib/std/security/seccomp.sls +++ b/lib/std/security/seccomp.sls @@ -47,9 +47,17 @@ (define c-errno (guard (e [#t (lambda () 0)]) - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*)))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*))))) (define (get-errno) (guard (e [#t 0]) --- a/lib/std/web/fastcgi.sls +++ b/lib/std/web/fastcgi.sls @@ -44,9 +44,17 @@ (define c-inet-pton (foreign-procedure "inet_pton" (int string void*) int)) (define c-fcntl (foreign-procedure "fcntl" (int int int) int)) (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define AF_INET 2) --- a/lib/std/web/rack.sls +++ b/lib/std/web/rack.sls @@ -39,9 +39,17 @@ (define c-inet-pton (foreign-procedure "inet_pton" (int string void*) int)) (define c-fcntl (foreign-procedure "fcntl" (int int int) int)) (define c-errno-location - (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) - (foreign-procedure "__error" () void*) - (foreign-procedure "__errno_location" () void*))) + (let ((mt (symbol->string (machine-type)))) + + (if (or (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb)) + + (and (>= (string-length mt) 3) + + (string=? (substring mt (- (string-length mt) 3) (string-length mt)) "osx"))) + + (foreign-procedure "__error" () void*) + + (foreign-procedure "__errno_location" () void*)))) (define (get-errno) (foreign-ref 'int (c-errno-location) 0)) (define AF_INET 2)