Forum: Ruby dl/loader ptr issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bda9bdaf350ff0f6c75618bbb69b76d3?d=identicon&s=25 Brian Caswell (Guest)
on 2005-12-27 23:34
(Received via mailing list)
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
4d6c1ba19a3d46b45a1fd9ad2e622620?d=identicon&s=25 Takaaki Tateishi (Guest)
on 2005-12-28 14:22
(Received via mailing list)
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"?
Bda9bdaf350ff0f6c75618bbb69b76d3?d=identicon&s=25 Brian Caswell (Guest)
on 2005-12-28 17:35
(Received via mailing list)
On Dec 28, 2005, at 8:20 AM, Takaaki Tateishi wrote:=
>>     end
>
> How about using "ptr" instead of "ptr.ref"?

Thanks!

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

Brian
This topic is locked and can not be replied to.