ffi: extend _list and _vector to support zero-length output

This commit is contained in:
Siddharth Agarwal 2012-03-16 00:08:09 +05:30 committed by Matthew Flatt
parent 0cfb3f1d39
commit a73b9bb788
2 changed files with 6 additions and 4 deletions

View File

@ -923,7 +923,8 @@
;; (_list <mode> <type> [<len>])
;; Similar to _ptr, except that it is used for converting lists to/from C
;; vectors. The length is needed for output values where it is used in the
;; post code, and in the pre code of an output mode to allocate the block. In
;; post code, and in the pre code of an output mode to allocate the block. (If
;; the length is 0, then NULL is passed in and an empty list is returned.) In
;; any case it can refer to a previous binding for the length of the list which
;; the C function will most likely require.
(provide _list)
@ -932,7 +933,7 @@
[(_ i t ) (type: _pointer
pre: (x => (list->cblock x t)))]
[(_ o t n) (type: _pointer
pre: (malloc n t)
pre: (if (zero? n) #f (malloc n t))
post: (x => (cblock->list x t n)))]
[(_ io t n) (type: _pointer
pre: (x => (list->cblock x t))
@ -946,7 +947,7 @@
[(_ i t ) (type: _pointer
pre: (x => (vector->cblock x t)))]
[(_ o t n) (type: _pointer
pre: (malloc n t)
pre: (if (zero? n) #f (malloc n t))
post: (x => (cblock->vector x t n)))]
[(_ io t n) (type: _pointer
pre: (x => (vector->cblock x t))

View File

@ -784,7 +784,8 @@ A @tech{custom function type} that is similar to @racket[_ptr], except
that it is used for converting lists to/from C vectors. The optional
@racket[maybe-len] argument is needed for output values where it is used in
the post code, and in the pre code of an output mode to allocate the
block. In either case, it can refer to a previous binding for the
block. (If the length is 0, then NULL is passed in and an empty list is
returned.) In either case, it can refer to a previous binding for the
length of the list which the C function will most likely require.}
@defform[(_vector mode type maybe-len)]{