chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] FFI Question


From: Heath Johns
Subject: Re: [Chicken-users] FFI Question
Date: Mon, 8 May 2006 09:59:01 -0700

Thank you, Thomas and Felix, for answering my question :)

Heath


On 07/05/06, felix winkelmann <address@hidden> wrote:
On 5/4/06, Heath Johns <address@hidden> wrote:

> I've got a noob question: Why does this segfault?  Should I be doing
> this differently?  I'm using 2.3 stable on linux...

Hi!

No noob question at all. You've found a genuine bug: the result
type conversion didn't  do the right thing for null pointers (#f).
Here is a patch to compiler.scm:

891,893c891,900
<                                              ,@(if (memq rtype 
'(nonnull-c-string c-string))
<                                                    `((##sys#make-c-string 
(let () ,@(cddr lam))))
<                                                    (cddr lam)) )
---
>                                              ,@(case rtype
>                                                  ((nonnull-c-string) 
`((##sys#make-c-string (let () ,@(cddr lam)))))
>                                                  ((c-string*)
>                                                   (##sys#syntax-error-hook
>                                                    "`c-string*' is not a valid 
resulte type for callback procedures"
>                                                    name) )
>                                                  ((c-string)
>                                                   `((let ((r (let () ,@(cddr 
lam))))
>                                                       (and r 
(##sys#make-c-string r)) ) ) )
>                                                  (else (cddr lam)) ) )

BTW, I recommend using `define-external' (as suggested by Thomas).
In fact I undocumented `foreign-safe-wrapper' and it wil be
deprecated in future releases, since it is kludgy and not really
useful.

(that c-string* works is a mere coincedence - the special treatment of
strings as callback-results didn't take `c-string*' into account).

Thanks for reporting this!


(felix)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]