Summary

(const c-string) as result type breaks with NULL

Metadata

Description

I'm writing bindings to a library which uses `const` on both string argument and return types. If I declare a foreign function returning `NULL` to have `(const c-string)` as return type, I get a segmentation violation, `c-string` as return type however returns `#f` as expected.

Minimal repro:

 (import chicken scheme foreign)
 
 #> static const char* test() { return NULL; } <#
 
 (define test (foreign-lambda c-string "test"))
 (define test2 (foreign-lambda (const c-string) "test"))
 
 (test) ;=> #f
 (test2) ;=> segfault

Changes and comments

[2017-11-09 14:10:10 UTC] wasamasa wrote:

FWIW, the C4 patch resolves the issue for me. The C5 one also works as intended, before I got a "cannot compute size of location for foreign type" error.

[2017-11-09 14:10:10 UTC] wasamasa wrote:

1510233053854813

[2017-11-09 14:10:10 UTC] wasamasa wrote:

1510234341587080

[2017-11-11 21:59:54 UTC] evhan changed status from new to closed

[2017-11-11 21:59:54 UTC] evhan set resolution to fixed

[2017-11-11 21:59:54 UTC] evhan wrote:

Fixed with a0bb345 and c3393980.