[ocaml-ctypes] Enum problem

Nick Betteridge buzzheavyyear at hotmail.com
Fri Feb 6 09:45:22 GMT 2015


Hello,

I've been trying to get enums/constant working and have been having a problem in matching types:

Error: This expression has type channel_states S.typ
       but an expression was expected of type 'a Ctypes.typ = 'a Static.typ

I get the same error when I try the fruit example from ocaml-ctypes/tests/test-enums, although the issue may be due to a) my inexperience with ocaml and b) the way I generate the stubs. However, all of the c functions I'm mapping to compile without problems. This is essentially what I have:

bindings:
------------

open Ctypes

module Bindings
  (F : sig type _ fn
           val foreign : string -> ('a -> 'b) Ctypes.fn -> ('a -> 'b) fn end) (S : Cstubs.Types.TYPE) = struct
    open F


  type channel_states = ENDED | OPENING | OPEN

  let ended    = S.constant "ENDED"   S.int64_t
  let opening  = S.constant "OPENING" S.int64_t
  let open_     = S.constant "OPEN"    S.int64_t

  let  channel_states = S.enum " channel_states" [
      ENDED, ended;
      OPENING, opening;
      OPEN, open_;
    ]

    type  channel_struct
    let  channel_struct = structure " channel_struct"
      let (-:) ty label = field  channel_struct label ty
      let state    = channel_states -: "state"
      let capacity = uint32_t           -: "capacity"
    let () = seal (channel_struct : channel_struct structure typ)

    type channel_t = channel_struct structure ptr
    let channel_t = ptr channel_struct

... the error occurs at the state field at channel_states


the generator:
-------------------

open Channel_bindings

let c_headers = "#include \"/home/nick/channel/include/channel.h\""

let main () =
  let ml_out = open_out "lib/channel_generated.ml" in
  let c_out = open_out "lib/channel_stubs.c" in
  let ml_fmt = Format.formatter_of_out_channel ml_out in
  let c_fmt = Format.formatter_of_out_channel c_out in
  Cstubs.write_ml ml_fmt ~prefix:"libchannel_" (module Bindings);
  Format.fprintf c_fmt "%s@\n" c_headers;
  Cstubs.write_c c_fmt ~prefix:"libchannel_" (module Bindings);
  Format.pp_print_flush ml_fmt ();
  Format.pp_print_flush c_fmt ();
  close_out ml_out;
  close_out c_out

let () =
  main ()

and the oasis BuildDepends is : ctypes, ctypes.foreign, ctypes.stubs, ctypes.foreign.base, ctypes.foreign.unthreaded

I've been trying to work this out since early wednesday ( and learnt alot!) but I can't think of anything else to try. I've locally pinned ocaml-ctypes from github head.

Cheers
Nick
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/ctypes/attachments/20150206/ab359cc5/attachment.html>


More information about the Ctypes mailing list