Skip to content

Commit 056ae04

Browse files
committed
generate and save a string defining the struct timeval as a FFI struct
1 parent 9a852dd commit 056ae04

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

library/ffi/generators/structures.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def write_config(io)
159159
@fields.each { |field| io.puts field.to_config(@name) }
160160
end
161161

162+
def write_class(io)
163+
layout = generate_layout.gsub(/\n/, '').squeeze(' ')
164+
struct_name = @struct_name.split(' ').last.capitalize + "_t"
165+
struct_class = "class #{struct_name} < FFI::Struct; #{layout}; end"
166+
167+
io.puts "rbx.platform.#{@name}.class = #{struct_class}"
168+
end
169+
162170
def generate_layout
163171
buf = ""
164172

rakelib/platform.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ file 'runtime/platform.conf' => deps do |task|
6262
s.name 'struct timeval'
6363
s.field :tv_sec, :time_t
6464
s.field :tv_usec, :suseconds_t
65-
end.write_config(f)
65+
end.tap { |struct| struct.write_config(f); struct.write_class(f) }
6666

6767
Rubinius::FFI::Generators::Structures.new 'sockaddr_in' do |s|
6868
if BUILD_CONFIG[:windows]

0 commit comments

Comments
 (0)