Class object creation and scope

J

John Lam

------=_Part_17443_21779548.1134793880018
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

It appears that class objects (created via Class.new) are somewhat unusual.
I'm trying to write some code to inject some non-Ruby data into these
objects. I'm worried about what happens at GC time, so I need to use
Data_Wrap_Struct() to create the class objects so that I can register my
memory cleanup functions with Ruby.

However, this technique doesn't seem to work. If I try to create a class
object using:

Data_Wrap_Struct(rb_cClass, 0, ReleaseClassObject, my_data);

Ruby complains with a bizarre TypeError exception: "wrong argument type
Class (expected Class)".

I've tried some other workarounds involving the use of
rb_define_alloc_func(), which works fine for non class objects, but there
seems to be something special about how Ruby handles class objects.

A secondary question: what's the lifetime of a class object in Ruby? Are
these things ever garbage collected?

Thanks
-John
http://www.iunknown.com

------=_Part_17443_21779548.1134793880018--
 
J

John Lam

------=_Part_17583_13030774.1134796132945
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I just took a look at rb_class_boot(), and it looks like I can't make a
class object a T_DATA type. Ugh.

So it looks like my only hope is that class objects are never GC'd ...
pointers here would be super-helpful.

Thanks
-John
http://www.iunknown.com

------=_Part_17583_13030774.1134796132945--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top