Subject:
[ruby-ffi] **char issues
From:
bk
Date:
10/28/09 7:04 PM
To:
ruby-ffi


I am attempting to convert the augeas bindings to ffi. I did this with
JNA, and it was very helpful. The method in question is:

int aug_get(const augeas *aug, const char *path, const char **value);

where the last paraemeter returns the result of the get. I have
attempted to wrap this with

  attach_function :aug_get, [:pointer, :string, :pointer], :int

and then call this with:

    def get(path)
        ptr = FFI::MemoryPointer.new(:pointer, 1)
        AugeasLib.aug_get(@aug, path, ptr)
        strPtr = ptr.read_pointer()
        return strPtr.read_string()
    end

This works fine if the get returns something, but if the get ruturns a
null string I fail with:

FFI::NullPointerError: invalid memory read at address=(nil)


On the read_string call. In JNA I could create a StringArray to pass
this in. I did not see a higher level concept like this in ffi. I am
sure I am missing something simple, but I am not seeing it.

Thanks!

-- bk