[gambit-list] FFI numeric vector lengths

Marc Feeley feeley at iro.umontreal.ca
Sun Aug 9 12:51:07 EDT 2020


The `___CONS` macro is meant to be used in C code generated by the gsc compiler (it does the allocation in an optimized way, it allocates a movable object and does not include the check for heap overflow).

You want to call `___make_pair` to allocate a still object with `___EXT(___make_pair) (___ps, x_scmobj, y_scmobj)` and you need to check for heap overflow explicitly with `___FIXNUMP(result)`.

For a full example, look at the definition of `STRINGS_to_SCMOBJ` in the Gambit manual (page 237).

Marc



> On Aug 9, 2020, at 12:39 PM, Lassi Kortela <lassi at lassi.io> wrote:
> 
>> You are using the `___U8VECTORLENGTH` macro and friends incorrectly.  They return a fixnum but your `c-lambda`s return `size_t`… so you want to say `___INT(___U8VECTORLENGTH(___arg1))` which converts the fixnum to an `int`, or use `scheme-object` instead of `size_t` as the return type of the `c-lambda`s.
> 
> Thanks! I didn't notice the fixnum tagging.
> 
> How does one build lists in a c-lambda? This:
> 
> (pp ((c-lambda () scheme-object
>       "___return(___CONS(___FIX(1), ___CONS(FIX(2), ___NUL)));")))
> 
> gives errors about:
> 
> /Users/lassi/.local/include/gambit.h:2459:30: error: '___hp' undeclared (first use in this function); did you mean '___fp'?
> 2459 | #define ___BEGIN_ALLOC_PAIR()___hp[0] = ___MAKE_HD_WORDS(___PAIR_SIZE,___sPAIR)
>      |                              ^~~~~
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list





More information about the Gambit-list mailing list