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: Wed, 4 Jul 2007 14:58:18 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

On Tue, Jul 03, 2007 at 05:26:54PM -0700, Robin Lee Powell wrote:
> 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*.

I went the easy-ffi route and did some more reading; what it looks
like I needed was (define-external ...) rather than let-location.

For those of you that might also be trying to feel your way through
FFI, the code is below.

I also have another general question.  I'm finding myself copying
lines verbatim from include files inte #>!...<# sections.  Why not
have a means to parse an entire include file for FFI use?

-Robin

- --------------------

#>
#include <stdlib.h>

#include <xmmsclient/xmmsclient.h>
<#

#>!
xmmsc_connection_t *xmmsc_init (const char *clientname);
int xmmsc_connect (xmmsc_connection_t *, const char *);
xmmsc_result_t *xmmsc_playback_current_id (xmmsc_connection_t *c);
void xmmsc_result_wait (xmmsc_result_t *res);
int xmmsc_result_iserror (xmmsc_result_t *res);
int xmmsc_result_get_uint (xmmsc_result_t *res, uint32_t *r);
void xmmsc_unref (xmmsc_connection_t *c);
void xmmsc_result_unref (xmmsc_result_t *res);
<#

(define conn (xmmsc_init "tut2"))

(xmmsc_connect conn "unix:///tmp/xmms-ipc-rlpowell")
(define result (xmmsc_playback_current_id conn))

(xmmsc_result_wait result)

(display (conc "result is error: " (xmmsc_result_iserror result) "\n"))

(define-external id unsigned-int32 7823412)
(display "before get_uint.\n")
(xmmsc_result_get_uint result (location id))
(display "after get_uint.\n")
(display (conc "uint: " id "\n"))

(display "after let-location.\n")

(xmmsc_result_unref result)

(xmmsc_unref conn)





reply via email to

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