From f461d9f67d34c4aeb62b3543ed66b232918838b8 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 16 Feb 2012 19:24:53 -0700 Subject: [PATCH] ffi: fix `_x-pointer/null' when `_x' has a supertype This is more specifically a bug in `_cpointer/null', but it shows up most easily through C structs. --- collects/ffi/unsafe.rkt | 5 ++++- collects/tests/racket/cstruct.rktl | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/collects/ffi/unsafe.rkt b/collects/ffi/unsafe.rkt index 669eaffabc..83f54aecd7 100644 --- a/collects/ffi/unsafe.rkt +++ b/collects/ffi/unsafe.rkt @@ -1105,7 +1105,10 @@ (if (cpointer? p) (and p (if (cpointer-has-tag? p t) p (error* p))) (error* p)))) - (make-ctype (or ptr-type _pointer) + (make-ctype (cond + [(and nullable? ptr-type) (_or-null ptr-type)] + [ptr-type] + [else _pointer]) ;; bad hack: `if's outside the lambda for efficiency (if nullable? (if scheme->c diff --git a/collects/tests/racket/cstruct.rktl b/collects/tests/racket/cstruct.rktl index f5eb8a9046..2a99547ef5 100644 --- a/collects/tests/racket/cstruct.rktl +++ b/collects/tests/racket/cstruct.rktl @@ -20,6 +20,8 @@ (test '(4 5 6) tri->list tv2) (test '(4 5 6) tri->list* tv2) (test '(7 8 9) tri->list* (list*->tri '(7 8 9))) + (test #f cast #f _tri-pointer/null _pointer) + (test #f cast #f _pointer _tri-pointer/null) (test #t tri? tv) (test #f tri? 'tv) (test #f tri? (cast 1 _intptr _pointer)) @@ -40,6 +42,8 @@ (test #f tri? 'tv) (test #f tri? (cast 1 _intptr _pointer)) (q-more qv) + (test #f cast #f _quad-pointer/null _pointer) + (test #f cast #f _pointer _quad-pointer/null) (define-cstruct _quint ([pre _quad] [r _float]))