Subject:
[ruby-ffi] Re: Correct type for binary buffer in a String?
From:
Wayne Meissner
Date:
5/7/11 10:30 PM
To:
ruby-ffi@googlegroups.com



On Friday, 6 May 2011 18:09:40 UTC+10, candlerb wrote:

Now, I also tried it using plain String instead of FFI::Buffer, and it
works. However if Ruby is sharing the underlying string storage
between multiple strings (copy-on-write) then aliasing happens:

str = "xxxx"
buf = str.dup
buflen = [buf.bytesize].pack("I")
puts Foo.getsockopt(s.fileno, Socket::IPPROTO_IP, Socket::IP_TTL, buf,
buflen)
p buf  # "@\000\000\000"
p str  # "@\000\000\000" as well!!

Is that intentional? Perhaps if the argument is :buffer_inout then FFI
should call rb_str_modify on the string first?

 It is highly likely you are correct.  If you haven't already, can you raise an issue on github for this, and also test it on JRuby and raise an issue in its bug tracker?