Cool! Ahh, this is because with ___FIX() it's implicit that the passed value will fit in a fixnum whereas with (c-lambda ([args]) int code) needs a conditional for if the return value would be a bignum.
Beyond this, can it ever be faster with regard to use (##c-code code) than (c-lambda (scheme-object:s) scheme-object code)?
Vijay: Feel free to document what you got from this on the wiki - this is like the most essential stuff ever so it deserves a place there.
2013/9/26 Marc Feeley feeley@iro.umontreal.ca
On 2013-09-26, at 12:21 AM, Vijay Mathew vijay.the.lisper@gmail.com wrote:
Thanks again for all the great feedback!
I think the call to ____FIX() is not required if Scheme code access the
C function through a declaration like this:
(define read-bytes (c-lambda (int unsigned-int scheme-object) int
"read_bytes"))
Is that correct?
That is correct. However, using ___FIX() is faster for converting a C integer to a Scheme fixnum. And ___INT() is faster for converting a Scheme fixnum to a C integer. So better performance is obtained with:
(define read-bytes (c-lambda (scheme-object scheme-object scheme-object) scheme-object "___result = ___FIX(read (___INT(___arg1),___BODY(___arg3),___INT(___arg2));"))
Marc