# Dl/loader ptr issue

**URL:** <https://www.ruby-forum.com/t/dl-loader-ptr-issue/51204>\
**Category:** Ruby\
**Created:** [December 27, 2005, 11:34pm UTC](https://www.ruby-forum.com/t/dl-loader-ptr-issue/51204 "2005-12-27T23:34:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Caswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@Brian\_Caswell](https://www.ruby-forum.com/u/Brian_Caswell)\
**Post date:** [December 27, 2005, 11:34pm UTC](https://www.ruby-forum.com/t/dl-loader-ptr-issue/51204/1 "2005-12-27T23:34:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Caswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@Brian\_Caswell](https://www.ruby-forum.com/u/Brian_Caswell)\
**Post date:** [December 28, 2005, 2:22pm UTC](https://www.ruby-forum.com/t/dl-loader-ptr-issue/51204/2 "2005-12-28T14:22:16Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![Brian\_Caswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9d8465/32.png) [@Brian\_Caswell](https://www.ruby-forum.com/u/Brian_Caswell)\
**Post date:** [December 28, 2005, 5:35pm UTC](https://www.ruby-forum.com/t/dl-loader-ptr-issue/51204/3 "2005-12-28T17:35:41Z")

</div>

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

> > ```
> > end
> > 
> > ```
> 
> How about using “ptr” instead of “ptr.ref”?

Thanks!

That worked, though the to\_s doesn’t, I needed to\_str.

Brian
