[gambit-list] Converting uint32 to scheme object
Adam
adam.mlmb at gmail.com
Wed Jan 6 06:47:33 EST 2016
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 at 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 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/20160106/ba4ed46e/attachment.htm>
More information about the Gambit-list
mailing list