Project

General

Profile

« Previous | Next » 

Revision 5c0d8c63

Added by tenderlovemaking (Aaron Patterson) over 4 years ago

[ruby/fiddle] Add "offsetof" to Struct classes (https://github.com/ruby/fiddle/pull/83)

  • Add "offsetof" to Struct classes

I need to get the offset of a member inside a struct without allocating
the struct. This patch adds an "offsetof" class method to structs that
are generated.

The usage is like this:

MyStruct = struct [ "int64_t i", "char c", ] MyStruct.offsetof("i") # => 0 MyStruct.offsetof("c") # => 8 
  • Update test/fiddle/test_c_struct_builder.rb

Co-authored-by: Sutou Kouhei

https://github.com/ruby/fiddle/commit/4e3b60c5b6

Co-authored-by: Sutou Kouhei