Guest User

Untitled

a guest
Jul 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. ## eval.c
  2.  
  3. rb_mod_append_features(module, include)
  4. VALUE module, include;
  5. {
  6. switch (TYPE(include)) {
  7. case T_CLASS:
  8. case T_MODULE:
  9. break;
  10. default:
  11. Check_Type(include, T_CLASS);
  12. break;
  13. }
  14. rb_include_module(include, module);
  15.  
  16. return module;
  17. }
  18.  
  19. ## class.c
  20.  
  21. void
  22. rb_include_module(klass, module)
  23. VALUE klass, module;
  24. {
  25. VALUE p, c;
  26. int changed = 0;
  27.  
  28. rb_frozen_class_p(klass);
  29. if (!OBJ_TAINTED(klass)) {
  30. rb_secure(4);
  31. }
  32.  
  33. if (TYPE(module) != T_MODULE) {
  34. Check_Type(module, T_MODULE);
  35. }
  36.  
  37. OBJ_INFECT(klass, module);
  38. c = klass;
  39. while (module) {
  40. int superclass_seen = Qfalse;
  41.  
  42. if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
  43. rb_raise(rb_eArgError, "cyclic include detected");
  44. /* ignore if the module included already in superclasses */
  45. for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
  46. switch (BUILTIN_TYPE(p)) {
  47. case T_ICLASS:
  48. if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) {
  49. if (!superclass_seen) {
  50. c = p; /* move insertion point */
  51. }
  52. goto skip;
  53. }
  54. break;
  55. case T_CLASS:
  56. superclass_seen = Qtrue;
  57. break;
  58. }
  59. }
  60. c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
  61. changed = 1;
  62. skip:
  63. module = RCLASS(module)->super;
  64. }
  65. if (changed) rb_clear_cache();
  66. }
  67.  
  68.  
  69. static VALUE
  70. include_class_new(module, super)
  71. VALUE module, super;
  72. {
  73. NEWOBJ(klass, struct RClass);
  74. OBJSETUP(klass, rb_cClass, T_ICLASS);
  75.  
  76. if (BUILTIN_TYPE(module) == T_ICLASS) {
  77. module = RBASIC(module)->klass;
  78. }
  79. if (!RCLASS(module)->iv_tbl) {
  80. RCLASS(module)->iv_tbl = st_init_numtable();
  81. }
  82. klass->iv_tbl = RCLASS(module)->iv_tbl;
  83. klass->m_tbl = RCLASS(module)->m_tbl;
  84. klass->super = super;
  85. if (TYPE(module) == T_ICLASS) {
  86. RBASIC(klass)->klass = RBASIC(module)->klass;
  87. }
  88. else {
  89. RBASIC(klass)->klass = module;
  90. }
  91. OBJ_INFECT(klass, module);
  92. OBJ_INFECT(klass, super);
  93.  
  94. return (VALUE)klass;
  95. }
Add Comment
Please, Sign In to add comment