Subject:
[ruby-ffi] Re: Representing an opaque struct pointer
From:
Misty De Meo
Date:
10/17/13 2:14 AM
To:
ruby-ffi@googlegroups.com

To answer my own question...

The opaque pointer is passed just by creating a new FFI::MemoryPointer of type pointer, like so:

ptr = FFI::MemoryPointer.new(:pointer)
gme_open_file(path, ptr.get_pointer(0), 44100)

That said, I'm having a little difficulty wrapping this particular function - I'm sure I'm just passing one of the arguments wrong, but I'm not quite sure what I'm doing wrong.

I have the specific gme_open_file() function wrapped like this:

attach_function :gme_open_file, [ :string, :pointer, :int ], :gme_err_t

And called like above, where `path` is any string. It exits instantly with a failed assert from the gme library, `require(path && out)` - suggesting to me I'm passing one of the first two arguments incorrectly. My test C program (https://gist.github.com/mistydemeo/f6e0c6e716b3e8a57939) using the same function works fine.

On Wednesday, October 16, 2013 8:57:42 PM UTC-7, Misty De Meo wrote:
Apologies if this has been asked before - couldn't find it on the list
archives or the wiki.

A library I'm using has an opaque struct (actually a pointer to a C++
object usable in pure C code), which is used in most of the functions
in the public C API. How should I represent this in ffi?

For example, the definition and a function using it:

typedef struct Music_Emu Music_Emu;

gme_err_t gme_open_file( const char path [], Music_Emu** out, int sample_rate );

Thanks,
Misty

--
 
---
You received this message because you are subscribed to the Google Groups "ruby-ffi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-ffi+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.