Skip to content

Commit 056ae04

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

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

Diff for: ‎library/ffi/generators/structures.rb

+8
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

Diff for: ‎rakelib/platform.rake

+1-1
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)