Add sb-alien:word and sb-alien:signed-word

This commit is contained in:
Stas Boukarev 2026-02-17 00:08:18 +03:00
parent ab3d830393
commit 9c9a4927ef
5 changed files with 8 additions and 9 deletions

View file

@ -97,9 +97,7 @@
;;; types and initialization
(define-alien-type gmp-limb
#-(and win32 64-bit) unsigned-long
#+(and win32 64-bit) unsigned-long-long)
(define-alien-type gmp-limb word)
(deftype ui ()
#-(and win32 64-bit) 'sb-vm:word

View file

@ -115,8 +115,7 @@ one or more times, not to exceed MAX-EXTENSIONS times"
(%primitive delete-arena arena)
#-x86-64
(alien-funcall (extern-alien "sbcl_delete_arena"
(function void
unsigned-long))
(function void word))
(get-lisp-obj-address arena))
;; It is illegal to access the structure now, since that was in the arena.
;; So return an arbitrary success indicator. It might happen that you can accidentally

View file

@ -34,6 +34,8 @@
(define-alien-type unsigned-long (unsigned #+win32 32
#-win32 #.sb-vm:n-machine-word-bits))
(define-alien-type unsigned-long-long (unsigned 64))
(define-alien-type word (unsigned #.sb-vm:n-machine-word-bits))
(define-alien-type signed-word (signed #.sb-vm:n-machine-word-bits))
(define-alien-type float single-float)
(define-alien-type double double-float)

View file

@ -1245,6 +1245,7 @@ of SBCL which maintained the CMU-CL-style split into two packages.)")
"UNLOAD-SHARED-OBJECT"
"UNSIGNED"
"UNSIGNED-CHAR" "UNSIGNED-INT" "UNSIGNED-LONG" "UNSIGNED-LONG-LONG" "UNSIGNED-SHORT"
"WORD" "SIGNED-WORD"
"UTF8-STRING"
"VALUES"
"VOID"

View file

@ -178,11 +178,10 @@
(sb-sys:with-pinned-objects (packed-int result)
;; Now exercise the C unpacker.
;; This hack of allocating 4 longs is terrible, but whatever.
(let ((unpacker (make-alien (signed #.sb-vm:n-word-bits) 4))
(let ((unpacker (make-alien word 4))
(prev-loc 0))
(alien-funcall (extern-alien "varint_unpacker_init"
(function void (* long)
(unsigned #.sb-vm:n-word-bits)))
(function void (* word) word))
unpacker
(sb-kernel:get-lisp-obj-address packed-int))
(sb-int:collect ((unpacked))
@ -190,7 +189,7 @@
(let ((status
(alien-funcall
(extern-alien "varint_unpack"
(function int (* long) system-area-pointer))
(function int (* word) system-area-pointer))
unpacker (sb-sys:vector-sap result))))
(let ((val (aref result 0)))
;; status of 0 is EOF, val = 0 means a decoded value was 0,