{"action":"created","issue":{"url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/392","repository_url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes","labels_url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/392/labels{/name}","comments_url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/392/comments","events_url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/392/events","html_url":"https://github.com/ocamllabs/ocaml-ctypes/pull/392","id":156998008,"number":392,"title":"Support for returning errno from generated stubs","user":{"login":"yallop","id":1736496,"avatar_url":"https://avatars.githubusercontent.com/u/1736496?v=3","gravatar_id":"","url":"https://api.github.com/users/yallop","html_url":"https://github.com/yallop","followers_url":"https://api.github.com/users/yallop/followers","following_url":"https://api.github.com/users/yallop/following{/other_user}","gists_url":"https://api.github.com/users/yallop/gists{/gist_id}","starred_url":"https://api.github.com/users/yallop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yallop/subscriptions","organizations_url":"https://api.github.com/users/yallop/orgs","repos_url":"https://api.github.com/users/yallop/repos","events_url":"https://api.github.com/users/yallop/events{/privacy}","received_events_url":"https://api.github.com/users/yallop/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-26T14:32:25Z","updated_at":"2016-05-26T15:07:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/pulls/392","html_url":"https://github.com/ocamllabs/ocaml-ctypes/pull/392","diff_url":"https://github.com/ocamllabs/ocaml-ctypes/pull/392.diff","patch_url":"https://github.com/ocamllabs/ocaml-ctypes/pull/392.patch"},"body":"This pull request adds support for returning [`errno`][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` to [`write_c`][write_c] and [`write_ml`][write_ml], specifying the policy to use.\r\n\r\nBesides the default, `ignore_errno`, there is one additional option, `return_errno`, which changes the return type of each function binding from `t` to `t * int`.\r\n\r\nFor example, here is the example bindings description for `puts` and `rmdir` from #391:\r\n\r\n```ocaml\r\nmodule Bindings(F: Cstubs.FOREIGN) =\r\nstruct\r\n  open F\r\n  let puts = foreign \"puts\" (string @-> returning int)\r\n  let rmdir = foreign \"rmdir\" (string @-> returning int)\r\nend\r\n```\r\n\r\nThe C and OCaml portions of the bindings may be generated in the usual way, specifying `return_errno` with a keyword argument:\r\n\r\n```ocaml\r\nwrite_c fmt ~errno:return_errno ~prefix (module Bindings)\r\nwrite_ml fmt ~errno:return_errno ~prefix (module Bindings)\r\n```\r\n\r\nIn 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 of `errno` just after the call:\r\n\r\n```ocaml\r\n(*\r\nsig\r\n  val puts : string -> int * int\r\n  val rmdir : string -> int * int\r\nend\r\n*)\r\nmodule C_errno = Bindings(Generated_module)\r\n```\r\n\r\n### Errno and Lwt \r\n\r\nThere is also support for the combination of the new `errno` and `concurrency` options.\r\n\r\nPassing `~concurrency:lwt_jobs` to `write_c` and `write_ml` changes the return type of a function binding from `t` to `Lwt.t` (or rather to the wrapper type [`return`](https://github.com/ocamllabs/ocaml-ctypes/pull/391)).\r\n\r\nPassing `~errno:return_errno` changes the return type from `t` to `t * int`.\r\n\r\nPassing both `~concurrency:lwt_jobs` and `~errno:return_errno` changes the return type from `t` to `(t * int) Lwt.t` --- that is, to an `Lwt` job that returns both the result of calling the bound C function and the value of `errno` just after the call.\r\n\r\n#### Note\r\n\r\nThis pull request is built on #391, and will be rebased if necessary when that PR is merged.\r\n\r\n[write_c]: http://ocamllabs.github.io/ocaml-ctypes/Cstubs.html#VALwrite_c\r\n[write_ml]: http://ocamllabs.github.io/ocaml-ctypes/Cstubs.html#VALwrite_ml\r\n[errno]: http://man7.org/linux/man-pages/man3/errno.3.html\r\n"},"comment":{"url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/comments/221899042","html_url":"https://github.com/ocamllabs/ocaml-ctypes/pull/392#issuecomment-221899042","issue_url":"https://api.github.com/repos/ocamllabs/ocaml-ctypes/issues/392","id":221899042,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2016-05-26T15:07:53Z","updated_at":"2016-05-26T15:07:53Z","body":"\n[![Coverage Status](https://coveralls.io/builds/6345815/badge)](https://coveralls.io/builds/6345815)\n\nCoverage decreased (-0.4%) to 87.775% when pulling **05c1d85334f1ca4466d05983214490c2ec244361 on yallop:errno-stubs** into **d27141372bb355ec84674691aad4f3eda3f173d0 on ocamllabs:master**.\n"}}
{"actor":{"display_login":"coveralls"}}