Skip to content

Commit 6032475

Browse files
committed
Handling with new feature of Sagittarius
1 parent 6eb8c97 commit 6032475

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed

src/pffi/compat.sagittarius.sls

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -155,58 +155,73 @@
155155
(int64_t ffi:int64_t)
156156
(uint64_t ffi:uint64_t)
157157
(wchar_t ffi:wchar_t)
158-
(pointer-ref-c-wchar ffi:pointer-ref-c-wchar ffi:)
158+
(pointer-ref-c-wchar ffi:pointer-ref-c-wchar)
159159
(pointer-set-c-wchar! ffi:pointer-set-c-wchar!))
160160
(pffi ffi-type-descriptor)
161161
(srfi :1))
162162

163-
(define (->native-type type)
164-
(cond ((ffi-type-descriptor? type)
165-
(let ((alias (ffi-type-descriptor-alias type)))
166-
(if (eq? alias ffi:wchar_t)
167-
(case size-of-wchar_t
168-
((2) ffi:uint16_t)
169-
((4) ffi:uint32_t))
170-
alias)))
171-
(else type)))
163+
(cond-expand
164+
;; proper wchar_t support is from 0.9.13
165+
((and cond-expand.version (version (>= "0.9.13")))
166+
(define (->native-type type)
167+
(cond ((ffi-type-descriptor? type) (ffi-type-descriptor-alias type))
168+
(else type)))
169+
(define (make-c-function lib conv ret name args)
170+
(%make-c-function lib (->native-type ret) name (map ->native-type args)))
171+
172+
(define (make-c-callback ret args proc)
173+
(%make-c-callback (->native-type ret) (map ->native-type args) proc))
174+
)
175+
;; other versions must have workaround
176+
(else
177+
(define (->native-type type)
178+
(cond ((ffi-type-descriptor? type)
179+
(let ((alias (ffi-type-descriptor-alias type)))
180+
(if (eq? alias ffi:wchar_t)
181+
(case size-of-wchar_t
182+
((2) ffi:uint16_t)
183+
((4) ffi:uint32_t))
184+
alias)))
185+
(else type)))
172186

173-
(define (convert-arg type arg)
174-
(cond ((ffi-type-descriptor? type)
175-
(let ((alias (ffi-type-descriptor-alias type)))
176-
(if (eq? alias ffi:wchar_t)
177-
(char->integer arg)
178-
arg)))
179-
((eq? type ffi:wchar_t) (char->integer arg))
180-
(else arg)))
181-
(define (convert-arg/guess arg)
182-
(if (char? arg)
183-
(char->integer arg)
184-
arg))
185-
(define (convert-ret type r)
186-
(cond ((ffi-type-descriptor? type)
187-
(let ((alias (ffi-type-descriptor-alias type)))
188-
(if (eq? alias ffi:wchar_t)
189-
(integer->char r)
190-
r)))
191-
((eq? type ffi:wchar_t) (integer->char r))
192-
(else r)))
193-
(define (make-c-function lib conv ret name args)
194-
(let ((proc (%make-c-function lib (->native-type ret) name
195-
(map ->native-type args))))
196-
(if (memq '___ args)
197-
(lambda formal
198-
(let ((n (- (length args) 1)))
199-
(let-values (((req opts) (split-at formal n)))
200-
(convert-ret ret
201-
(apply proc (append! (map convert-arg args req)
202-
(map convert-arg/guess opts)))))))
203-
(lambda formal
204-
(convert-ret ret (apply proc (map convert-arg args formal)))))))
187+
(define (convert-arg type arg)
188+
(cond ((ffi-type-descriptor? type)
189+
(let ((alias (ffi-type-descriptor-alias type)))
190+
(if (eq? alias ffi:wchar_t)
191+
(char->integer arg)
192+
arg)))
193+
((eq? type ffi:wchar_t) (char->integer arg))
194+
(else arg)))
195+
(define (convert-arg/guess arg)
196+
(if (char? arg)
197+
(char->integer arg)
198+
arg))
199+
(define (convert-ret type r)
200+
(cond ((ffi-type-descriptor? type)
201+
(let ((alias (ffi-type-descriptor-alias type)))
202+
(if (eq? alias ffi:wchar_t)
203+
(integer->char r)
204+
r)))
205+
((eq? type ffi:wchar_t) (integer->char r))
206+
(else r)))
207+
(define (make-c-function lib conv ret name args)
208+
(let ((proc (%make-c-function lib (->native-type ret) name
209+
(map ->native-type args))))
210+
(if (memq '___ args)
211+
(lambda formal
212+
(let ((n (- (length args) 1)))
213+
(let-values (((req opts) (split-at formal n)))
214+
(convert-ret ret
215+
(apply proc (append! (map convert-arg args req)
216+
(map convert-arg/guess opts)))))))
217+
(lambda formal
218+
(convert-ret ret (apply proc (map convert-arg args formal)))))))
205219

206-
(define (make-c-callback ret args proc)
207-
(define (wrapped . args*)
208-
(convert-arg ret (apply proc (map convert-ret args args*))))
209-
(%make-c-callback (->native-type ret) (map ->native-type args) wrapped))
220+
(define (make-c-callback ret args proc)
221+
(define (wrapped . args*)
222+
(convert-arg ret (apply proc (map convert-ret args args*))))
223+
(%make-c-callback (->native-type ret) (map ->native-type args) wrapped))
224+
))
210225

211226
(define-syntax callback
212227
(syntax-rules ()

0 commit comments

Comments
 (0)