Skip to content

Commit 9ebdfd6

Browse files
committed
Change Marshal::State#construct_string to use #__allocate__ instead of #set_class
1 parent d8b43d2 commit 9ebdfd6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/ruby/core/marshal.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,17 @@ def set_instance_variables(obj)
223223
end
224224
end
225225

226+
STRING_ALLOCATE = String.method(:__allocate__).unbind
227+
226228
def construct_string
227-
obj = get_byte_sequence
228-
Truffle::Internal::Unsafe.set_class(obj, get_user_class) if @user_class
229+
bytes = get_byte_sequence.force_encoding(Encoding::ASCII_8BIT)
229230

230-
set_object_encoding(obj, Encoding::ASCII_8BIT)
231+
if @user_class
232+
obj = STRING_ALLOCATE.bind(get_user_class).call
233+
Truffle.invoke_primitive(:string_initialize, obj, bytes, Encoding::ASCII_8BIT)
234+
else
235+
obj = bytes
236+
end
231237

232238
store_unique_object obj
233239
end

0 commit comments

Comments
 (0)