8 Jul 2007 06:03
IDL issue
Jonathan S. Shapiro <shap <at> eros-os.com>
2007-07-08 04:03:10 GMT
2007-07-08 04:03:10 GMT
An issue has come up in defining the C binding for CapIDL, and I would
like input. The issue is not specific to capabilities.
Any IDL method returns two results: a result (error) code, and a return
value. [There may also be additional OUT parameters, but for my question
we can ignore those.]
The question is: should the C stub return the error code or the return
value?
Concrete example:
idl: float f(int arg);
C: float f(int arg, IDL_Env *_env); [return result value]
C: result_T f(int arg, float *_retVal, IDL_Env *_env);
[returns error code]
When the result value is returned, the error code is generally stored
into a dedicated slot within the IDL_Env structure.
In my opinion, returning the error code is better for two reasons:
1. It leads to more consistent error checking:
CHECKRESULT(f(arg, &retVal, &idlEnv));
// where CHECKRESULT is a macro that may cause exceptional
// control flow, and any code below this point can assume
// the operation succeeded.
2. It avoids an initialization problem. Consider the "return result
(Continue reading)
> This might eliminate some problems due to sloppy programming. The one
> argument I can think of in favour of returning the result value is a
> performance related one. The architecture calling conventions...
Yes, but as Tom Bachmann pointed out, this is not an issue when stubs
are inlined. Inlining stubs seems to be a universal assumption, though
it is probably not an optimization to do this on most architectures.
RSS Feed