[前][次][番号順一覧][スレッド一覧]

ruby-changes:73703

From: Takashi <ko1@a...>
Date: Fri, 23 Sep 2022 06:45:13 +0900 (JST)
Subject: [ruby-changes:73703] dc5b536468 (master): Bindgen offsetof struct and union with builtin

https://git.ruby-lang.org/ruby.git/commit/?id=dc5b536468

From dc5b536468f8def4ab808da57462aee6a99a6fe0 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Thu, 22 Sep 2022 21:39:54 +0900
Subject: Bindgen offsetof struct and union with builtin

except for bit fields.

I made a risky assumption on leading bit fields and just gave up
non-leading bit fields for now. I'll change it to let C code access bit
fields later.
---
 mjit_c.rb            | 366 +++++++++++++++++++++++++--------------------------
 mjit_compiler.c      |   4 +
 tool/mjit/bindgen.rb |  12 +-
 3 files changed, 197 insertions(+), 185 deletions(-)

diff --git a/mjit_c.rb b/mjit_c.rb
index e540fceda9..d4edbf2825 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -179,63 +179,63 @@ module RubyVM::MJIT https://github.com/ruby/ruby/blob/trunk/mjit_c.rb#L179
   def C.compile_branch
     @compile_branch ||= CType::Struct.new(
       "compile_branch", Primitive.cexpr!("SIZEOF(struct compile_branch)"),
-      stack_size: [0, CType::Immediate.parse("unsigned int")],
-      finish_p: [32, self._Bool],
+      stack_size: [Primitive.cexpr!("OFFSETOF((*((struct compile_branch *)NULL)), stack_size)"), CType::Immediate.parse("unsigned int")],
+      finish_p: [Primitive.cexpr!("OFFSETOF((*((struct compile_branch *)NULL)), finish_p)"), self._Bool],
     )
   end
 
   def C.compile_status
     @compile_status ||= CType::Struct.new(
       "compile_status", Primitive.cexpr!("SIZEOF(struct compile_status)"),
-      success: [0, self._Bool],
-      stack_size_for_pos: [64, CType::Pointer.new { CType::Immediate.parse("int") }],
-      local_stack_p: [128, self._Bool],
-      is_entries: [192, CType::Pointer.new { self.iseq_inline_storage_entry }],
-      cc_entries_index: [256, CType::Immediate.parse("int")],
-      compiled_iseq: [320, CType::Pointer.new { self.rb_iseq_constant_body }],
-      compiled_id: [384, CType::Immediate.parse("int")],
-      compile_info: [448, CType::Pointer.new { self.rb_mjit_compile_info }],
-      merge_ivar_guards_p: [512, self._Bool],
-      ivar_serial: [576, self.rb_serial_t],
-      max_ivar_index: [640, CType::Immediate.parse("size_t")],
-      inlined_iseqs: [704, CType::Pointer.new { CType::Pointer.new { self.rb_iseq_constant_body } }],
-      inline_context: [768, self.inlined_call_context],
+      success: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), success)"), self._Bool],
+      stack_size_for_pos: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), stack_size_for_pos)"), CType::Pointer.new { CType::Immediate.parse("int") }],
+      local_stack_p: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), local_stack_p)"), self._Bool],
+      is_entries: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), is_entries)"), CType::Pointer.new { self.iseq_inline_storage_entry }],
+      cc_entries_index: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), cc_entries_index)"), CType::Immediate.parse("int")],
+      compiled_iseq: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), compiled_iseq)"), CType::Pointer.new { self.rb_iseq_constant_body }],
+      compiled_id: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), compiled_id)"), CType::Immediate.parse("int")],
+      compile_info: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), compile_info)"), CType::Pointer.new { self.rb_mjit_compile_info }],
+      merge_ivar_guards_p: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), merge_ivar_guards_p)"), self._Bool],
+      ivar_serial: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), ivar_serial)"), self.rb_serial_t],
+      max_ivar_index: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), max_ivar_index)"), CType::Immediate.parse("size_t")],
+      inlined_iseqs: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), inlined_iseqs)"), CType::Pointer.new { CType::Pointer.new { self.rb_iseq_constant_body } }],
+      inline_context: [Primitive.cexpr!("OFFSETOF((*((struct compile_status *)NULL)), inline_context)"), self.inlined_call_context],
     )
   end
 
   def C.inlined_call_context
     @inlined_call_context ||= CType::Struct.new(
       "inlined_call_context", Primitive.cexpr!("SIZEOF(struct inlined_call_context)"),
-      orig_argc: [0, CType::Immediate.parse("int")],
-      me: [64, self.VALUE],
-      param_size: [128, CType::Immediate.parse("int")],
-      local_size: [160, CType::Immediate.parse("int")],
+      orig_argc: [Primitive.cexpr!("OFFSETOF((*((struct inlined_call_context *)NULL)), orig_argc)"), CType::Immediate.parse("int")],
+      me: [Primitive.cexpr!("OFFSETOF((*((struct inlined_call_context *)NULL)), me)"), self.VALUE],
+      param_size: [Primitive.cexpr!("OFFSETOF((*((struct inlined_call_context *)NULL)), param_size)"), CType::Immediate.parse("int")],
+      local_size: [Primitive.cexpr!("OFFSETOF((*((struct inlined_call_context *)NULL)), local_size)"), CType::Immediate.parse("int")],
     )
   end
 
   def C.iseq_inline_constant_cache
     @iseq_inline_constant_cache ||= CType::Struct.new(
       "iseq_inline_constant_cache", Primitive.cexpr!("SIZEOF(struct iseq_inline_constant_cache)"),
-      entry: [0, CType::Pointer.new { self.iseq_inline_constant_cache_entry }],
-      segments: [64, CType::Pointer.new { self.ID }],
+      entry: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache *)NULL)), entry)"), CType::Pointer.new { self.iseq_inline_constant_cache_entry }],
+      segments: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache *)NULL)), segments)"), CType::Pointer.new { self.ID }],
     )
   end
 
   def C.iseq_inline_constant_cache_entry
     @iseq_inline_constant_cache_entry ||= CType::Struct.new(
       "iseq_inline_constant_cache_entry", Primitive.cexpr!("SIZEOF(struct iseq_inline_constant_cache_entry)"),
-      flags: [0, self.VALUE],
-      value: [64, self.VALUE],
-      _unused1: [128, self.VALUE],
-      _unused2: [192, self.VALUE],
-      ic_cref: [256, CType::Pointer.new { self.rb_cref_t }],
+      flags: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache_entry *)NULL)), flags)"), self.VALUE],
+      value: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache_entry *)NULL)), value)"), self.VALUE],
+      _unused1: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache_entry *)NULL)), _unused1)"), self.VALUE],
+      _unused2: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache_entry *)NULL)), _unused2)"), self.VALUE],
+      ic_cref: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_constant_cache_entry *)NULL)), ic_cref)"), CType::Pointer.new { self.rb_cref_t }],
     )
   end
 
   def C.iseq_inline_iv_cache_entry
     @iseq_inline_iv_cache_entry ||= CType::Struct.new(
       "iseq_inline_iv_cache_entry", Primitive.cexpr!("SIZEOF(struct iseq_inline_iv_cache_entry)"),
-      entry: [0, CType::Pointer.new { self.rb_iv_index_tbl_entry }],
+      entry: [Primitive.cexpr!("OFFSETOF((*((struct iseq_inline_iv_cache_entry *)NULL)), entry)"), CType::Pointer.new { self.rb_iv_index_tbl_entry }],
     )
   end
 
