More embedding fun! 
Author Message
 More embedding fun!

I have another question that relates to embedding.  I've got a few
objects that were created in C and manipulated in ruby, but are not
really variables in ruby.  Anyway, when ruby invokes it's garbage
collector, it sees these objects with no ruby name associated with them
and assumes they're just garbage.  Worse, these have objects pointers in
them, and it's causing ruby to call rb_bug, which is exiting my program
(at least that's what I think is causing the problem).  

Long story short:  Can I have a variable not registered with the garbage
collector, then reregister it with the collector later (e.g. when I'm
done with the object)?  I know I can call rb_global_variable to get
register it, but is there something to get it out of the garbage
collector?  Or increase the reference count?  Thanks.

-Jeff Ward



Sun, 31 Oct 2004 07:35:50 GMT  
 More embedding fun!
Hi,

In message "More embedding fun!"

|Long story short:  Can I have a variable not registered with the garbage
|collector, then reregister it with the collector later (e.g. when I'm
|done with the object)?  I know I can call rb_global_variable to get
|register it, but is there something to get it out of the garbage
|collector?  Or increase the reference count?  Thanks.

rb_gc_unregister_address().  See gc.c

                                                        matz.



Sun, 31 Oct 2004 08:07:12 GMT  
 More embedding fun!

Quote:

> Hi,

> In message "More embedding fun!"

> |Long story short:  Can I have a variable not registered with the garbage
> |collector, then reregister it with the collector later (e.g. when I'm
> |done with the object)?  I know I can call rb_global_variable to get
> |register it, but is there something to get it out of the garbage
> |collector?  Or increase the reference count?  Thanks.

> rb_gc_unregister_address().  See gc.c

>                                                    matz.

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?


Mon, 01 Nov 2004 05:47:01 GMT  
 More embedding fun!
Hi,

In message "Re: More embedding fun!"

|> 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.



Mon, 01 Nov 2004 12:31:12 GMT  
 More embedding fun!

Quote:

> Hi,

> In message "Re: More embedding fun!"

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

// 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

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?



Tue, 02 Nov 2004 03:56:20 GMT  
 More embedding fun!
Hi,

At Fri, 17 May 2002 05:02:12 +0900,

Quote:

> // set a bunch of instance variables including            


Never set other than VALUE to instance variable.

--
Nobu Nakada



Wed, 03 Nov 2004 22:01:33 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. more embedding fun

2. count bits, fun fun fun.

3. Lot of embed point: Where to embed?

4. Embeds in Embeds

5. ABC-embed for legacy embed: Validate Record: Filter Checking

6. 30 new pages of embedded products + UK Embedded Show

7. Debuggin embedded python: building device drivers for an embedded python virtual machine

8. Embedding Tcl Interpreter in an embedded system

9. Fun with Clients

10. Fun APL/J Programming Problem

11. roman and arabic - some fun(ctions)

12. Fun trivia question. :-)

 

 
Powered by phpBB® Forum Software