File tree Expand file tree Collapse file tree 7 files changed +27
-8
lines changed
Expand file tree Collapse file tree 7 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ PFFI is a portable foreign function interface for R6RS Scheme implementations.
2020- ` define-type-alias ` is introduced, similar usage as ` typedef ` in C.
2121- ` boolean ` support for Scheme boolean.
2222- Supporting array foreign variable.
23+ - Empty struct, i.e. ` (define-foreign-struct foo) ` , is supported
2324
2425## Example
2526
Original file line number Diff line number Diff line change 204204
205205(define-syntax callback
206206 (syntax-rules ()
207+ ((_ (conv ...) ret (args ...))
208+ (_cprocedure
209+ (->immutable-list (list (ffi-type-descriptor-alias args) ...))
210+ (ffi-type-descriptor-alias ret)))
207211 ((_ ret (args ...))
208212 (_cprocedure
209213 (->immutable-list (list (ffi-type-descriptor-alias args) ...))
210214 (ffi-type-descriptor-alias ret)))))
215+
211216(define-ftype void _void)
212217
213218(define (open-shared-object path )
Original file line number Diff line number Diff line change 4545 (lambda (x )
4646 (define (register-type-alias! name alias )
4747 (hashtable-set! *typedef-table* name alias))
48- (syntax-case x (*)
48+ (syntax-case x (* callback )
4949 ((_ name (* alias))
5050 (register-type-alias! (syntax->datum #'name ) 'void* )
5151 #' (define-ftype name void*))
52+ ((_ name (callback (conv ...) ret (args ...)))
53+ (register-type-alias! (syntax->datum #'name ) (syntax->datum 'void* ))
54+ #' (define-ftype name void*))
55+ ((_ name (callback ret (args ...)))
56+ (register-type-alias! (syntax->datum #'name ) 'void* )
57+ #' (define-ftype name void*))
5258 ((_ name alias)
5359 (register-type-alias! (syntax->datum #'name ) (syntax->datum #'alias ))
5460 #' (define-ftype name alias)))))
Original file line number Diff line number Diff line change 3434 (import (only (rnrs) define-syntax syntax-rules define *)
3535 (only (srfi :13) string-map)
3636 (only (srfi :1) take drop drop-right split-at)
37- (only (pffi compat) pointer))
37+ (only (pffi compat) pointer callback ))
3838
3939(define-syntax define-type-alias
40- (syntax-rules (*)
40+ (syntax-rules (* callback )
4141 ((_ name (* alias)) (define name pointer))
4242 ((_ name alias) (define name alias))))
4343
Original file line number Diff line number Diff line change 193193 t))
194194
195195(define (struct-alignment lis )
196- (apply max (map (lambda (l )
197- (if (foreign-struct-descriptor? l)
198- (generic-foreign-struct-descriptor-alignment l)
199- (type-descriptor-size l))) lis)))
196+ (if (null? lis)
197+ 0
198+ (apply max (map (lambda (l )
199+ (if (foreign-struct-descriptor? l)
200+ (generic-foreign-struct-descriptor-alignment l)
201+ (type-descriptor-size l))) lis))))
200202
201203; ; ref
202204; ; http://en.wikipedia.org/wiki/Data_structure_alignment
Original file line number Diff line number Diff line change 6666 x (car fields))))))
6767 (let loop ((clauses clauses) (fs #f ) (par #f ) (proto #f ) (align #f ))
6868 (syntax-case clauses (fields parent protocol alginment)
69- (() (list fs par proto align))
69+ (() (list ( or fs '() ) par proto align))
7070 (((fields defs (... ...)) . rest)
7171 (or (not fs)
7272 (syntax-violation who " only one fields clause allowed" x
Original file line number Diff line number Diff line change 382382 (test-equal " count p-st" 10 (st-parent-count st))))
383383
384384
385+ ; ; empty struct
386+ (let ()
387+ (define-foreign-struct ok)
388+ (test-equal " size of empty struct" 0 size-of-ok))
389+
385390(test-end)
You can’t perform that action at this time.
0 commit comments