Fixing the pffi-type? and size-of

This commit is contained in:
retropikzel 2025-02-18 19:20:05 +02:00
parent 7b12ab40cb
commit 24cdacfcef
6 changed files with 29 additions and 9 deletions

View File

@ -20,9 +20,10 @@
((equal? type 'double) double)
((equal? type 'pointer) '*)
((equal? type 'void) void)
((equal? type 'string) '*)
((equal? type 'callback) '*)
((equal? type 'struct) '*)
(else (error "pffi-type->native-type -- No such pffi type" type)))))
(else #f))))
(define pffi-pointer?
(lambda (object)
@ -47,7 +48,10 @@
(define size-of-type
(lambda (type)
(sizeof (pffi-type->native-type type))))
(let ((native-type (pffi-type->native-type type)))
(cond ((equal? native-type void) 0)
(native-type (sizeof native-type))
(else #f)))))
(define pffi-pointer-allocate
(lambda (size)

View File

@ -48,10 +48,11 @@
((equal? type 'float) (invoke (static-field java.lang.foreign.ValueLayout 'JAVA_FLOAT) 'withByteAlignment 4))
((equal? type 'double) (invoke (static-field java.lang.foreign.ValueLayout 'JAVA_DOUBLE) 'withByteAlignment 8))
((equal? type 'pointer) (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 8))
((equal? type 'string) (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 8))
((equal? type 'void) (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 1))
((equal? type 'callback) (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 8))
((equal? type 'struct) (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 8))
(else (error "pffi-type->native-type -- No such pffi type" type)))))
(else #f))))
(define pffi-pointer?
(lambda (object)
@ -125,7 +126,10 @@
(define size-of-type
(lambda (type)
(invoke (pffi-type->native-type type) 'byteAlignment)))
(let ((native-type (pffi-type->native-type type)))
(if native-type
(invoke native-type 'byteAlignment)
#f))))
(define pffi-pointer-allocate
(lambda (size)

View File

@ -9,7 +9,10 @@
(define pffi-init
(lambda () #t))))
(define (pffi-type? object) (if (equal? (size-of-type object) #f) #f #t))
(define (pffi-type? object)
(if (equal? (size-of-type object) #f)
#f
#t))
(define (pffi-size-of object)
(cond ((pffi-struct? object) (pffi-struct-size object))

View File

@ -19,7 +19,10 @@
((eq? type 'float) size-of-float)
((eq? type 'double) size-of-double)
((eq? type 'pointer) size-of-pointer)
(else (error "Can not get size of unknown type" type)))))
((eq? type 'string) size-of-pointer)
((eq? type 'callback) size-of-pointer)
((eq? type 'void) 0)
(else #f))))
(define pffi-shared-object-load
(lambda (header path . options)

View File

@ -21,8 +21,9 @@
((equal? type 'pointer) _pointer)
((equal? type 'void) _void)
((equal? type 'callback) _pointer)
((equal? type 'string) _pointer)
((equal? type 'struct) _pointer)
(else (error "pffi-type->native-type -- No such pffi type" type)))))
(else #f))))
(define pffi-pointer?
(lambda (object)
@ -47,7 +48,10 @@
(define size-of-type
(lambda (type)
(ctype-sizeof (pffi-type->native-type type))))
(let ((native-type (pffi-type->native-type type)))
(if native-type
(ctype-sizeof native-type)
#f))))
(define pffi-pointer-allocate
(lambda (size)

View File

@ -23,7 +23,7 @@
((equal? type 'void) 'void)
((equal? type 'callback) 'callback)
((equal? type 'struct) 'void*)
(else (error "pffi-type->native-type -- No such pffi type" type)))))
(else #f))))
(define pffi-pointer?
(lambda (object)
@ -68,7 +68,9 @@
((eq? type 'float) size-of-float)
((eq? type 'double) size-of-double)
((eq? type 'pointer) size-of-void*)
((eq? type 'void) 0)
((eq? type 'string) size-of-void*)
((eq? type 'callback) size-of-void*)
(else #f))))
(define pffi-pointer-allocate