Fixing the load interface

This commit is contained in:
2025-01-31 12:15:36 +02:00
parent efad73ac55
commit 19c9c3f802
22 changed files with 104 additions and 68 deletions
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-size-of
(lambda (type)
(cond ((eq? type 'int8) (size-of-int8_t))
-5
View File
@@ -1,8 +1,3 @@
(define-syntax pffi-init
(er-macro-transformer
(lambda (expr rename compare)
'(import (chicken foreign)
(chicken memory)))))
(define pffi-type->native-type
(lambda (type)
-6
View File
@@ -1,9 +1,3 @@
(define-syntax pffi-init
(er-macro-transformer
(lambda (expr rename compare)
'(import (chicken foreign)
(chicken memory)))))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) 'byte)
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) int)
-2
View File
@@ -1,7 +1,5 @@
(c-declare "#include <stdint.h>")
(define pffi-init (lambda () #t))
;(c-declare "int size_of_int8() { return sizeof(int8_t);}")
;(define size-of-int8 (c-lambda () int "__return(sizeof(int8_t));"))
;(define int8-size ((c-lambda () int "__return(sizeof(int8_t));")))
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-size-of
(lambda (type)
(cond ((equal? type 'int8) 1))))
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(error "Not defined")))
-3
View File
@@ -1,6 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) int8)
-6
View File
@@ -2,8 +2,6 @@
(define method-handle-lookup (invoke-static java.lang.invoke.MethodHandles 'lookup))
(define native-linker (invoke-static java.lang.foreign.Linker 'nativeLinker))
(define pffi-init (lambda () #t))
(define value->object
(lambda (value type)
(cond ((equal? type 'byte)
@@ -136,10 +134,6 @@
(lambda (pointer)
(invoke pointer 'get (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 1) 0)))
(define pffi-pointer-dereference
(lambda (pointer)
(invoke pointer 'get (invoke (static-field java.lang.foreign.ValueLayout 'ADDRESS) 'withByteAlignment 1) 0)))
(define pffi-pointer-null
(lambda ()
(static-field java.lang.foreign.MemorySegment 'NULL)))
-2
View File
@@ -1,7 +1,5 @@
(require 'std-ffi)
(define pffi-init (lambda () #t))
;; FIXME
(define pffi-size-of
(lambda (type)
-2
View File
@@ -1,2 +0,0 @@
+52 -7
View File
@@ -1,3 +1,26 @@
(define debug? #f)
(define (debug msg value)
(display "[R7RS-PFFI DEBUG] ")
(display msg)
(display ": ")
(write value)
(newline))
(cond-expand
((or chicken5 chicken6)
(define-syntax pffi-init
(er-macro-transformer
(lambda (expr rename compare)
'(import (chicken foreign)
(chicken memory))))))
(else
(define (pffi-init . options)
(when (and (assoc 'debug? (car options))
(cdr (assoc 'debug? (car options))))
(set! debug? #t))
#t)))
;(when (not debug?) (set! debug (lambda (msg value) #t)))
(define pffi-types
'(int8
@@ -45,21 +68,32 @@
(cond-expand
(gambit
(define-macro
(pffi-shared-object-auto-load headers additional-paths object-name additional-versions)
(pffi-shared-object-auto-load headers object-name options)
`(pffi-shared-object-load ,(car headers))))
(cyclone
(define-syntax pffi-shared-object-auto-load
(syntax-rules ()
((pffi-shared-object-auto-load headers additional-paths object-name additional-versions)
((pffi-shared-object-auto-load headers object-name)
(pffi-shared-object-auto-load headers object-name (list)))
((pffi-shared-object-auto-load headers object-name options)
(pffi-shared-object-load headers)))))
(else
(define-syntax pffi-shared-object-auto-load
(syntax-rules ()
((pffi-shared-object-auto-load headers additional-paths object-name additional-versions)
((pffi-shared-object-auto-load headers object-name)
(pffi-shared-object-auto-load headers object-name (list)))
((pffi-shared-object-auto-load headers object-name options)
(cond-expand
(chicken (pffi-shared-object-load headers))
(else
(let* ((slash (cond-expand (windows (string #\\)) (else "/")))
(debug "Options given" options)
(let* ((additional-paths (if (assoc 'additional-paths options)
(cadr (assoc 'additional-paths options))
(list)))
(additional-versions (if (assoc 'additional-versions options)
(cadr (assoc 'additional-versions options))
(list)))
(slash (cond-expand (windows (string #\\)) (else "/")))
(auto-load-paths
(cond-expand
(windows
@@ -131,8 +165,11 @@
(windows ".dll")
(else ".so")))
(shared-object #f))
(debug "Auto load paths" paths)
(debug "Auto load versions" versions)
(for-each
(lambda (path)
(debug "Checking path" path)
(for-each
(lambda (version)
(let ((library-path (string-append path
@@ -140,9 +177,17 @@
platform-lib-prefix
object-name
platform-file-extension
version)))
(if (file-exists? library-path)
(set! shared-object library-path))))
version))
(library-path-without-suffixes (string-append path
slash
platform-lib-prefix
object-name)))
(debug "Checking if library exists in" library-path)
(when (file-exists? library-path)
(debug "Library exists, setting to be loaded" library-path)
(cond-expand
(racket (set! shared-object library-path-without-suffixes))
(else (set! shared-object library-path))))))
versions))
paths)
(if (not shared-object)
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-size-of
(lambda (type)
(cond ((eq? type 'int8) 1)
+5 -4
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) _int8)
@@ -76,8 +74,11 @@
(string-copy (cast pointer _pointer _string))))
(define pffi-shared-object-load
(lambda (header path)
(ffi-lib path)))
(lambda (header path . options)
(if (and (not (null? options))
(assoc 'versions (car options)))
(ffi-lib path (mlist->list (append (cadr (assoc 'versions (car options))) (list #f))))
(ffi-lib path))))
(define pffi-pointer-free
(lambda (pointer)
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) 'int8_t)
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-size-of
(lambda (type)
(cond ((equal? type 'int8) 1))))
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-type->native-type
(lambda (type)
(cond ((equal? type 'int8) :int)
-2
View File
@@ -1,5 +1,3 @@
(define pffi-init (lambda () #t))
(define pffi-size-of
(lambda (type)
(cond ((equal? type 'int8) 1))))
-1
View File
@@ -1 +0,0 @@
(define pffi-init (lambda () #t))