From a73b9bb7883c699894b5befcb2aa11f5ea8c358c Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Fri, 16 Mar 2012 00:08:09 +0530 Subject: [PATCH] ffi: extend _list and _vector to support zero-length output --- collects/ffi/unsafe.rkt | 7 ++++--- collects/scribblings/foreign/types.scrbl | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/collects/ffi/unsafe.rkt b/collects/ffi/unsafe.rkt index fd2151bd95..ea0f9e314c 100644 --- a/collects/ffi/unsafe.rkt +++ b/collects/ffi/unsafe.rkt @@ -923,7 +923,8 @@ ;; (_list []) ;; 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)) diff --git a/collects/scribblings/foreign/types.scrbl b/collects/scribblings/foreign/types.scrbl index 7612febdc8..40985f227e 100644 --- a/collects/scribblings/foreign/types.scrbl +++ b/collects/scribblings/foreign/types.scrbl @@ -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)]{