Hi,
Here are some fixes that will result in more specific scrutinizer
annotations, and removes some spurious type warnings (0003).
>From 42657f466937e2dcaf19b385eed31ed27fda0dbd Mon Sep 17 00:00:00 2001
From: megane
Date: Sat, 22 May 2021 07:47:53 +0300
Subject: [PATCH 1/4] FFI: Make scrutinizer not allow #t where nullable value
is expected
E.g. annotate (foreign-lambda* void ((blob x)) "return;") with
((or false blob) -> undefined)
instead of current
((or boolean blob) -> undefined)
---
support.scm | 12 ++--
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/support.scm b/support.scm
index b56b7d00..19702271 100644
--- a/support.scm
+++ b/support.scm
@@ -1363,17 +1363,17 @@
((scheme-pointer nonnull-scheme-pointer) '*)
((blob)
(case mode
-((arg) '(or boolean blob))
+((arg) '(or false blob))
(else 'blob)))
((nonnull-blob) 'blob)
((pointer-vector)
(case mode
-((arg) '(or boolean pointer-vector))
+((arg) '(or false pointer-vector))
(else 'pointer-vector)))
((nonnull-pointer-vector) 'pointer-vector)
((u8vector u16vector s8vector s16vector u32vector s32vector u64vector
s64vector f32vector f64vector)
(case mode
-((arg) `(or boolean (struct ,ft)))
+((arg) `(or false (struct ,ft)))
(else `(struct ,ft
((nonnull-u8vector) '(struct u8vector))
((nonnull-s8vector) '(struct s8vector))
@@ -1389,10 +1389,10 @@
unsigned-long)
'integer)
((c-pointer)
- '(or boolean pointer locative))
+ '(or false pointer locative))
((nonnull-c-pointer) 'pointer)
((c-string c-string* unsigned-c-string unsigned-c-string*)
- '(or boolean string))
+ '(or false string))
((c-string-list c-string-list*)
'(list-of string))
((nonnull-c-string nonnull-c-string* nonnull-unsigned-c-string*)
'string)
@@ -1401,7 +1401,7 @@
(cond ((pair? t)
(case (car t)
((ref pointer function c-pointer)
-'(or boolean pointer locative))
+'(or false pointer locative))
((const) (foreign-type->scrutiny-type (cadr t) mode))
((enum) 'integer)
((nonnull-pointer nonnull-c-pointer) 'pointer)
--
2.25.1
>From c8e604fc386be2ff163eb1e264748d39983df344 Mon Sep 17 00:00:00 2001
From: megane
Date: Sat, 22 May 2021 07:53:54 +0300
Subject: [PATCH 2/4] FFI: Remove annotation of locative as return type for
c-pointer
The c-pointers are converted to pointers or #f, not locatives.
See foreign-result-conversion
---
support.scm | 8 ++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/support.scm b/support.scm
index 19702271..c7408903 100644
--- a/support.scm
+++ b/support.scm
@@ -1389,7 +1389,9 @@
unsigned-long)
'integer)
((c-pointer)
- '(or false pointer locative))
+ (if (eq? 'arg mode)
+ '(or false pointer locative)
+ '(or false pointer)))
((nonnull-c-pointer) 'pointer)
((c-string c-string* unsigned-c-string unsigned-c-string*)
'(or false string))
@@ -1401,7 +1403,9 @@
(cond ((pair? t)
(case (car t)
((ref pointer function c-pointer)
-'(or false pointer locative))
+(if (eq? 'arg mode)
+'(or false pointer locative)
+'(or false pointer)))
((const) (foreign-type->scrutiny-type (cadr t) mode))
((enum) 'integer)
((nonnull-pointer nonnull-c-pointer) 'pointer)
--
2.25.1
>From 1886d131b20e377b13d032bd3108d590b80d0e51 Mon Sep 17 00:00:00 2001
From: megane
Date: Sat, 22 May 2021 08:13:45 +0300
Subject: [PATCH 3/4] FFI: Make scrutinizer accept locatives for
nonnull-c-pointer arguments
E.g. annotate (foreign-lambda* void ((nonnull-c-pointer x)) "return;")
with
((or pointer locative) -> undefined)
instead of current
(pointer -> undefined)
---
support.scm | 10 --
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/support.scm b/support.scm
index c7408903..7929334c 100644
--- a/support.scm
+++ b/support.scm
@@ -1392,7 +1392,10 @@
(if (eq? 'arg mode)
'(or false pointer locative)
'(or false pointer)))
- ((nonnull-c-pointer) 'pointer)
+ ((nonnull-c-pointer)
+ (if (eq? 'arg mode)
+ '(or pointer locative)
+ 'pointer))
((c-string c-string* unsigned-c-string unsigned-c-string*)
'(or false string))
((c-string-list c-string-list*)
@@ -1408,7 +1411,10 @@
'(or false pointer)))