Fix sb-posix for 64-bit time_t.

This commit is contained in:
Stas Boukarev 2025-01-17 05:19:04 +03:00
parent 966aefb714
commit f119986c69
9 changed files with 60 additions and 38 deletions

View file

@ -23,9 +23,9 @@ jobs:
CC: arm-linux-gnueabihf-gcc CC: arm-linux-gnueabihf-gcc
run: ./make.sh --xc-host='sbcl --dynamic-space-size 700MB --lose-on-corruption --disable-ldb --disable-debugger' --arch=arm run: ./make.sh --xc-host='sbcl --dynamic-space-size 700MB --lose-on-corruption --disable-ldb --disable-debugger' --arch=arm
# - name: test - name: test
# env: env:
# CC: arm-linux-gnueabihf-gcc CC: arm-linux-gnueabihf-gcc
# run: cd tests; ./run-tests.sh run: cd tests; ./run-tests.sh
- name: ansi-test - name: ansi-test
run: cd tests; ./ansi-tests.sh run: cd tests; ./ansi-tests.sh

View file

@ -197,6 +197,8 @@ code:
(split-cflags (sb-ext:posix-getenv "EXTRA_CFLAGS")) (split-cflags (sb-ext:posix-getenv "EXTRA_CFLAGS"))
#+(and linux largefile) #+(and linux largefile)
'("-D_LARGEFILE_SOURCE" "-D_LARGEFILE64_SOURCE" "-D_FILE_OFFSET_BITS=64") '("-D_LARGEFILE_SOURCE" "-D_LARGEFILE64_SOURCE" "-D_FILE_OFFSET_BITS=64")
#+64-bit-time
'("-D_TIME_BITS=64")
#+(and (or x86 ppc sparc) (or linux freebsd)) '("-m32") #+(and (or x86 ppc sparc) (or linux freebsd)) '("-m32")
#+(and x86-64 darwin inode64) #+(and x86-64 darwin inode64)
`("-arch" "x86_64" ,(format nil "-mmacosx-version-min=~A" `("-arch" "x86_64" ,(format nil "-mmacosx-version-min=~A"

View file

@ -424,7 +424,8 @@
;; utime(), utimes() ;; utime(), utimes()
#-win32 #-win32
(:type suseconds-t ; OAOOM warning: similar kludge in tools-for-build (:type suseconds-t ; OAOOM warning: similar kludge in tools-for-build
#+os-provides-suseconds-t "suseconds_t" #+(and os-provides-suseconds-t 64-bit-time) "__suseconds64_t"
#+(and os-provides-suseconds-t (not 64-bit-time)) "suseconds_t"
#-os-provides-suseconds-t "long") #-os-provides-suseconds-t "long")
#-win32 #-win32
@ -436,7 +437,9 @@
(:structure alien-timeval (:structure alien-timeval
("struct timeval" ("struct timeval"
(time-t sec "time_t" "tv_sec") (time-t sec "time_t" "tv_sec")
(suseconds-t usec "suseconds_t" "tv_usec"))) (suseconds-t usec #+64-bit-time "__suseconds64_t"
#-64-bit-time "suseconds_t"
"tv_usec")))
(:integer veof "VEOF" nil t) (:integer veof "VEOF" nil t)
(:integer veol "VEOL" nil t) (:integer veol "VEOL" nil t)

View file

@ -908,7 +908,8 @@ not supported."
(progn (progn
(export 'time :sb-posix) (export 'time :sb-posix)
(defun time () (defun time ()
(let ((result (alien-funcall (extern-alien "time" (let ((result (alien-funcall (extern-alien #-64-bit-time "time"
#+64-bit-time "__time64"
(function time-t (* time-t))) (function time-t (* time-t)))
nil))) nil)))
(if (minusp result) (if (minusp result)
@ -916,18 +917,19 @@ not supported."
result))) result)))
(export 'utime :sb-posix) (export 'utime :sb-posix)
(defun utime (filename &optional access-time modification-time) (defun utime (filename &optional access-time modification-time)
(with-alien ((fun (function int (c-string :not-null t) (* alien-utimbuf)) (with-alien ((fun (function int (c-string :not-null t) (* alien-utimbuf))
:extern #-netbsd "utime" #+netbsd "_utime")) :extern #-(or 64-bit-time netbsd) "utime" #+netbsd "_utime"
(let ((name (filename filename))) #+64-bit-time "__utime64"))
(if (not (and access-time modification-time)) (let ((name (filename filename)))
(alien-funcall fun name nil) (if (not (and access-time modification-time))
(with-alien ((utimbuf (struct alien-utimbuf))) (alien-funcall fun name nil)
(setf (slot utimbuf 'actime) (or access-time 0) (with-alien ((utimbuf (struct alien-utimbuf)))
(slot utimbuf 'modtime) (or modification-time 0)) (setf (slot utimbuf 'actime) (or access-time 0)
(let ((result (alien-funcall fun name (alien-sap utimbuf)))) (slot utimbuf 'modtime) (or modification-time 0))
(if (minusp result) (let ((result (alien-funcall fun name (alien-sap utimbuf))))
(syscall-error 'utime) (if (minusp result)
result))))))) (syscall-error 'utime)
result)))))))
(export 'utimes :sb-posix) (export 'utimes :sb-posix)
(defun utimes (filename &optional access-time modification-time) (defun utimes (filename &optional access-time modification-time)
(flet ((seconds-and-useconds (time) (flet ((seconds-and-useconds (time)
@ -938,22 +940,22 @@ not supported."
(if (minusp value) (if (minusp value)
(syscall-error 'utimes) (syscall-error 'utimes)
value))) value)))
(with-alien ((fun (function int (c-string :not-null t) (* (array alien-timeval 2))) (with-alien ((fun (function int (c-string :not-null t) (* (array alien-timeval 2)))
:extern #-netbsd "utimes" #+netbsd "sb_utimes")) :extern #-(or netbsd 64-bit-time) "utimes" #+(or netbsd 64-bit-time) "sb_utimes"))
(let ((name (filename filename))) (let ((name (filename filename)))
(if (not (and access-time modification-time)) (if (not (and access-time modification-time))
(maybe-syscall-error (alien-funcall fun name nil)) (maybe-syscall-error (alien-funcall fun name nil))
(with-alien ((buf (array alien-timeval 2))) (with-alien ((buf (array alien-timeval 2)))
(let ((actime (deref buf 0)) (let ((actime (deref buf 0))
(modtime (deref buf 1))) (modtime (deref buf 1)))
(setf (values (slot actime 'sec) (setf (values (slot actime 'sec)
(slot actime 'usec)) (slot actime 'usec))
(seconds-and-useconds (or access-time 0)) (seconds-and-useconds (or access-time 0))
(values (slot modtime 'sec) (values (slot modtime 'sec)
(slot modtime 'usec)) (slot modtime 'usec))
(seconds-and-useconds (or modification-time 0))) (seconds-and-useconds (or modification-time 0)))
(maybe-syscall-error (alien-funcall fun name (maybe-syscall-error (alien-funcall fun name
(alien-sap buf))))))))))) (alien-sap buf)))))))))))
;;; environment ;;; environment

View file

@ -422,7 +422,7 @@
#+win32 #+win32
(alien-funcall (extern-alien "Sleep" (function void int)) 300) (alien-funcall (extern-alien "Sleep" (function void int)) 300)
#-win32 #-win32
(alien-funcall (extern-alien "sb_nanosleep" (function void int int)) 0 300000000) (alien-funcall (extern-alien "sb_nanosleep" (function void sb-unix:time-t int)) 0 300000000)
(values a b c d e f g h i j k l m)))) (values a b c d e f g h i j k l m))))
(thr (sb-thread:make-thread (lambda () (thr (sb-thread:make-thread (lambda ()
(let ((args #1=(list (LIST 'A) (LIST 'B) (LIST 'C) (let ((args #1=(list (LIST 'A) (LIST 'B) (LIST 'C)

View file

@ -8,7 +8,8 @@
;;; SLEEP should not cons except on 32-bit platforms when ;;; SLEEP should not cons except on 32-bit platforms when
;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9)) ;;; (> (mod seconds 1) (* most-positive-fixnum 1e-9))
(with-test (:name (sleep :non-consing) (with-test (:name (sleep :non-consing)
:serial t :skipped-on :interpreter) :serial t :skipped-on :interpreter
:fails-on (and :arm :64-bit-time))
(handler-case (sb-ext:with-timeout 5 (handler-case (sb-ext:with-timeout 5
(ctu:assert-no-consing (sleep 0.00001s0)) (ctu:assert-no-consing (sleep 0.00001s0))
(locally (declare (notinline sleep)) (locally (declare (notinline sleep))

View file

@ -0,0 +1,8 @@
#include <time.h>
int main ()
{
if (sizeof( time_t) == 8)
return 104;
return 1;
}

View file

@ -52,6 +52,13 @@ featurep os-provides-close-range-wrapper
featurep os-provides-posix-spawn featurep os-provides-posix-spawn
if [ "$sbcl_os" = linux ] ; then
case "$sbcl_arch" in
arm | x86 | ppc | mips | sparc | riscv32)
featurep 64-bit-time
esac
fi
if [ "$sbcl_arch" = arm ] ; then if [ "$sbcl_arch" = arm ] ; then
featurep arm-softfp featurep arm-softfp
fi fi

View file

@ -1,4 +1,3 @@
/* test to build and run so that we know if we have blksize_t */
#include <sys/types.h> #include <sys/types.h>