You are using the `___U8VECTORLENGTH` macro and friends incorrectly. They return a fixnum but your `c-lambda`s return `size_t`… so you want to say `___INT(___U8VECTORLENGTH(___arg1))` which converts the fixnum to an `int`, or use `scheme-object` instead of `size_t` as the return type of the `c-lambda`s.
Marc
On Aug 9, 2020, at 10:09 AM, Lassi Kortela lassi@lassi.io wrote:
What causes the following?
;;; Code:
(define (disp . xs) (for-each display xs) (newline))
(define-syntax show (syntax-rules () ((_ x) (begin (write 'x) (display " => ") (write x) (newline)))))
(define try-as-u8 (c-lambda (scheme-object) size_t "___return(___U8VECTORLENGTH(___arg1));"))
(define try-as-u16 (c-lambda (scheme-object) size_t "___return(___U16VECTORLENGTH(___arg1));"))
(define try-as-u32 (c-lambda (scheme-object) size_t "___return(___U32VECTORLENGTH(___arg1));"))
(define try-as-u64 (c-lambda (scheme-object) size_t "___return(___U64VECTORLENGTH(___arg1));"))
(define n 1024) (disp "u8vector of " n " elements") (let ((v (make-u8vector n))) (show (try-as-u8 v)) (show (try-as-u16 v)) (show (try-as-u32 v)) (show (try-as-u64 v))) (newline) (disp "u16vector of " n " elements") (let ((v (make-u16vector n))) (show (try-as-u8 v)) (show (try-as-u16 v)) (show (try-as-u32 v)) (show (try-as-u64 v))) (newline) (disp "u32vector of " n " elements") (let ((v (make-u32vector n))) (show (try-as-u8 v)) (show (try-as-u16 v)) (show (try-as-u32 v)) (show (try-as-u64 v)))
;;; Output:
u8vector of 1024 elements (try-as-u8 v) => 4096 (try-as-u16 v) => 2048 (try-as-u32 v) => 1024 (try-as-u64 v) => 512
u16vector of 1024 elements (try-as-u8 v) => 8192 (try-as-u16 v) => 4096 (try-as-u32 v) => 2048 (try-as-u64 v) => 1024
u32vector of 1024 elements (try-as-u8 v) => 16384 (try-as-u16 v) => 8192 (try-as-u32 v) => 4096 (try-as-u64 v) => 2048
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list