# Nested structures and C extensions

**URL:** <https://www.ruby-forum.com/t/nested-structures-and-c-extensions/109509>\
**Category:** Ruby\
**Created:** [July 16, 2007, 5:42am UTC](https://www.ruby-forum.com/t/nested-structures-and-c-extensions/109509 "2007-07-16T05:42:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![infamouxxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@infamouxxx](https://www.ruby-forum.com/u/infamouxxx)\
**Post date:** [July 16, 2007, 5:42am UTC](https://www.ruby-forum.com/t/nested-structures-and-c-extensions/109509/1 "2007-07-16T05:42:58Z")

</div>

Hey everybody,

I’ve been wrestling with an issue in writing a Ruby extension with C.  
I’m seeing that I can access (without Bus errors) top level attributes  
in my initial structure that aren’t nestled into another C structure  
that is a member of this initial structure.

On the other hand, if I try to access the members of some structure that  
is a member of the base structure after setting up a pointer to that  
base structure via Data\_Get\_Struct, I get Bus errors. Even after  
initializing all those variables in my C initializer, they don’t come  
back initialized when I pull them from a C implementation of an accessor  
method.

I read some older posts under “Data\_Make\_Struct() considered dangerous?”  
and the original poster described what may have been my problem. I’m  
not really sure what the conclusion to that thread was, however. I’m  
dealing with structs that contain multiple structs which, in turn,  
contain other structs (along with regular primitive data such as  
integers, etc.). I’m finding that the top-level structs give me easy,  
Bus error-free access to things like integers and chars. Things get  
hairy when I try to access structs from within instances of structs  
after having created a pointer with Data\_Get\_Struct.

I’m not really interested in using SWIG, etc., so does anybody have any  
ideas about how to go about fixing this problem?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![infamouxxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@infamouxxx](https://www.ruby-forum.com/u/infamouxxx)\
**Post date:** [July 16, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/nested-structures-and-c-extensions/109509/2 "2007-07-16T17:35:35Z")

</div>

Hi,

In message “Re: Nested structures and C extensions”  
on Mon, 16 Jul 2007 12:43:06 +0900, Donnie Brasco  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|On the other hand, if I try to access the members of some structure that  
|is a member of the base structure after setting up a pointer to that  
|base structure via Data\_Get\_Struct, I get Bus errors. Even after  
|initializing all those variables in my C initializer, they don’t come  
|back initialized when I pull them from a C implementation of an accessor  
|method.

Show us the code. Without seeing the actual code, there’s little  
chance for us to help you.

```
          matz.

```
