Skip to content

Commit 8ca9852

Browse files
committed
Avoid creating autorelease pointers when spawning subprocesses
* Instead use stack_alloc in #with_array_of_strings_pointer.
1 parent 30abc9b commit 8ca9852

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/ruby/truffleruby/core/posix.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,15 @@ def self.with_array_of_ints(ints)
326326

327327
def self.with_array_of_strings_pointer(strings)
328328
Truffle::FFI::MemoryPointer.new(:pointer, strings.size + 1) do |ptr|
329-
pointers = strings.map do |str|
330-
Truffle::FFI::MemoryPointer.from_string(str)
329+
pointers = Truffle::FFI::Pool.stack_alloc(*strings.map { |s| s.bytesize + 1 })
330+
begin
331+
pointers.zip(strings) { |sp, s| sp.put_string(0, s) }
332+
pointers << Truffle::FFI::Pointer::NULL
333+
ptr.write_array_of_pointer pointers
334+
yield(ptr)
335+
ensure
336+
Truffle::FFI::Pool.stack_free(pointers[0])
331337
end
332-
pointers << Truffle::FFI::Pointer::NULL
333-
ptr.write_array_of_pointer pointers
334-
yield(ptr)
335338
end
336339
end
337340

0 commit comments

Comments
 (0)