[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

dl/loader ptr issue

Brian Caswell

12/27/2005 10:32:00 PM

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

2 Answers

Takaaki Tateishi

12/28/2005 1:20:00 PM

0

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>




Brian Caswell

12/28/2005 4:35:00 PM

0

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