rktio: header and extraction improvements for FFI

This commit is contained in:
Matthew Flatt 2017-06-29 14:32:14 -06:00
parent 63146e5451
commit af7a520102
2 changed files with 19 additions and 15 deletions

View File

@ -24,8 +24,8 @@
;; => fails when result equals <err-v>, keep step
;;
;; <type> = <prim-type>
;; | (ref <type>) ; opaque, needs to be deallocated somehow
;; | (* <type>) ; transparent argument, can be represented by a byte string
;; | (ref <type>) ; opaque, needs to be deallocated somehow
;; | (*ref <type>) ; transparent argument, can be represented by a byte string
(define output-file #f)
@ -138,7 +138,7 @@
(append (map (lambda (id) `(,(shift-stars id $1) ,(unstar id))) $2)
$3)])
(<id> [(ID) $1]
[(STAR <id>) `(* ,$2)])
[(STAR <id>) `(*ref ,$2)])
(<ids> [(<id> SEMI) (list $1)]
[(<id> COMMA <ids>) (cons $1 $3)])
(<expr> [(ID) $1]
@ -162,19 +162,20 @@
[(eq? r 'rktio_bool_t) '(define-function)]
[(eq? r 'void) '(define-function)]
[(pair? def-kind) def-kind]
[(pair? r) '(define-function/errno NULL)]
[(eq? r 'rktio_ok_t) '(define-function/errno #f)]
[(eq? def-kind 'define-function) (list def-kind)]
[(pair? r) `(,def-kind NULL)]
[(eq? r 'rktio_ok_t) `(,def-kind #f)]
[else (list def-kind)]))
(define (shift-stars from to)
(if (and (pair? from)
(eq? '* (car from)))
`(* ,(shift-stars (cadr from) to))
(eq? '*ref (car from)))
`(*ref ,(shift-stars (cadr from) to))
to))
(define (unstar from)
(if (and (pair? from)
(eq? '* (car from)))
(eq? '*ref (car from)))
(unstar (cadr from))
from))
@ -244,12 +245,12 @@
;; explicitly freed.
(define (update-type t #:as-argument? [as-argument? #f])
(cond
[(and (pair? t) (eq? (car t) '*))
[(and (pair? t) (eq? (car t) '*ref))
(let ([s (update-type (cadr t))])
(if (and as-argument?
(or (pair? s)
(hash-ref defined-types s #f)))
`(* ,s)
`(*ref ,s)
`(ref ,s)))]
[else t]))
@ -261,6 +262,9 @@
[`(,def ,ret ,name ,args)
`(,def ,(update-type ret) ,name
,(map (lambda (a) (update-bind a #:as-argument? #t)) args))]
[`(,def ,err-val ,ret ,name ,args)
`(,def ,err-val ,(update-type ret) ,name
,(map (lambda (a) (update-bind a #:as-argument? #t)) args))]
[else e]))
(define (update-type-types e)

View File

@ -728,7 +728,7 @@ RKTIO_EXTERN rktio_bool_t rktio_is_regular_file(rktio_t *rktio, const char *file
RKTIO_EXTERN rktio_ok_t rktio_delete_file(rktio_t *rktio, const char *fn, rktio_bool_t enable_write_on_fail);
RKTIO_EXTERN rktio_ok_t rktio_rename_file(rktio_t *rktio, const char *dest, const char *src, int exists_ok);
RKTIO_EXTERN rktio_ok_t rktio_rename_file(rktio_t *rktio, const char *dest, const char *src, rktio_bool_t exists_ok);
/* Can report `RKTIO_ERROR_EXISTS`. */
RKTIO_EXTERN char *rktio_get_current_directory(rktio_t *rktio);
@ -738,7 +738,7 @@ RKTIO_EXTERN rktio_ok_t rktio_make_directory(rktio_t *rktio, const char *filenam
/* Can report `RKTIO_ERROR_EXISTS`. */
RKTIO_EXTERN rktio_ok_t rktio_delete_directory(rktio_t *rktio, const char *filename, const char *current_directory,
int enable_write_on_fail);
rktio_bool_t enable_write_on_fail);
/* The `current_directory` argument is used on Windows to avoid being
in `filename` (instead) as a directory while trying to delete it.
The `enable_write_on_fail` argument also applied to Windows. */
@ -748,7 +748,7 @@ RKTIO_EXTERN char *rktio_readlink(rktio_t *rktio, const char *fullfilename);
`RKTIO_ERROR_NOT_A_LINK`. */
RKTIO_EXTERN rktio_ok_t rktio_make_link(rktio_t *rktio, const char *src, const char *dest,
int dest_is_directory);
rktio_bool_t dest_is_directory);
/* The `dest_is_directory` argument is used only
on Windows. Can report `RKTIO_ERROR_EXISTS`. */
@ -768,7 +768,7 @@ typedef struct rktio_identity_t {
} rktio_identity_t;
RKTIO_EXTERN rktio_identity_t *rktio_fd_identity(rktio_t *rktio, rktio_fd_t *fd);
RKTIO_EXTERN rktio_identity_t *rktio_path_identity(rktio_t *rktio, const char *path, int follow_links);
RKTIO_EXTERN rktio_identity_t *rktio_path_identity(rktio_t *rktio, const char *path, rktio_bool_t follow_links);
/*************************************************/
/* Permissions */
@ -781,7 +781,7 @@ RKTIO_EXTERN rktio_identity_t *rktio_path_identity(rktio_t *rktio, const char *p
#define RKTIO_PERMISSION_ERROR (-1)
RKTIO_EXTERN_ERR(RKTIO_PERMISSION_ERROR)
int rktio_get_file_or_directory_permissions(rktio_t *rktio, const char *filename, int all_bits);
int rktio_get_file_or_directory_permissions(rktio_t *rktio, const char *filename, rktio_bool_t all_bits);
/* Result is `RKTIO_PERMISSION_ERROR` for error, otherwise a combination of
bits. If not `all_bits`, then use constants above. */