chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] A more concrete FFI question.


From: Robin Lee Powell
Subject: Re: [Chicken-users] A more concrete FFI question.
Date: Tue, 3 Jul 2007 17:26:54 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

On Tue, Jul 03, 2007 at 05:00:43PM -0700, Robin Lee Powell wrote:
> 
> The following C code (trimmed) works fine:
> 
>     xmmsc_connection_t *connection;
>     xmmsc_result_t *result;
> 
>     unsigned int id;
> 
>     result = xmmsc_playback_current_id (connection);
> 
>     xmmsc_result_wait (result);
> 
>     if (!xmmsc_result_get_uint (result, &id)) {
>           fprintf (stderr, "xmmsc_playback_current_id didn't"
>                   "return uint as expected\n");
>     }
> 
>     printf ("Currently playing id is %d\n", id);
> 
> The following Chicken does not:
> 
> (let-location ([ret unsigned-int 275])
>               (let* (
>                      [res ($ c-pointer xmmsc_broadcast_playback_current_id 
> (c-pointer conn))]
>                      [null ($ void xmmsc_result_wait (pointer res))]

Just for the record, what particularily disturbs me is that if I
replace "(pointer res)" with "(c-pointer res)", things hang.  Since
(pointer ...) appears to be something else entirely, I'm not at all
certain what my code actually *does*.

Adding:

    (define-foreign-type xmmsc-result (pointer "xmmsc_result_t"))

to the top and replacing the c-pointer bits with xmmsc-result also
hangs.

However, the following code works:

    (define-foreign-type xmmsc-ptr (pointer "xmmsc_connection_t"))
    (define-foreign-type xmmsc-result (pointer "xmmsc_result_t"))
    (define-foreign-type xmmsc-result-type "xmmsc_result_type_t")
    (define xmmsc_playback_stop
        (foreign-lambda xmmsc-result "xmmsc_playback_stop" xmmsc-ptr))
    (define xmmsc_result_wait
        (foreign-lambda void "xmmsc_result_wait" xmmsc-result))

    (xmmsc_result_wait (xmmsc_playback_stop conn))

Basically, xmmsc_result_wait works if I don't store the xmmsc-result
in a Scheme variable first; I can't figure out how to do so and
still have xmmsc_result_wait work properly.

-Robin




reply via email to

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