Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain struct layout details from C to help avoid runtime mismatches. #30

Closed
wants to merge 1 commit into from
Closed

Obtain struct layout details from C to help avoid runtime mismatches. #30

wants to merge 1 commit into from

Conversation

yallop
Copy link
Owner

@yallop yallop commented Jul 1, 2013

   # module V = Verify_struct_layout
   [...]
   # V.struct_info ~headers:["sys/types.h"] ~tag:"timeval"
       ~fields:["tv_sec"; "tv_usec"];;
   - : V.struct_info =
   {V.tag = "timeval";
    fields =
     [{V.label = "tv_sec"; offset = 0; size = 8};
      {V.label = "tv_usec"; offset = 8; size = 8}];
    size = 16}
   # V.struct_info ~headers:["time.h"] ~tag:"tm"
       ~fields:["tm_isdst"; "tm_mday"; "tm_mon"; "tm_year";
                "tm_wday"; "tm_yday"; "tm_sec"; "tm_min"; "tm_hour"];;
   - : V.struct_info =
   {V.tag = "tm";
    fields =
     [{V.label = "tm_sec"; offset = 0; size = 4};
      {V.label = "tm_min"; offset = 4; size = 4};
      {V.label = "tm_hour"; offset = 8; size = 4};
      {V.label = "tm_mday"; offset = 12; size = 4};
      {V.label = "tm_mon"; offset = 16; size = 4};
      {V.label = "tm_year"; offset = 20; size = 4};
      {V.label = "tm_wday"; offset = 24; size = 4};
      {V.label = "tm_yday"; offset = 28; size = 4};
      {V.label = "tm_isdst"; offset = 32; size = 4}];
    size = 56}

Currently just a comically inefficient proof-of-concept implementation.

   # module V = Verify_struct_layout
   [...]
   # V.struct_info ~headers:["sys/types.h"] ~tag:"timeval"
       ~fields:["tv_sec"; "tv_usec"];;
   - : V.struct_info =
   {V.tag = "timeval";
    fields =
     [{V.label = "tv_sec"; offset = 0; size = 8};
      {V.label = "tv_usec"; offset = 8; size = 8}];
    size = 16}
   # V.struct_info ~headers:["time.h"] ~tag:"tm"
       ~fields:["tm_isdst"; "tm_mday"; "tm_mon"; "tm_year";
                "tm_wday"; "tm_yday"; "tm_sec"; "tm_min"; "tm_hour"];;
   - : V.struct_info =
   {V.tag = "tm";
    fields =
     [{V.label = "tm_sec"; offset = 0; size = 4};
      {V.label = "tm_min"; offset = 4; size = 4};
      {V.label = "tm_hour"; offset = 8; size = 4};
      {V.label = "tm_mday"; offset = 12; size = 4};
      {V.label = "tm_mon"; offset = 16; size = 4};
      {V.label = "tm_year"; offset = 20; size = 4};
      {V.label = "tm_wday"; offset = 24; size = 4};
      {V.label = "tm_yday"; offset = 28; size = 4};
      {V.label = "tm_isdst"; offset = 32; size = 4}];
    size = 56}

Currently just a comically inefficient proof-of-concept implementation.
@yallop
Copy link
Owner Author

yallop commented Aug 14, 2013

Pull request #62 gives a more useful implementation.

@yallop yallop closed this Aug 14, 2013
@yallop yallop deleted the verify-struct-layout branch August 14, 2013 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant