Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Racket: Add yuniffi compat definitions
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(library (racket-yuni compat ffi primitives) | ||
(export yuniffi-nccc-call | ||
yuniffi-module-load | ||
yuniffi-module-lookup) | ||
(import (yuni scheme) | ||
;; Some of definitions are placed in runtime | ||
;; because we need to use keywords and other Racket specific | ||
;; notations. | ||
(yuni-runtime racket-ffi) | ||
(ffi unsafe)) | ||
|
||
;; | ||
|
||
(define (yuniffi-nccc-call func | ||
in in-offset in-size | ||
out out-offset out-size) | ||
;; Bytevector is byte string in Racket. So we don't have to convert them. | ||
(define inp (and in (ptr-add in (* in-offset 8)))) | ||
(define outp (and out (ptr-add out (* out-offset 8)))) | ||
(func inp in-size outp out-size)) | ||
|
||
(define (yuniffi-module-load path) | ||
(ffi-lib path)) | ||
|
||
|
||
(define (yuniffi-module-lookup handle str) | ||
;; nccc-func is defined in (yuni-runtime racket-ffi) | ||
(get-ffi-obj str handle nccc-func | ||
;; Failure thunk | ||
(lambda () #f))) | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!r6rs | ||
(library (yuni-runtime racket-ffi) | ||
(export nccc-func) | ||
(import (rnrs) | ||
(ffi unsafe)) | ||
(define nccc-func | ||
(_fun _gcpointer _int _gcpointer _int -> _void)) | ||
|
||
) |