[gambit-list] Converting uint32 to scheme object

Adam adam.mlmb at gmail.com
Wed Jan 6 09:06:08 EST 2016


Right, that the boolean value not has a mapping within the int32
"namespace".

How would you suggest to pass it then, Marc?


I don't see any clear way this can be done with Scheme structures, so
simply passing a C structure as result value that has accessors, per the
example in my previous email, seems like the best thing. That one has the
issue that it requires a malloc()/free() combo which is a bit unfortunate.


Returning an uint64 would work of course even if it would be a hack - Marc,
what is the C FFI integer type names specified to specific numbers of bits?
(Usually you just say "integer" etc.)


2016-01-06 21:22 GMT+08:00 Marc Feeley <feeley at iro.umontreal.ca>:

> 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 at 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 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/9b100bb7/attachment.htm>


More information about the Gambit-list mailing list