@@ -244,8 +244,8 @@ module RubyVM::MJIT https://github.com/ruby/ruby/blob/trunk/mjit_c.rb#L244
       "iseq_inline_storage_entry", Primitive.cexpr!("SIZEOF(union iseq_inline_storage_entry)"),
       once: CType::Struct.new(
         "", Primitive.cexpr!("SIZEOF(((union iseq_inline_storage_entry *)NULL)->once)"),
-        running_thread: [0, CType::Pointer.new { self.rb_thread_struct }],
-        value: [64, self.VALUE],
+        running_thread: [Primitive.cexpr!("OFFSETOF(((union iseq_inline_storage_entry *)NULL)->once, running_thread)"), CType::Pointer.new { self.rb_thread_struct }],
+        value: [Primitive.cexpr!("OFFSETOF(((union iseq_inline_storage_entry *)NULL)->once, value)"), self.VALUE],
       ),
       ic_cache: self.iseq_inline_constant_cache,
       iv_cache: self.iseq_inline_iv_cache_entry,
@@ -255,58 +255,58 @@ module RubyVM::MJIT https://github.com/ruby/ruby/blob/trunk/mjit_c.rb#L255
   def C.mjit_options
     @mjit_options ||= CType::Struct.new(
       "mjit_options", Primitive.cexpr!("SIZEOF(struct mjit_options)"),
-      on: [0, self._Bool],
-      save_temps: [8, self._Bool],
-      warnings: [16, self._Bool],
-      debug: [24, self._Bool],
-      debug_flags: [64, CType::Pointer.new { CType::Immediate.parse("char") }],
-      wait: [128, self._Bool],
-      min_calls: [160, CType::Immediate.parse("unsigned int")],
-      verbose: [192, CType::Immediate.parse("int")],
-      max_cache_size: [224, CType::Immediate.parse("int")],
-      pause: [256, self._Bool],
-      custom: [264, self._Bool],
+      on: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), on)"), self._Bool],
+      save_temps: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), save_temps)"), self._Bool],
+      warnings: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), warnings)"), self._Bool],
+      debug: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), debug)"), self._Bool],
+      debug_flags: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), debug_flags)"), CType::Pointer.new { CType::Immediate.parse("char") }],
+      wait: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), wait)"), self._Bool],
+      min_calls: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), min_calls)"), CType::Immediate.parse("unsigned int")],
+      verbose: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), verbose)"), CType::Immediate.parse("int")],
+      max_cache_size: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), max_cache_size)"), CType::Immediate.parse("int")],
+      pause: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), pause)"), self._Bool],
+      custom: [Primitive.cexpr!("OFFSETOF((*((struct mjit_options *)NULL)), custom)"), self._Bool],
     )
   end
 
   def C.rb_builtin_function
     @rb_buil (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]