Subject:
[ruby-ffi] Re: What is the best way to convert a Fixnum to a :pointer?
From:
Brett Blackham
Date:
9/16/09 8:40 AM
To:
ruby-ffi



So MemoryPointer is like calling malloc and returning a pointer to
it.

I had tried just sending address to Pointer.new in hopes that it could
handle an Int as well as an existing pointer. But it doesn't appear to
work.

>> require 'ffi'
=> true
>> address = FFI::Pointer.new(5)
=> #<Native Pointer address=0x5>
>> p = FFI::Pointer.new(address)
TypeError: can't convert FFI::Pointer into Integer
        from (irb):4:in `initialize'
        from (irb):4:in `new'
        from (irb):4

>> address = FFI::MemoryPointer :pointer
NoMethodError: undefined method `MemoryPointer' for FFI:Module
        from (irb):5
>> address = FFI::MemoryPointer.new :pointer
=> #<MemoryPointer address=0x155f140 size=8>
>> p = FFI::Pointer.new(address)
TypeError: can't convert FFI::MemoryPointer into Integer
        from (irb):7:in `initialize'
        from (irb):7:in `new'
        from (irb):7