Skip to content

Commit ebe660f

Browse files
committed
Support writing to an inline char array in FFI
1 parent 8dd4e61 commit ebe660f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/truffle/truffle/ffi_backend/struct_layout.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ def get(struct_pointer)
159159
FFI::Struct::InlineArray.new(struct_pointer, self)
160160
end
161161
end
162+
163+
def put(struct_pointer, value)
164+
if @type.char_array?
165+
if value.bytesize < @type.length
166+
struct_pointer.put_string(@offset, value)
167+
elsif value.bytesize == @type.length
168+
struct_pointer.put_bytes(@offset, value)
169+
else
170+
raise IndexError, "String is longer (#{value.bytesize} bytes) than the char array (#{@type.length} bytes)"
171+
end
172+
else
173+
raise NotImplementedError, 'cannot set array field'
174+
end
175+
end
162176
end
163177
end
164178
end

0 commit comments

Comments
 (0)