If you go through a c-lambda, the glue code generated by the FFI will check ___err and raise an exception accordingly if ___err != ___FIX(___NO_ERR). It is up to the C code to set ___err correctly. In the code I gave it is the part:
if ((___err = ___U32_to_SCMOBJ (___PSTATE, val, &___result, ___RETURN_POS)) == ___FIX(___NO_ERR)) { ___release_scmobj (___result); }
Note that this will set ___err in addition to testing if the conversion succeeded (in which case the resulting Scheme object must be released (reference count decremented) because the C world will no longer point to it when it is returned).
If you call ___alloc_scmobj and other internal Gambit runtime functions then you have to check the result explicitly and errors are indicated in two ways. In the case of ___alloc_scmobj, ___make_pair, ___make_vector, and similar functions returning a useful Scheme object (but not a fixnum), then if ___FIXNUMP(result) there was an error and result contains the error code. Functions with side-effects, such as ___setup, ___call, and all the type conversion functions always return a fixnum and anything other than ___FIX(___NO_ERR) indicates an error. If you look at the Gambit sources, you’ll see that sometimes these error checks are done in C and sometimes in Scheme (look at the code for ##process-statistics in lib/_kernel.scm which does both).
Marc
On Jan 6, 2016, at 4:42 PM, Adam adam.mlmb@gmail.com wrote:
Aha.
How can I know based on the return value of some random Gambit C function like ___aloc_scmobj or ___U32_to_SCMOBJ that it guaranteedly will trig an exception when returning to the Scheme world, without me needing to take any futher action for that to happen - will that happen in all non-___FIX(___NO_ERR) result cases?
2016-01-07 5:37 GMT+08:00 Marc Feeley feeley@iro.umontreal.ca: Actually, all c-lambdas that can generate an exception will check the variable ___err to see if there was an error.
The implementation is the macro ___CFUN_CONV_ERROR in gambit.h .
Marc
On Jan 6, 2016, at 4:32 PM, Adam adam.mlmb@gmail.com wrote:
Aha interesting, so every c-lambda that returns a scheme-object, will check if ___result is set to an error. Does that check trig on all errors, what's its definition.., is it implemented in any particular macro or alike?
Just for me as a user to be able to know exactly.