Re: how to understand



when call "boot_defclass("Object", 0)","rb_cClass" is not defined,why
"rb_class_boot" can call "rb_cClass"?

Dear Curious Friend

I'm not a Ruby expert, nor do I know much about C. But since your
curiosity infected me, I ventured into the Ruby source trying to figure
this out. The following are my findings.

rb_cObject, rb_cModule, rb_cClass all get allocated in NEWOBJ as struct
RClass.

NEWOBJ(obj, struct RClass);

In, OBJSETUP, they're cast to type struct RObject, and the structs
member klass gets assigned rb_cClass, which is a VALUE pointer:

OBJSETUP(obj, klass, flags);

#define OBJSETUP(obj,c,t) do {\
/*...*/
RBASIC(obj)->klass = (c);\
/*...*/
} while (0)

Here, rb_cClass gets assigned an RClass type like rb_cObject, and
rb_cModule. But it will also have a klass member that still holds a
pointer to the same struct, which rb_cClass pointed to before:
rb_cClass = boot_defclass("Class", rb_cModule);

As pointed out in the beginning, I'm not an expert on this, so the above
might very well be incorrect or incomplete. I would very much appreciate
it if someone with better insight could provide a more thorough
explanation and elaborate on why rb_cClass is needed.

Regards
wisccal
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: Yet another binary search tree library
    ... type is 'struct my_struct) containing the member 'my_node' pointed ... The pointer conversions ... and less assuming reading ...
    (comp.lang.c)
  • Re: how to store list of varying types
    ... represent that with those in the struct definitions? ... pointer null, and the second one the CString object. ... then have to finish constructing the packet by copying the two data objects ... start with an upper-case letter (so, I would use DataElement ...
    (microsoft.public.vc.mfc)
  • Re: N1298 - try/finally for C
    ... Do you mean that "struct throwInfo" should be optional? ... that exception handling would be supported only on implementations ... If the standard mandates an integer as throw argument, ... should be an integer wide enough to encode a pointer if necessary. ...
    (comp.std.c)
  • Re: [RFC][PATCH 1/4] cgroup: support per cgroup subsys state ID (CSS ID)
    ... Patch for Per-CSS(Cgroup Subsys State) ID and private hierarchy code. ... This patch attaches unique ID to each css and provides following. ... returns pointer to struct cgroup_subysys_state of id. ... using a pointer introduces no such restriction. ...
    (Linux-Kernel)