[gambit-list] c interface: enums issue

Álvaro Castro-Castilla alvaro.castro.castilla at gmail.com
Sun Feb 5 12:58:45 EST 2012


hi Mikael,

Thanks for your response.
Unfortunately, your solution also breaks. Actually, it is doing more or
less the same I did. What you say should be used like this, right?:
(image-surface (cairo-image-surface-create-for-data
                         (SDL::surface-pixels sdl-surface)
                         (CAIRO_FORMAT_RGB24)
                         maxx
                         maxy
                         (SDL::screen-pitch sdl-surface)))

What I was proposing just decides the output at runtime (the argument is an
int, but passed to a function that converts it into a enum -should
convert-):
(image-surface (cairo-image-surface-create-for-data
                         (SDL::surface-pixels sdl-surface)
                         (cairo-format CAIRO_FORMAT_RGB24)
                         maxx
                         maxy
                         (SDL::screen-pitch sdl-surface)))

But the result is the same: segfault. Using your first solution (returning
an int) causes the same problem I got at the
beginning: (cairo#cairo-image-surface-create-for-data '#<|unsigned char*|
#16 0x7f584104c000> 0 500 500 2000)

Thanks for your help.

Best regards



On Sun, Feb 5, 2012 at 6:35 PM, Mikael <mikael.rcv at gmail.com> wrote:

> If those are int consts from the C header files of the lib, then import
> them as is fromt here (define CAIRO_FORMAT_ARGB32 ((c-lambda () int
> "___result = CAIRO_FORMAT_ARGB32;")) etc. , and any arguments that need
> them declare as int too.
>
> If they're C enums, maybe you want another datatype declaration of them
> than int - though I suppose int ought to be generally viable for that too.
>
> The exception in your example below is not so strange, as the second arg
> is an int while the procedure is declared as cairo-format-t. For it to
> work, I suppose define CAIRO_FORMAT_RGB24 to ((c-lambda () cairo-format-t
> "___result = CAIRO_FORMAT_RGB24;")) . Works?
>
> 2012/2/5 Álvaro Castro-Castilla <alvaro.castro.castilla at gmail.com>
>
>>  Hi,
>>
>> I'm using my ffi cairo bindings, that worked fine in the past. However
>> now that I'm using Gambit compiled with C++ support it stopped working.
>>
>>
>>
>>
>> I got this error:
>>
>> *** ERROR IN main-sdl#main, "main-sdl.scm"@19.24 -- (Argument 2) Can't
>> convert to C type
>> (cairo#cairo-image-surface-create-for-data '#<|unsigned char*| #16
>> 0x7f33ba191000> 1 500 500 2000)
>>
>> On the ffi side, things are declared like this:
>>
>> (c-define-type cairo-format-t "cairo_format_t")
>> (define CAIRO_FORMAT_ARGB32 0)
>> (define CAIRO_FORMAT_RGB24 1)
>> (define CAIRO_FORMAT_A8 2)
>> (define CAIRO_FORMAT_A1 3)
>> (define CAIRO_FORMAT_RGB16_565 4)
>> (define cairo-image-surface-create-for-data (c-lambda (unsigned-char*
>> cairo-format-t int int int) cairo-surface-t*
>> "cairo_image_surface_create_for_data"))
>>
>> And used like this:
>>
>> (cairo-image-surface-create-for-data
>>                          (SDL::surface-pixels sdl-surface)
>>                          CAIRO_FORMAT_RGB24
>>                          maxx
>>                          maxy
>>                          (SDL::screen-pitch sdl-surface))
>>
>> I've tried with this idea:
>>
>> (define cairo-format
>>   (c-lambda (int) cairo-format-t
>>             "
>>             switch (___arg1) {
>>               case 0: ___result = CAIRO_FORMAT_ARGB32; break;
>>               case 1: ___result = CAIRO_FORMAT_RGB24; break; // and so
>> on...
>>             }
>>             "))
>>
>> And then calling on the Scheme side "(cairo-format CAIRO_FORMAT_RGB24)"
>> instead of just using the int directly, but it segfaults.
>>
>>
>> How should I really handle enums properly?
>>
>>
>>
>> Best regards,
>>
>>
>> _______________________________________________
>> Gambit-list mailing list
>> Gambit-list at iro.umontreal.ca
>> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20120205/08770cff/attachment.htm>


More information about the Gambit-list mailing list