The FFI supports all the C integer types so it is simplest to let Gambit do the conversion with (c-lambda (TIFF* ttag_t) unsigned-int32 "uint32_tag").
Is the issue that you need to return an integer or #f? Could one of the integer values be used instead of #f?
Marc
On Jan 6, 2016, at 6:47 AM, Adam adam.mlmb@gmail.com wrote:
One way would be to return a special C "int-or-boolean" structure and then access it via special accessors. E.g. (let* ((r (your-c-call))) (if (struct=false? r) #f (struct-int r))) ?
Marc, any better ideas?
2016-01-06 19:41 GMT+08:00 Alex Silva asandroq@gmail.com: Hello list,
I am currently writing some FFI code that interfaces with libtiff to read tags from TIFF image files. The values of these tags have different C types and using the right type is needed to avoid memory corruption.
For reading tags with uint16 values the code is straightforward:
static ___SCMOBJ uint16_tag(TIFF *tiff, ttag_t tag) { uint16 val; int ret = TIFFGetField(tiff, tag, &val); return ret == 1 ? ___FIX(val) : ___FAL; }
But, since fixnums have less than 32 bits I cannot use the same code. It seems the solution would be something similar to:
static ___SCMOBJ uint32_tag(TIFF *tiff, ttag_t tag) { uint32 val; if(TIFFGetField(tiff, tag, &val) == 1) { ___SCMOBJ ret; ___U32_to_SCMOBJ(___ps, val, &ret, ___RETURN_POS); <---- ERROR return ret; } else { return ___FAL; } }
except that I don't know how to get hold of the processor state. Can anybody shed a light here?
Thanks, -alex http://unendli.ch/ _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list