Support for returning errno from generated stubs #392
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds support for returning
errno
alongside the return value of bound functions in generated stubs. As with #391, the interface changes are fairly modest: there is an additional argument,errno
towrite_c
andwrite_ml
, specifying the policy to use.Besides the default,
ignore_errno
, there is one additional option,return_errno
, which changes the return type of each function binding fromt
tot * int
.For example, here is the example bindings description for
puts
andrmdir
from #391:The C and OCaml portions of the bindings may be generated in the usual way, specifying
return_errno
with a keyword argument:In the module signature built by the linking step (i.e. by applying
Bindings
to the generated OCaml module) each function binding returns a pair of the return value of the bound C function and the value oferrno
just after the call:Errno and Lwt
There is also support for the combination of the new
errno
andconcurrency
options.Passing
~concurrency:lwt_jobs
towrite_c
andwrite_ml
changes the return type of a function binding fromt
toLwt.t
(or rather to the wrapper typereturn
).Passing
~errno:return_errno
changes the return type fromt
tot * int
.Passing both
~concurrency:lwt_jobs
and~errno:return_errno
changes the return type fromt
to(t * int) Lwt.t
--- that is, to anLwt
job that returns both the result of calling the bound C function and the value oferrno
just after the call.