Project

General

Profile

Actions

Feature #17832

closed

allow IO write to write memoryview object without copying or add IO#write_memoryview

Added by dsisnero (Dominic Sisneros) almost 3 years ago. Updated almost 3 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
[ruby-core:103604]

Description

IO#write() - arguments that are not a string will be converted to string using to_s
want IO#write to be able to write memoryview objects without conversion to string

require 'fiddle'
include Fiddle
ptr = Fiddle::Pointer['this is a string']
mv = MemoryView.new ptr
mv.byte_size  #17802 
mv[0]  # 116
'this is a string'.bytes[0] = 116
File.open('test.txt', 'wb'){ f.write mv}
contents = File.open('test.txt', 'r'){ |f| f.read}  # contents is  "#<Fiddle::MemoryView:0x000001a75ae76258>" not 'this is a string'

buffer = ByteBuffer.new('this is a string')
File.open('test.txt', 'w'){|f| f.write Fiddle::MemoryView.new(buffer)}

allow IO#write to write memoryview objects without converting to string or add a new method on IO to write memoryview objects without converting to string

Related

#17834
#17833

Updated by dsisnero (Dominic Sisneros) almost 3 years ago

any comments on this feature request?

Updated by xtkoba (Tee KOBAYASHI) almost 3 years ago

For debugging purposes, it would be nice if we could modify the content of view directly from Ruby code without any third-party C extension, although I cannot tell whether IO is suitable for that.

Updated by dsisnero (Dominic Sisneros) almost 3 years ago

This is a separate request #17851 to allow memoryview extension in ruby - this request is so that IO doesn't require a separate copy
to string when writing a memoryview object

Actions #4

Updated by dsisnero (Dominic Sisneros) almost 3 years ago

  • Description updated (diff)

Updated by kou (Kouhei Sutou) almost 3 years ago

  • Status changed from Open to Third Party's Issue

We can implement this by adding Fiddle::MemoryView#to_s with rb_str_new_static().

Could you file this to https://github.com/ruby/fiddle/ ?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0