# GC Bug? Ruby 1.8.4 core dumps on a very small extension

**URL:** https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061
**Category:** ruby-talk
**Created:** [19 February 2006 22:47 UTC](https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061 "2006-02-19T22:47:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Danie\_Roux](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Danie\_Roux](https://rubytalk.org/u/Danie_Roux)
#### Post date: [19 February 2006 22:47 UTC](https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061/1 "2006-02-19T22:47:40Z")

</div>

Hi all,

Long (and tiring) story short:

I have an extension that is 40 lines\* in total, the C code and Ruby  
code that exercise it. It core dumps, while I repeatedly call a method  
that just returns Qtrue.

All it really does is:

rb\_iv\_set(self, "@v", 100);

in initialize. If I change that 100 to 99, it doesn't core dump.  
Change it back to 100, it core dumps within a few seconds.

Further, the while loop that executes it looks like this:

while true  
&nbsp;&nbsp;&nbsp;&nbsp;print ''  
&nbsp;&nbsp;&nbsp;&nbsp;b.buzz  
end

If I take out the print statement, it keeps on running. Put back the  
print statement, and it core dumps.

This is a self-compiled 1.8.4 on Ubuntu i386. A friend confirms that  
the same thing happens to him on Gentoo with 1.8.4.

I am attaching the code, hopefully its going to come through.

\* It was around 600, and use to core dump every 8 hours or so.  
Snipping it down to these 40 lines was pure blind luck, and many 8  
hour turnaround iterations.

[funny\_fail.tar.gz](https://rubytalk.org/uploads/short-url/r6YMOK1XXrZe5IS4qeGc3CYDsBi.gz) (540 Bytes)

> **···**
>
> --  
> Danie Roux \*shuffle\* Adore Unix [http://blog.acolyte.co.za](http://blog.acolyte.co.za)

---

<div class="post-metadata">

### Author: ![Ross\_Bamford4](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Ross\_Bamford4](https://rubytalk.org/u/Ross_Bamford4)
#### Post date: [19 February 2006 23:04 UTC](https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061/2 "2006-02-19T23:04:50Z")

</div>

Please try making this change:

--- buzz-orig.c 2006-02-19 23:01:22.000000000 +0000  
+++ buzz.c 2006-02-19 23:01:56.000000000 +0000  
@@ -8,7 +8,7 @@

static VALUE initialize(VALUE self)  
{  
- rb\_iv\_set(self, "@v", 100);  
+ rb\_iv\_set(self, "@v", INT2FIX(100));

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self;  
}

> **···**
>
> On Mon, 2006-02-20 at 07:47 +0900, Danie Roux wrote:
> 
> > Hi all,
> > 
> > Long (and tiring) story short:
> > 
> > I have an extension that is 40 lines\* in total, the C code and Ruby  
> > code that exercise it. It core dumps, while I repeatedly call a method  
> > that just returns Qtrue.
> 
> --  
> Ross Bamford - rosco@roscopeco.REMOVE.co.uk

---

<div class="post-metadata">

### Author: ![Danie\_Roux](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@Danie\_Roux](https://rubytalk.org/u/Danie_Roux)
#### Post date: [21 February 2006 16:54 UTC](https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061/3 "2006-02-21T16:54:00Z")

</div>

Ross,

Thank you. Moral of the story: Explicitly cast any C value into a Ruby one.

It still strikes me odd that it would run a couple of hundred  
iterations before breaking, though.

> **···**
>
> On 2/20/06, Ross Bamford \<rossrt@roscopeco.co.uk\> wrote:
> 
> > On Mon, 2006-02-20 at 07:47 +0900, Danie Roux wrote:  
> > \> Hi all,  
> > \>  
> > \> Long (and tiring) story short:  
> > \>  
> > \> I have an extension that is 40 lines\* in total, the C code and Ruby  
> > \> code that exercise it. It core dumps, while I repeatedly call a method  
> > \> that just returns Qtrue.
> > 
> > Please try making this change:  
> > - rb\_iv\_set(self, "@v", 100);  
> > + rb\_iv\_set(self, "@v", INT2FIX(100));
> 
> --  
> Danie Roux \*shuffle\* Adore Unix [http://blog.acolyte.co.za](http://blog.acolyte.co.za)

---

<div class="post-metadata">

### Author: ![Charles\_Mills1](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@Charles\_Mills1](https://rubytalk.org/u/Charles_Mills1)
#### Post date: [21 February 2006 19:33 UTC](https://rubytalk.org/t/gc-bug-ruby-1-8-4-core-dumps-on-a-very-small-extension/25061/4 "2006-02-21T19:33:31Z")

</div>

Danie Roux wrote:

> **···**
>
> > On 2/20/06, Ross Bamford \<rossrt@roscopeco.co.uk\> wrote:  
> > \> On Mon, 2006-02-20 at 07:47 +0900, Danie Roux wrote:  
> > \> \> Hi all,  
> > \> \>  
> > \> \> Long (and tiring) story short:  
> > \> \>  
> > \> \> I have an extension that is 40 lines\* in total, the C code and Ruby  
> > \> \> code that exercise it. It core dumps, while I repeatedly call a method  
> > \> \> that just returns Qtrue.  
> > \>  
> > \> Please try making this change:  
> > \> - rb\_iv\_set(self, "@v", 100);  
> > \> + rb\_iv\_set(self, "@v", INT2FIX(100));
> > 
> > Ross,
> > 
> > Thank you. Moral of the story: Explicitly cast any C value into a Ruby one.
> > 
> > It still strikes me odd that it would run a couple of hundred  
> > iterations before breaking, though.
> > 
> > --  
> > Danie Roux \*shuffle\* Adore Unix [http://blog.acolyte.co.za](http://blog.acolyte.co.za)
> 
> Assuming you're using a 32bit machine. 100 % 4 == 0, so Ruby thinks  
> 100 is a pointer to a Ruby object. (Dereferencing 100 causes the core  
> dump.) 99 % 2 == 1, so 99 looks like a Fixnum to Ruby -- but not 99,  
> 99\>\>1 I think.
> 
> It may take a couple hundred iterations before the GC runs.
> 
> -Charlie
