[ocaml-ctypes] Defines, and Structs with platform-specific fields
Trevor Smith
trevorsummerssmith at gmail.com
Thu Oct 30 12:34:48 GMT 2014
Jeremy,
Thanks for this work! I just got a chance this morning to take a look. This
work should save me a ton of time.
I'm having problems referencing a cstub'd struct within another cstub'd
struct. Looking at the types it doesn't seem that this would work - the
cstubs typ is different than the Ctypes.typ. I reproduced a tiny example in
the cstubs test files (diff below).
Thoughts? Thanks.
Trevor
Diff:
diff --git a/tests/clib/test_functions.h b/tests/clib/test_functions.h
index 17ec554..ec0e449 100644
--- a/tests/clib/test_functions.h
+++ b/tests/clib/test_functions.h
@@ -164,7 +164,7 @@ void post1_wait2(void);
void post2_wait1(void);
struct s1 { int x1, x2, x3, x4; };
-struct s2 { int y1, y2, y3, y4; };
+struct s2 { int y1, y2, y3, y4; struct s1 foo; };
size_t sizeof_s1(void);
size_t alignmentof_s1(void);
diff --git a/tests/test-structs/stubs/types.ml b/tests/test-structs/stubs/
types.ml
index d03f497..fc54f25 100644
--- a/tests/test-structs/stubs/types.ml
+++ b/tests/test-structs/stubs/types.ml
@@ -21,5 +21,6 @@ struct
let s2 : [`s2] structure typ = structure "s2"
let y2 = field s2 "y2" int
let y1 = field s2 "y1" int
+ let foo = field s2 "foo" s1
let () = seal s2
end
Build error:
File "tests/test-structs/stubs/types.ml", line 24, characters 32-34:
Error: This expression has type [ `s1 ] Ctypes.structure S.typ
but an expression was expected of type 'a Ctypes.typ = 'a Static.typ
On Sat, Oct 25, 2014 at 2:31 PM, Jeremy Yallop <yallop at gmail.com> wrote:
> On 20 October 2014 21:46, Jeremy Yallop <yallop at gmail.com> wrote:
> > This discussion is a useful reminder that ctypes really needs support
> > for retrieving struct layout details from the declared API. I'll look
> > at how to add that support later this week and report back.
>
> I've added support for retrieving struct layout from C in a pull request:
>
> https://github.com/ocamllabs/ocaml-ctypes/pull/62
>
> It works in a very similar fashion to cstubs: you put your struct
> declaration inside a functor
>
> module Bindings(S : Cstubs_structs.STRUCT) =
> struct
> open S
> let cell = structure "cell"
> let payload = field cell int "payload"
> let next = field cell (ptr cell) "next"
> let () = seal cell
> end
>
> and then call Cstubs_structs.write_c to generate an ML module with
> which to instantiate the functor.
>
> The pull request has more details and some illustrative tests.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/ctypes/attachments/20141030/48b3ed9f/attachment.html>
More information about the Ctypes
mailing list