[plt-scheme] scheme/foreign and C arrays

From: troels knak-nielsen (troelskn at gmail.com)
Date: Fri Dec 26 07:16:35 EST 2008

I had a similar problem a few months back. Have a look over here:
http://stackoverflow.com/questions/105816/how-do-i-access-a-char-through-ffi-in-plt-scheme

--
troels

On Fri, Dec 26, 2008 at 12:44 AM, Ben Simon <benjisimon at gmail.com> wrote:
> Howdy -
>
> Now that my MySQL FFI implementation doesn't crash every few moments, I've
> been able to make some headway into making the API useful.  This has been
> going well, until I hit the row handling MySQL requires. Here's the C
> example they provide:
>
>
> MYSQL_ROW row;
> unsigned int num_fields;
> unsigned int i;
>
> num_fields = mysql_num_fields(result);
> while ((row = mysql_fetch_row(result)))
> {
>    unsigned long *lengths;
>    lengths = mysql_fetch_lengths(result);
>    for(i = 0; i < num_fields; i++)
>    {
>        printf("[%.*s] ", (int) lengths[i],
>               row[i] ? row[i] : "NULL");
>    }
>    printf("\n");
> }
>
> Apparently, when I call mysql_fetch_row(...) it will return back a big array
> of character data that is the series of columns.  I can index into this
> array by calling mysql_num_fields and mysql_fetch_lengths.
>
> mysql_fetch_lengths returns back  an array of numbers, while the row object
> is essentially an array.
>
> Given this, I think I need to focus on how Scheme handles C arrays.  What's
> the cleanest way to handle this?   I've found some discussion about
> cvectors, is that I'm looking for?
>
> Thanks,
> -Ben
>
> --
> Have an idea for software?  I can make it happen -
> http://www.ideas2executables.com
> My Blog: http://benjisimon.blogspot.com
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


Posted on the users mailing list.