matz / ruby-lang.org (Yukihiro Matsumoto) wrote in message news:<1021523383.560215.27303.nullmailer / picachu.netlab.jp>...
> Hi,
> 
> In message "Re: More embedding fun!"
>     on 02/05/16, Jeff Ward <wardja / jmu.edu> writes:
> 
> |> rb_gc_unregister_address().  See gc.c
>  
> |The plot thickens!  The object is being marked as part of a scope
> |object, so it's being ignored by my rb_gc_unregister_address() call. 
> |I tried making it a global, but the scope version still exsists and is
> |causing my program to crash out when it gets marked.  Any way around
> |this?  Can I call .new() on an object without it entering local scope?
> 
> I guess I misunderstood you and your problem.  Show me the code
> (snippet) that fails.
> 
> 							matz.


This has been edited recently, but it still has the same basic
problem.  Me is a pointer to a c++ object.  It contains two instance
variables, one to the ruby type associated with it and one to the ruby
object:

// Try to bypass local scope by assigning to a global variable
me->rbObject = rb_gv_set("$tObj", rb_funcall(me->rbType,
rb_intern("new"), 0));

// <snip>
// set a bunch of instance variables including		
VALUE val = rb_iv_set(me->rbObject, "@cObj", me);

// Tell ruby I'll handle this object
// I walked through this and it doesn't seam to unregister anything
rb_gc_unregister_address(&me->rbObject);
// should it be: eb_gc_unregister_address(VALUE *)(me->rbObject)?
// I tried that too

So when the garbage collector goes through to get rid of the variable
that's local scoped (which doesn't have a name), it sees the @cObj
variable, and think's it's a ruby object and try's to get rid of it
(which it can't do).

I got around the problem for now by changing the pointer to a fix and
back when I need it.  Is this my only recourse?