Dl/loader ptr issue

I'm having fits with passing pointers to a function I've imported via DL::Importable. I'm wrapping a simple opaque blob library (part of libdnet). However, the function I'm wrapping doesn't seem to work as I expect it to.

     extern "int blob_read(void *blob, void *buf, int size)"

Basically, read the specified amount (size) from the blob, and put it in buf. return status code. From what I've read, I should be able to wrap this with something akin to:

  def read (blob, len)
    ptr = DL.malloc(len)
    ret = Dnet.blob_read(blob, ptr.ref, len)
    return ret.to_s
  end

However, I get a EXC_BAD_ACCESS segv duing the to_s call. How should I be getting access to buf?

My current test is attached. I have validated that the shared object works as expected, when using dlopen/dlsym in C. (dnet.c works as an example usage of the C api)

Brian

dnet.rb (1008 Bytes)

dnet.c (1.48 KB)

Brian Caswell wrote:

However, the function I'm wrapping doesn't seem to work as I
expect it to.

    extern "int blob_read(void *blob, void *buf, int size)"

...

    def read (blob, len)
        ptr = DL.malloc(len)
        ret = Dnet.blob_read(blob, ptr.ref, len)
        return ret.to_s
    end

How about using "ptr" instead of "ptr.ref"?

···

--
Takaaki Tateishi <ttate@ttsky.net>

On Dec 28, 2005, at 8:20 AM, Takaaki Tateishi wrote:=

Brian Caswell wrote:

However, the function I'm wrapping doesn't seem to work as I
expect it to.

    extern "int blob_read(void *blob, void *buf, int size)"

...

    def read (blob, len)
        ptr = DL.malloc(len)
        ret = Dnet.blob_read(blob, ptr.ref, len)
        return ret.to_s
    end

How about using "ptr" instead of "ptr.ref"?

Thanks!

That worked, though the to_s doesn't, I needed to_str.

Brian