[plt-scheme] scheme/foreign and C arrays

From: Ben Simon (benjisimon at gmail.com)
Date: Fri Dec 26 09:54:13 EST 2008

On Fri, Dec 26, 2008 at 7:16 AM, troels knak-nielsen <troelskn at gmail.com>wrote:

> 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


Figures, the exact question I was asking was already asked - typical.

The answer doesn't really make sense to me. But, it gives me a place to
start, and I'll mull it over from there.

Oh - and I have the same goals you had when you were working on the code
mentioned in the above post. It's all about learning FFI...

Thanks,
Ben




>
>
> --
> 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
> >
> >
>



-- 
Have an idea for software?  I can make it happen -
http://www.ideas2executables.com
My Blog: http://benjisimon.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081226/3efcfec6/attachment.html>

Posted on the users mailing list.