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 |
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?