<div dir="ltr">Right, that the boolean value not has a mapping within the int32 "namespace".<div><br></div><div>How would you suggest to pass it then, Marc?</div><div><br></div><div><br></div><div>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.<br><div><br></div><div><br></div><div>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.)</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-06 21:22 GMT+08:00 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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").<br>
<br>
Is the issue that you need to return an integer or #f?  Could one of the integer values be used instead of #f?<br>
<span class="HOEnZb"><font color="#888888"><br>
Marc<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Jan 6, 2016, at 6:47 AM, Adam <<a href="mailto:adam.mlmb@gmail.com">adam.mlmb@gmail.com</a>> wrote:<br>
><br>
> 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))) ?<br>
><br>
> Marc, any better ideas?<br>
><br>
><br>
> 2016-01-06 19:41 GMT+08:00 Alex Silva <<a href="mailto:asandroq@gmail.com">asandroq@gmail.com</a>>:<br>
> Hello list,<br>
><br>
> I am currently writing some FFI code that interfaces with libtiff to<br>
> read tags from TIFF image files. The values of these tags have different<br>
> C types and using the right type is needed to avoid memory corruption.<br>
><br>
> For reading tags with uint16 values the code is straightforward:<br>
><br>
> ```<br>
> static ___SCMOBJ uint16_tag(TIFF *tiff, ttag_t tag)<br>
> {<br>
>   uint16 val;<br>
>   int ret = TIFFGetField(tiff, tag, &val);<br>
><br>
>   return ret == 1 ? ___FIX(val) : ___FAL;<br>
> }<br>
> ```<br>
><br>
> But, since fixnums have less than 32 bits I cannot use the same code. It<br>
> seems the solution would be something similar to:<br>
><br>
> ```<br>
> static ___SCMOBJ uint32_tag(TIFF *tiff, ttag_t tag)<br>
> {<br>
>   uint32 val;<br>
><br>
>   if(TIFFGetField(tiff, tag, &val) == 1)<br>
>   {<br>
>     ___SCMOBJ ret;<br>
>     ___U32_to_SCMOBJ(___ps, val, &ret, ___RETURN_POS);  <---- ERROR<br>
>     return ret;<br>
>   }<br>
>   else<br>
>   {<br>
>     return ___FAL;<br>
>   }<br>
> }<br>
><br>
> ```<br>
><br>
> except that I don't know how to get hold of the processor state. Can<br>
> anybody shed a light here?<br>
><br>
> Thanks,<br>
> -alex<br>
> <a href="http://unendli.ch/" rel="noreferrer" target="_blank">http://unendli.ch/</a><br>
> _______________________________________________<br>
> Gambit-list mailing list<br>
> <a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
> <a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" rel="noreferrer" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
><br>
<br>
</div></div></blockquote></div><br></div>