Skip to content
This repository
Newer
Older
100644 1302 lines (1173 sloc) 30.847 kb
511dc44a » Laurent Sansonetti
2008-02-25 initial import
1 /* -*-c-*- */
2 /*
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
3 * This file is included by vm_eval.c
511dc44a » Laurent Sansonetti
2008-02-25 initial import
4 */
5
6 #define CACHE_SIZE 0x800
7 #define CACHE_MASK 0x7ff
8 #define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
9
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
10 static void rb_vm_check_redefinition_opt_method(const NODE *node);
11
12 static ID __send__, object_id;
13 static ID removed, singleton_removed, undefined, singleton_undefined;
14 static ID eqq, each, aref, aset, match, missing;
15 static ID added, singleton_added;
16
511dc44a » Laurent Sansonetti
2008-02-25 initial import
17 struct cache_entry { /* method hash table. */
18 ID mid; /* method's id */
19 ID mid0; /* method's original id */
20 VALUE klass; /* receiver's class */
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
21 VALUE oklass; /* original's class */
511dc44a » Laurent Sansonetti
2008-02-25 initial import
22 NODE *method;
23 };
24
25 static struct cache_entry cache[CACHE_SIZE];
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
26 #define ruby_running (GET_VM()->running)
27 /* int ruby_running = 0; */
9808f45b » Laurent Sansonetti
2008-08-26 do not call method_added if enable_method_added is false (for better …
28 VALUE enable_method_added;
511dc44a » Laurent Sansonetti
2008-02-25 initial import
29
30 void
31 rb_clear_cache(void)
32 {
33 struct cache_entry *ent, *end;
34
35 rb_vm_change_state();
36
37 if (!ruby_running)
38 return;
39 ent = cache;
40 end = ent + CACHE_SIZE;
41 while (ent < end) {
42 ent->mid = 0;
43 ent++;
44 }
45 }
46
47 static void
48 rb_clear_cache_for_undef(VALUE klass, ID id)
49 {
50 struct cache_entry *ent, *end;
51
52 rb_vm_change_state();
53
54 if (!ruby_running)
55 return;
56 ent = cache;
57 end = ent + CACHE_SIZE;
58 while (ent < end) {
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
59 if (ent->oklass == klass && ent->mid == id) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
60 ent->mid = 0;
61 }
62 ent++;
63 }
64 }
65
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
66 #if !WITH_OBJC
511dc44a » Laurent Sansonetti
2008-02-25 initial import
67 static void
68 rb_clear_cache_by_id(ID id)
69 {
70 struct cache_entry *ent, *end;
71
72 rb_vm_change_state();
73
74 if (!ruby_running)
75 return;
76 ent = cache;
77 end = ent + CACHE_SIZE;
78 while (ent < end) {
79 if (ent->mid == id) {
80 ent->mid = 0;
81 }
82 ent++;
83 }
84 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
85 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
86
87 void
88 rb_clear_cache_by_class(VALUE klass)
89 {
90 struct cache_entry *ent, *end;
91
92 rb_vm_change_state();
93
94 if (!ruby_running)
95 return;
96 ent = cache;
97 end = ent + CACHE_SIZE;
98 while (ent < end) {
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
99 if (ent->klass == klass || ent->oklass == klass) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
100 ent->mid = 0;
101 }
102 ent++;
103 }
104 }
105
106 void
107 rb_add_method(VALUE klass, ID mid, NODE * node, int noex)
108 {
109 NODE *body;
110
111 if (NIL_P(klass) || klass == 0) {
112 klass = rb_cObject;
113 }
114 if (rb_safe_level() >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) {
115 rb_raise(rb_eSecurityError, "Insecure: can't define method");
116 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
117 if (!RCLASS_SINGLETON(klass) &&
511dc44a » Laurent Sansonetti
2008-02-25 initial import
118 node && nd_type(node) != NODE_ZSUPER &&
119 (mid == rb_intern("initialize") || mid == rb_intern("initialize_copy"))) {
120 noex = NOEX_PRIVATE | noex;
121 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
122 else if (RCLASS_SINGLETON(klass) && node
511dc44a » Laurent Sansonetti
2008-02-25 initial import
123 && nd_type(node) == NODE_CFUNC && mid == rb_intern("allocate")) {
124 rb_warn
125 ("defining %s.allocate is deprecated; use rb_define_alloc_func()",
126 rb_class2name(rb_iv_get(klass, "__attached__")));
127 mid = ID_ALLOCATOR;
128 }
129 if (OBJ_FROZEN(klass)) {
130 rb_error_frozen("class/module");
131 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
132 #if !WITH_OBJC
511dc44a » Laurent Sansonetti
2008-02-25 initial import
133 rb_clear_cache_by_id(mid);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
134 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
135
136 /*
137 * NODE_METHOD (NEW_METHOD(body, klass, vis)):
138 * nd_body : method body // (2) // mark
139 * nd_clss : klass // (1) // mark
140 * nd_noex : visibility // (3)
141 *
142 * NODE_FBODY (NEW_FBODY(method, alias)):
143 * nd_body : method (NODE_METHOD) // (2) // mark
144 * nd_oid : original id // (1)
145 * nd_cnt : alias count // (3)
146 */
147 if (node) {
148 body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_WITH_SAFE(noex)), 0);
149 }
150 else {
151 body = 0;
152 }
153
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
154 #if !WITH_OBJC // TODO
511dc44a » Laurent Sansonetti
2008-02-25 initial import
155 {
156 /* check re-definition */
157 st_data_t data;
158 NODE *old_node;
159
160 if (st_lookup(RCLASS_M_TBL(klass), mid, &data)) {
161 old_node = (NODE *)data;
162 if (old_node) {
163 if (nd_type(old_node->nd_body->nd_body) == NODE_CFUNC) {
164 rb_vm_check_redefinition_opt_method(old_node);
165 }
166 if (RTEST(ruby_verbose) && node && old_node->nd_cnt == 0 && old_node->nd_body) {
167 rb_warning("method redefined; discarding old %s", rb_id2name(mid));
168 }
169 }
eee9d7b4 » Laurent Sansonetti
2008-05-18 sync with ruby trunk r15665
170 }
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
171 if (klass == rb_cObject && node && mid == idInitialize) {
eee9d7b4 » Laurent Sansonetti
2008-05-18 sync with ruby trunk r15665
172 rb_warn("redefining Object#initialize may cause infinite loop");
511dc44a » Laurent Sansonetti
2008-02-25 initial import
173 }
174
175 if (mid == object_id || mid == __send__) {
176 if (node && nd_type(node) == RUBY_VM_METHOD_NODE) {
177 rb_warn("redefining `%s' may cause serious problem",
178 rb_id2name(mid));
179 }
180 }
181 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
182 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
183
184 #if WITH_OBJC
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
185 rb_objc_register_ruby_method(klass, mid, body != NULL ? body->nd_body : NULL);
186 #else
187 st_insert(RCLASS_M_TBL(klass), mid, (st_data_t) body);
511dc44a » Laurent Sansonetti
2008-02-25 initial import
188 #endif
189
9808f45b » Laurent Sansonetti
2008-08-26 do not call method_added if enable_method_added is false (for better …
190 if (node && mid != ID_ALLOCATOR && ruby_running && enable_method_added == Qtrue) {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
191 if (RCLASS_SINGLETON(klass)) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
192 rb_funcall(rb_iv_get(klass, "__attached__"), singleton_added, 1,
193 ID2SYM(mid));
194 }
195 else {
196 rb_funcall(klass, added, 1, ID2SYM(mid));
197 }
198 }
199 }
200
201 void
202 rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE))
203 {
204 Check_Type(klass, T_CLASS);
205 rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
206 NOEX_PUBLIC);
511dc44a » Laurent Sansonetti
2008-02-25 initial import
207 }
208
209 void
210 rb_undef_alloc_func(VALUE klass)
211 {
212 Check_Type(klass, T_CLASS);
213 rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, 0, NOEX_UNDEF);
214 }
215
216 rb_alloc_func_t
217 rb_get_alloc_func(VALUE klass)
218 {
219 NODE *n;
220 Check_Type(klass, T_CLASS);
221 n = rb_method_node(CLASS_OF(klass), ID_ALLOCATOR);
222 if (!n) return 0;
223 if (nd_type(n) != NODE_METHOD) return 0;
224 n = n->nd_body;
225 if (nd_type(n) != NODE_CFUNC) return 0;
226 return (rb_alloc_func_t)n->nd_cfnc;
227 }
228
229 static NODE *
230 search_method(VALUE klass, ID id, VALUE *klassp)
231 {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
232 #if WITH_OBJC
233 NODE *node;
234 if (klass == 0)
235 return NULL;
236 node = rb_method_node(klass, id);
237 if (node != NULL) {
238 if (klassp != NULL) /* TODO honour klassp */
239 *klassp = klass;
240 }
241 return node;
242 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
243 st_data_t body;
244
245 if (!klass) {
246 return 0;
247 }
248
249 while (!st_lookup(RCLASS_M_TBL(klass), id, &body)) {
250 klass = RCLASS_SUPER(klass);
251 if (!klass)
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
252 return 0;
511dc44a » Laurent Sansonetti
2008-02-25 initial import
253 }
254
255 if (klassp) {
256 *klassp = klass;
257 }
258
259 return (NODE *)body;
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
260 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
261 }
262
263 /*
264 * search method body (NODE_METHOD)
265 * with : klass and id
266 * without : method cache
267 *
268 * if you need method node with method cache, use
269 * rb_method_node()
270 */
271 NODE *
272 rb_get_method_body(VALUE klass, ID id, ID *idp)
273 {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
274 #if WITH_OBJC
275 return search_method(klass, id, NULL);
276 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
277 NODE *volatile fbody, *body;
278 NODE *method;
279
280 if ((fbody = search_method(klass, id, 0)) == 0 || !fbody->nd_body) {
281 /* store empty info in cache */
282 struct cache_entry *ent;
283 ent = cache + EXPR1(klass, id);
284 ent->klass = klass;
285 ent->mid = ent->mid0 = id;
286 ent->method = 0;
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
287 ent->oklass = 0;
511dc44a » Laurent Sansonetti
2008-02-25 initial import
288 return 0;
289 }
290
291 method = fbody->nd_body;
292
293 if (ruby_running) {
294 /* store in cache */
295 struct cache_entry *ent;
296 ent = cache + EXPR1(klass, id);
297 ent->klass = klass;
298 ent->mid = id;
299 ent->mid0 = fbody->nd_oid;
300 ent->method = body = method;
d31a74f3 » Laurent Sansonetti
2008-03-07 synchronized with ruby trunk r15665
301 ent->oklass = method->nd_clss;
511dc44a » Laurent Sansonetti
2008-02-25 initial import
302 }
303 else {
304 body = method;
305 }
306
307 if (idp) {
308 *idp = fbody->nd_oid;
309 }
310
311 return body;
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
312 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
313 }
314
315 NODE *
316 rb_method_node(VALUE klass, ID id)
317 {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
318 #if WITH_OBJC
319 NODE *node = rb_objc_method_node(klass, id, NULL, NULL);
320 if (node == NULL && id != ID_ALLOCATOR) {
321 const char *id_str = rb_id2name(id);
322 size_t slen = strlen(id_str);
323
324 if (strcmp(id_str, "retain") == 0
325 || strcmp(id_str, "release") == 0
326 || strcmp(id_str, "zone") == 0) {
327 char buf[100];
328 snprintf(buf, sizeof buf, "__rb_%s__", id_str);
329 return rb_method_node(klass, rb_intern(buf));
330 }
331 else {
332 if (id_str[slen - 1] == ':') {
333 return NULL;
334 }
335 else {
336 char buf[100];
337 snprintf(buf, sizeof buf, "%s:", id_str);
338 return rb_method_node(klass, rb_intern(buf));
339 }
340 }
341 }
342 return node;
343 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
344 struct cache_entry *ent;
345
346 ent = cache + EXPR1(klass, id);
347 if (ent->mid == id && ent->klass == klass && ent->method) {
348 return ent->method;
349 }
350
351 return rb_get_method_body(klass, id, 0);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
352 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
353 }
354
355 static void
356 remove_method(VALUE klass, ID mid)
357 {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
358 #if !WITH_OBJC
511dc44a » Laurent Sansonetti
2008-02-25 initial import
359 st_data_t data;
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
360 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
361 NODE *body = 0;
362
363 if (klass == rb_cObject) {
364 rb_secure(4);
365 }
366 if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
367 rb_raise(rb_eSecurityError, "Insecure: can't remove method");
368 }
369 if (OBJ_FROZEN(klass))
370 rb_error_frozen("class/module");
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
371 if (mid == object_id || mid == __send__ || mid == idInitialize) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
372 rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
373 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
374 #if WITH_OBJC
f8ce513d » Laurent Sansonetti
2008-08-31 implement #remove_method
375 SEL sel;
376 Method m;
377
378 sel = sel_registerName(rb_id2name(mid));
379 m = class_getInstanceMethod((Class)klass, sel);
380 if (m == NULL) {
381 char buf[100];
382 size_t len = strlen((char *)sel);
383 if (((char *)sel)[len - 1] != ':') {
384 snprintf(buf, sizeof buf, "%s:", (char *)sel);
385 sel = sel_registerName(buf);
386 m = class_getInstanceMethod((Class)klass, sel);
387 }
388 }
389 if (m == NULL) {
390 rb_name_error(mid, "method `%s' not defined in %s",
391 rb_id2name(mid), rb_class2name(klass));
392 }
393 if (rb_objc_method_node3(method_getImplementation(m)) == NULL) {
394 rb_warn("removing pure Objective-C method `%s' may cause serious problem", rb_id2name(mid));
395 }
396 method_setImplementation(m, NULL);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
397 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
398 if (st_lookup(RCLASS_M_TBL(klass), mid, &data)) {
399 body = (NODE *)data;
400 if (!body || !body->nd_body) body = 0;
401 else {
402 st_delete(RCLASS_M_TBL(klass), &mid, &data);
403 }
404 }
405 if (!body) {
406 rb_name_error(mid, "method `%s' not defined in %s",
407 rb_id2name(mid), rb_class2name(klass));
408 }
f8ce513d » Laurent Sansonetti
2008-08-31 implement #remove_method
409 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
410
411 if (nd_type(body->nd_body->nd_body) == NODE_CFUNC) {
412 rb_vm_check_redefinition_opt_method(body);
413 }
414
415 rb_clear_cache_for_undef(klass, mid);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
416 if (RCLASS_SINGLETON(klass)) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
417 rb_funcall(rb_iv_get(klass, "__attached__"), singleton_removed, 1,
418 ID2SYM(mid));
419 }
420 else {
421 rb_funcall(klass, removed, 1, ID2SYM(mid));
422 }
423 }
424
425 void
426 rb_remove_method(VALUE klass, const char *name)
427 {
428 remove_method(klass, rb_intern(name));
429 }
430
431 /*
432 * call-seq:
433 * remove_method(symbol) => self
434 *
435 * Removes the method identified by _symbol_ from the current
436 * class. For an example, see <code>Module.undef_method</code>.
437 */
438
439 static VALUE
440 rb_mod_remove_method(int argc, VALUE *argv, VALUE mod)
441 {
442 int i;
443
444 for (i = 0; i < argc; i++) {
445 remove_method(mod, rb_to_id(argv[i]));
446 }
447 return mod;
448 }
449
450 #undef rb_disable_super
451 #undef rb_enable_super
452
453 void
454 rb_disable_super(VALUE klass, const char *name)
455 {
456 /* obsolete - no use */
457 }
458
459 void
460 rb_enable_super(VALUE klass, const char *name)
461 {
462 rb_warning("rb_enable_super() is obsolete");
463 }
464
465 static void
466 rb_export_method(VALUE klass, ID name, ID noex)
467 {
468 NODE *fbody;
469 VALUE origin;
470
471 if (klass == rb_cObject) {
472 rb_secure(4);
473 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
474 #if WITH_OBJC
475 fbody = rb_method_node(klass, name);
476 if (fbody == NULL && TYPE(klass) == T_MODULE) {
477 fbody = rb_method_node(rb_cObject, name);
478 origin = rb_method_node(rb_cObject, name) == fbody
479 ? rb_cObject : klass;
480 }
481 else {
482 origin = rb_method_node(RCLASS_SUPER(klass), name) == fbody
483 ? RCLASS_SUPER(klass) : klass;
484 }
485 if (fbody == NULL) {
486 rb_print_undef(klass, name, 0);
487 }
488 if (fbody->nd_noex != noex) {
489 if (nd_type(fbody->nd_body) == NODE_CFUNC) {
490 rb_vm_check_redefinition_opt_method(fbody);
491 }
492 if (klass == origin) {
493 fbody->nd_noex = noex;
494 }
495 else {
496 rb_add_method(klass, name, NEW_ZSUPER(), noex);
497 }
498 }
499 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
500 fbody = search_method(klass, name, &origin);
501 if (!fbody && TYPE(klass) == T_MODULE) {
502 fbody = search_method(rb_cObject, name, &origin);
503 }
504 if (!fbody || !fbody->nd_body) {
505 rb_print_undef(klass, name, 0);
506 }
507 if (fbody->nd_body->nd_noex != noex) {
508 if (nd_type(fbody->nd_body->nd_body) == NODE_CFUNC) {
509 rb_vm_check_redefinition_opt_method(fbody);
510 }
511 if (klass == origin) {
512 fbody->nd_body->nd_noex = noex;
513 }
514 else {
515 rb_add_method(klass, name, NEW_ZSUPER(), noex);
516 }
517 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
518 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
519 }
520
521 int
522 rb_method_boundp(VALUE klass, ID id, int ex)
523 {
524 NODE *method;
525
526 if ((method = rb_method_node(klass, id)) != 0) {
527 if (ex && (method->nd_noex & NOEX_PRIVATE)) {
528 return Qfalse;
529 }
530 return Qtrue;
531 }
532 return Qfalse;
533 }
534
535 void
536 rb_attr(VALUE klass, ID id, int read, int write, int ex)
537 {
538 const char *name;
539 ID attriv;
540 int noex;
541
542 if (!ex) {
543 noex = NOEX_PUBLIC;
544 }
545 else {
546 if (SCOPE_TEST(NOEX_PRIVATE)) {
547 noex = NOEX_PRIVATE;
548 rb_warning((SCOPE_CHECK(NOEX_MODFUNC)) ?
549 "attribute accessor as module_function" :
550 "private attribute?");
551 }
552 else if (SCOPE_TEST(NOEX_PROTECTED)) {
553 noex = NOEX_PROTECTED;
554 }
555 else {
556 noex = NOEX_PUBLIC;
557 }
558 }
559
560 if (!rb_is_local_id(id) && !rb_is_const_id(id)) {
561 rb_name_error(id, "invalid attribute name `%s'", rb_id2name(id));
562 }
563 name = rb_id2name(id);
564 if (!name) {
565 rb_raise(rb_eArgError, "argument needs to be symbol or string");
566 }
567 attriv = rb_intern_str(rb_sprintf("@%s", name));
568 if (read) {
569 rb_add_method(klass, id, NEW_IVAR(attriv), noex);
570 }
571 if (write) {
572 rb_add_method(klass, rb_id_attrset(id), NEW_ATTRSET(attriv), noex);
510f2e99 » Laurent Sansonetti
2008-08-30 fix for #40
573 #if WITH_OBJC
574 rb_objc_define_kvo_setter(klass, id);
575 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
576 }
577 }
578
579 void
580 rb_undef(VALUE klass, ID id)
581 {
582 VALUE origin;
583 NODE *body;
584
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
585 if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
586 rb_secure(4);
587 }
588 if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
589 rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'",
590 rb_id2name(id));
591 }
592 rb_frozen_class_p(klass);
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
593 if (id == object_id || id == __send__ || id == idInitialize) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
594 rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
595 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
596 /* TODO: warn if a very important method of NSObject is undefined
597 * by default, pure objc methods are not exposed by introspections API
598 */
511dc44a » Laurent Sansonetti
2008-02-25 initial import
599 body = search_method(klass, id, &origin);
600 if (!body || !body->nd_body) {
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
601 const char *s0 = " class";
511dc44a » Laurent Sansonetti
2008-02-25 initial import
602 VALUE c = klass;
603
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
604 if (RCLASS_SINGLETON(c)) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
605 VALUE obj = rb_iv_get(klass, "__attached__");
606
607 switch (TYPE(obj)) {
608 case T_MODULE:
609 case T_CLASS:
610 c = obj;
611 s0 = "";
612 }
613 }
614 else if (TYPE(c) == T_MODULE) {
615 s0 = " module";
616 }
617 rb_name_error(id, "undefined method `%s' for%s `%s'",
618 rb_id2name(id), s0, rb_class2name(c));
619 }
620
621 rb_add_method(klass, id, 0, NOEX_PUBLIC);
622
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
623 if (RCLASS_SINGLETON(klass)) {
511dc44a » Laurent Sansonetti
2008-02-25 initial import
624 rb_funcall(rb_iv_get(klass, "__attached__"),
625 singleton_undefined, 1, ID2SYM(id));
626 }
627 else {
628 rb_funcall(klass, undefined, 1, ID2SYM(id));
629 }
630 }
631
632 /*
633 * call-seq:
634 * undef_method(symbol) => self
635 *
636 * Prevents the current class from responding to calls to the named
637 * method. Contrast this with <code>remove_method</code>, which deletes
638 * the method from the particular class; Ruby will still search
639 * superclasses and mixed-in modules for a possible receiver.
640 *
641 * class Parent
642 * def hello
643 * puts "In parent"
644 * end
645 * end
646 * class Child < Parent
647 * def hello
648 * puts "In child"
649 * end
650 * end
651 *
652 *
653 * c = Child.new
654 * c.hello
655 *
656 *
657 * class Child
658 * remove_method :hello # remove from child, still in parent
659 * end
660 * c.hello
661 *
662 *
663 * class Child
664 * undef_method :hello # prevent any calls to 'hello'
665 * end
666 * c.hello
667 *
668 * <em>produces:</em>
669 *
670 * In child
671 * In parent
672 * prog.rb:23: undefined method `hello' for #<Child:0x401b3bb4> (NoMethodError)
673 */
674
675 static VALUE
676 rb_mod_undef_method(int argc, VALUE *argv, VALUE mod)
677 {
678 int i;
679 for (i = 0; i < argc; i++) {
680 rb_undef(mod, rb_to_id(argv[i]));
681 }
682 return mod;
683 }
684
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
685 /*
686 * call-seq:
687 * mod.method_defined?(symbol) => true or false
688 *
689 * Returns +true+ if the named method is defined by
690 * _mod_ (or its included modules and, if _mod_ is a class,
691 * its ancestors). Public and protected methods are matched.
692 *
693 * module A
694 * def method1() end
695 * end
696 * class B
697 * def method2() end
698 * end
699 * class C < B
700 * include A
701 * def method3() end
702 * end
703 *
704 * A.method_defined? :method1 #=> true
705 * C.method_defined? "method1" #=> true
706 * C.method_defined? "method2" #=> true
707 * C.method_defined? "method3" #=> true
708 * C.method_defined? "method4" #=> false
709 */
710
711 static VALUE
712 rb_mod_method_defined(VALUE mod, VALUE mid)
713 {
714 return rb_method_boundp(mod, rb_to_id(mid), 1);
715 }
716
717 #define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
718
719 /*
720 * call-seq:
721 * mod.public_method_defined?(symbol) => true or false
722 *
723 * Returns +true+ if the named public method is defined by
724 * _mod_ (or its included modules and, if _mod_ is a class,
725 * its ancestors).
726 *
727 * module A
728 * def method1() end
729 * end
730 * class B
731 * protected
732 * def method2() end
733 * end
734 * class C < B
735 * include A
736 * def method3() end
737 * end
738 *
739 * A.method_defined? :method1 #=> true
740 * C.public_method_defined? "method1" #=> true
741 * C.public_method_defined? "method2" #=> false
742 * C.method_defined? "method2" #=> true
743 */
744
745 static VALUE
746 rb_mod_public_method_defined(VALUE mod, VALUE mid)
747 {
748 ID id = rb_to_id(mid);
749 NODE *method;
750
751 method = rb_method_node(mod, id);
752 if (method) {
753 if (VISI_CHECK(method->nd_noex, NOEX_PUBLIC))
754 return Qtrue;
755 }
756 return Qfalse;
757 }
758
759 /*
760 * call-seq:
761 * mod.private_method_defined?(symbol) => true or false
762 *
763 * Returns +true+ if the named private method is defined by
764 * _ mod_ (or its included modules and, if _mod_ is a class,
765 * its ancestors).
766 *
767 * module A
768 * def method1() end
769 * end
770 * class B
771 * private
772 * def method2() end
773 * end
774 * class C < B
775 * include A
776 * def method3() end
777 * end
778 *
779 * A.method_defined? :method1 #=> true
780 * C.private_method_defined? "method1" #=> false
781 * C.private_method_defined? "method2" #=> true
782 * C.method_defined? "method2" #=> false
783 */
784
785 static VALUE
786 rb_mod_private_method_defined(VALUE mod, VALUE mid)
787 {
788 ID id = rb_to_id(mid);
789 NODE *method;
790
791 method = rb_method_node(mod, id);
792 if (method) {
793 if (VISI_CHECK(method->nd_noex, NOEX_PRIVATE))
794 return Qtrue;
795 }
796 return Qfalse;
797 }
798
799 /*
800 * call-seq:
801 * mod.protected_method_defined?(symbol) => true or false
802 *
803 * Returns +true+ if the named protected method is defined
804 * by _mod_ (or its included modules and, if _mod_ is a
805 * class, its ancestors).
806 *
807 * module A
808 * def method1() end
809 * end
810 * class B
811 * protected
812 * def method2() end
813 * end
814 * class C < B
815 * include A
816 * def method3() end
817 * end
818 *
819 * A.method_defined? :method1 #=> true
820 * C.protected_method_defined? "method1" #=> false
821 * C.protected_method_defined? "method2" #=> true
822 * C.method_defined? "method2" #=> true
823 */
824
825 static VALUE
826 rb_mod_protected_method_defined(VALUE mod, VALUE mid)
827 {
828 ID id = rb_to_id(mid);
829 NODE *method;
830
831 method = rb_method_node(mod, id);
832 if (method) {
833 if (VISI_CHECK(method->nd_noex, NOEX_PROTECTED))
834 return Qtrue;
835 }
836 return Qfalse;
837 }
838
511dc44a » Laurent Sansonetti
2008-02-25 initial import
839 void
840 rb_alias(VALUE klass, ID name, ID def)
841 {
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
842 #if !WITH_OBJC
511dc44a » Laurent Sansonetti
2008-02-25 initial import
843 NODE *orig_fbody, *node;
844 st_data_t data;
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
845 #endif
846 VALUE singleton = 0;
511dc44a » Laurent Sansonetti
2008-02-25 initial import
847
848 rb_frozen_class_p(klass);
849 if (klass == rb_cObject) {
850 rb_secure(4);
851 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
852 #if WITH_OBJC
853 if (RCLASS_SINGLETON(klass)) {
854 singleton = rb_iv_get(klass, "__attached__");
855 }
856 rb_objc_alias(klass, name, def);
857 #else
511dc44a » Laurent Sansonetti
2008-02-25 initial import
858 orig_fbody = search_method(klass, def, 0);
859 if (!orig_fbody || !orig_fbody->nd_body) {
860 if (TYPE(klass) == T_MODULE) {
861 orig_fbody = search_method(rb_cObject, def, 0);
862 }
863 }
864 if (!orig_fbody || !orig_fbody->nd_body) {
865 rb_print_undef(klass, def, 0);
866 }
867 if (FL_TEST(klass, FL_SINGLETON)) {
868 singleton = rb_iv_get(klass, "__attached__");
869 }
870
871 orig_fbody->nd_cnt++;
872
873 if (st_lookup(RCLASS_M_TBL(klass), name, &data)) {
874 node = (NODE *)data;
875 if (node) {
876 if (RTEST(ruby_verbose) && node->nd_cnt == 0 && node->nd_body) {
877 rb_warning("discarding old %s", rb_id2name(name));
878 }
879 if (nd_type(node->nd_body->nd_body) == NODE_CFUNC) {
880 rb_vm_check_redefinition_opt_method(node);
881 }
882 }
883 }
884
885 st_insert(RCLASS_M_TBL(klass), name,
886 (st_data_t) NEW_FBODY(
887 NEW_METHOD(orig_fbody->nd_body->nd_body,
888 orig_fbody->nd_body->nd_clss,
889 NOEX_WITH_SAFE(orig_fbody->nd_body->nd_noex)), def));
890
891 rb_clear_cache_by_id(name);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
892 #endif
511dc44a » Laurent Sansonetti
2008-02-25 initial import
893
894 if (!ruby_running) return;
895
896 if (singleton) {
897 rb_funcall(singleton, singleton_added, 1, ID2SYM(name));
898 }
899 else {
900 rb_funcall(klass, added, 1, ID2SYM(name));
901 }
902 }
903
904 /*
905 * call-seq:
906 * alias_method(new_name, old_name) => self
907 *
908 * Makes <i>new_name</i> a new copy of the method <i>old_name</i>. This can
909 * be used to retain access to methods that are overridden.
910 *
911 * module Mod
912 * alias_method :orig_exit, :exit
913 * def exit(code=0)
914 * puts "Exiting with code #{code}"
915 * orig_exit(code)
916 * end
917 * end
918 * include Mod
919 * exit(99)
920 *
921 * <em>produces:</em>
922 *
923 * Exiting with code 99
924 */
925
926 static VALUE
927 rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname)
928 {
929 rb_alias(mod, rb_to_id(newname), rb_to_id(oldname));
930 return mod;
931 }
932
933 static void
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
934 secure_visibility(VALUE self)
935 {
936 if (rb_safe_level() >= 4 && !OBJ_TAINTED(self)) {
937 rb_raise(rb_eSecurityError,
938 "Insecure: can't change method visibility");
939 }
940 }
941
942 static void
943 set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
944 {
945 int i;
946 secure_visibility(self);
947 for (i = 0; i < argc; i++) {
948 rb_export_method(self, rb_to_id(argv[i]), ex);
949 }
950 rb_clear_cache_by_class(self);
951 }
952
953 /*
954 * call-seq:
955 * public => self
956 * public(symbol, ...) => self
957 *
958 * With no arguments, sets the default visibility for subsequently
959 * defined methods to public. With arguments, sets the named methods to
960 * have public visibility.
961 */
962
963 static VALUE
964 rb_mod_public(int argc, VALUE *argv, VALUE module)
965 {
966 secure_visibility(module);
967 if (argc == 0) {
968 SCOPE_SET(NOEX_PUBLIC);
969 }
970 else {
971 set_method_visibility(module, argc, argv, NOEX_PUBLIC);
972 }
973 return module;
974 }
975
976 /*
977 * call-seq:
978 * protected => self
979 * protected(symbol, ...) => self
980 *
981 * With no arguments, sets the default visibility for subsequently
982 * defined methods to protected. With arguments, sets the named methods
983 * to have protected visibility.
984 */
985
986 static VALUE
987 rb_mod_protected(int argc, VALUE *argv, VALUE module)
988 {
989 secure_visibility(module);
990 if (argc == 0) {
991 SCOPE_SET(NOEX_PROTECTED);
992 }
993 else {
994 set_method_visibility(module, argc, argv, NOEX_PROTECTED);
995 }
996 return module;
997 }
998
999 /*
1000 * call-seq:
1001 * private => self
1002 * private(symbol, ...) => self
1003 *
1004 * With no arguments, sets the default visibility for subsequently
1005 * defined methods to private. With arguments, sets the named methods
1006 * to have private visibility.
1007 *
1008 * module Mod
1009 * def a() end
1010 * def b() end
1011 * private
1012 * def c() end
1013 * private :a
1014 * end
1015 * Mod.private_instance_methods #=> [:a, :c]
1016 */
1017
1018 static VALUE
1019 rb_mod_private(int argc, VALUE *argv, VALUE module)
1020 {
1021 secure_visibility(module);
1022 if (argc == 0) {
1023 SCOPE_SET(NOEX_PRIVATE);
1024 }
1025 else {
1026 set_method_visibility(module, argc, argv, NOEX_PRIVATE);
1027 }
1028 return module;
1029 }
1030
1031 /*
1032 * call-seq:
1033 * mod.public_class_method(symbol, ...) => mod
1034 *
1035 * Makes a list of existing class methods public.
1036 */
1037
1038 static VALUE
1039 rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
1040 {
1041 set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PUBLIC);
1042 return obj;
1043 }
1044
1045 /*
1046 * call-seq:
1047 * mod.private_class_method(symbol, ...) => mod
1048 *
1049 * Makes existing class methods private. Often used to hide the default
1050 * constructor <code>new</code>.
1051 *
1052 * class SimpleSingleton # Not thread safe
1053 * private_class_method :new
1054 * def SimpleSingleton.create(*args, &block)
1055 * @me = new(*args, &block) if ! @me
1056 * @me
1057 * end
1058 * end
1059 */
1060
1061 static VALUE
1062 rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
1063 {
1064 set_method_visibility(CLASS_OF(obj), argc, argv, NOEX_PRIVATE);
1065 return obj;
1066 }
1067
1068 /*
1069 * call-seq:
1070 * public
1071 * public(symbol, ...)
1072 *
1073 * With no arguments, sets the default visibility for subsequently
1074 * defined methods to public. With arguments, sets the named methods to
1075 * have public visibility.
1076 */
1077
1078 static VALUE
1079 top_public(int argc, VALUE *argv)
1080 {
1081 return rb_mod_public(argc, argv, rb_cObject);
1082 }
1083
1084 static VALUE
1085 top_private(int argc, VALUE *argv)
1086 {
1087 return rb_mod_private(argc, argv, rb_cObject);
1088 }
1089
1090 /*
1091 * call-seq:
1092 * module_function(symbol, ...) => self
1093 *
1094 * Creates module functions for the named methods. These functions may
1095 * be called with the module as a receiver, and also become available
1096 * as instance methods to classes that mix in the module. Module
1097 * functions are copies of the original, and so may be changed
1098 * independently. The instance-method versions are made private. If
1099 * used with no arguments, subsequently defined methods become module
1100 * functions.
1101 *
1102 * module Mod
1103 * def one
1104 * "This is one"
1105 * end
1106 * module_function :one
1107 * end
1108 * class Cls
1109 * include Mod
1110 * def callOne
1111 * one
1112 * end
1113 * end
1114 * Mod.one #=> "This is one"
1115 * c = Cls.new
1116 * c.callOne #=> "This is one"
1117 * module Mod
1118 * def one
1119 * "This is the new one"
1120 * end
1121 * end
1122 * Mod.one #=> "This is one"
1123 * c.callOne #=> "This is the new one"
1124 */
1125
1126 static VALUE
1127 rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
1128 {
1129 int i;
1130 ID id;
1131 NODE *fbody;
1132
1133 if (TYPE(module) != T_MODULE) {
1134 rb_raise(rb_eTypeError, "module_function must be called for modules");
1135 }
1136
1137 secure_visibility(module);
1138 if (argc == 0) {
1139 SCOPE_SET(NOEX_MODFUNC);
1140 return module;
1141 }
1142
1143 set_method_visibility(module, argc, argv, NOEX_PRIVATE);
1144
1145 for (i = 0; i < argc; i++) {
1146 VALUE m = module;
1147
1148 id = rb_to_id(argv[i]);
1149 for (;;) {
1150 fbody = search_method(m, id, &m);
1151 if (fbody == 0) {
1152 fbody = search_method(rb_cObject, id, &m);
1153 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
1154 #if WITH_OBJC
1155 if (fbody == 0) {
1156 rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
1157 }
1158 if (nd_type(fbody->nd_body) != NODE_ZSUPER) {
1159 break; /* normal case: need not to follow 'super' link */
1160 }
1161 #else
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1162 if (fbody == 0 || fbody->nd_body == 0) {
1163 rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
1164 }
1165 if (nd_type(fbody->nd_body->nd_body) != NODE_ZSUPER) {
1166 break; /* normal case: need not to follow 'super' link */
1167 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
1168 #endif
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1169 m = RCLASS_SUPER(m);
1170 if (!m)
1171 break;
1172 }
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
1173 #if WITH_OBJC
1174 rb_add_method(rb_singleton_class(module), id, fbody->nd_body,
1175 NOEX_PUBLIC);
1176 #else
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1177 rb_add_method(rb_singleton_class(module), id, fbody->nd_body->nd_body,
1178 NOEX_PUBLIC);
4a2b903a » Laurent Sansonetti
2008-08-21 merging lrz_unstable branch
1179 #endif
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1180 }
1181 return module;
1182 }
1183
1184 /*
1185 * call-seq:
1186 * obj.respond_to?(symbol, include_private=false) => true or false
1187 *
1188 * Returns +true+> if _obj_ responds to the given
1189 * method. Private methods are included in the search only if the
1190 * optional second parameter evaluates to +true+.
1191 */
1192
1193 static NODE *basic_respond_to = 0;
1194
1195 int
1196 rb_obj_respond_to(VALUE obj, ID id, int priv)
1197 {
1198 VALUE klass = CLASS_OF(obj);
0e197981 » Laurent Sansonetti
2008-08-25 passing more tests
1199 #if WITH_OBJC
1200 IMP imp;
1201 static SEL sel_respondTo = 0;
1202 if (sel_respondTo == 0)
1203 sel_respondTo = sel_registerName("respond_to?:");
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1204
0e197981 » Laurent Sansonetti
2008-08-25 passing more tests
1205 if (rb_objc_method_node2(klass, sel_respondTo, NULL) == basic_respond_to) {
dc79458f » Laurent Sansonetti
2008-08-30 fixed respond_to? to respond to objc methods, also honor the priv arg…
1206 NODE *method;
1207
1208 method = rb_objc_method_node(klass, id, &imp, NULL);
1209 if (method != NULL && priv == 0 && (method->nd_noex & NOEX_PRIVATE))
1210 return false;
0e197981 » Laurent Sansonetti
2008-08-25 passing more tests
1211 return imp != NULL;
1212 }
1213 #else
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1214 if (rb_method_node(klass, idRespond_to) == basic_respond_to) {
1215 return rb_method_boundp(klass, id, !priv);
1216 }
0e197981 » Laurent Sansonetti
2008-08-25 passing more tests
1217 #endif
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1218 else {
1219 VALUE args[2];
1220 int n = 0;
1221 args[n++] = ID2SYM(id);
1222 if (priv)
1223 args[n++] = Qtrue;
1224 return RTEST(rb_funcall2(obj, idRespond_to, n, args));
1225 }
1226 }
1227
1228 int
1229 rb_respond_to(VALUE obj, ID id)
1230 {
1231 return rb_obj_respond_to(obj, id, Qfalse);
1232 }
1233
1234 /*
1235 * call-seq:
1236 * obj.respond_to?(symbol, include_private=false) => true or false
1237 *
1238 * Returns +true+> if _obj_ responds to the given
1239 * method. Private methods are included in the search only if the
1240 * optional second parameter evaluates to +true+.
1241 */
1242
1243 static VALUE
1244 obj_respond_to(int argc, VALUE *argv, VALUE obj)
1245 {
1246 VALUE mid, priv;
1247 ID id;
1248
1249 rb_scan_args(argc, argv, "11", &mid, &priv);
1250 id = rb_to_id(mid);
dc79458f » Laurent Sansonetti
2008-08-30 fixed respond_to? to respond to objc methods, also honor the priv arg…
1251 #if WITH_OBJC
1252 return rb_obj_respond_to(obj, id, RTEST(priv)) ? Qtrue : Qfalse;
1253 #else
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1254 if (rb_method_boundp(CLASS_OF(obj), id, !RTEST(priv))) {
1255 return Qtrue;
1256 }
dc79458f » Laurent Sansonetti
2008-08-30 fixed respond_to? to respond to objc methods, also honor the priv arg…
1257 #endif
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1258 return Qfalse;
1259 }
1260
1261 void
511dc44a » Laurent Sansonetti
2008-02-25 initial import
1262 Init_eval_method(void)
1263 {
9808f45b » Laurent Sansonetti
2008-08-26 do not call method_added if enable_method_added is false (for better …
1264 enable_method_added = Qtrue;
1265
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1266 rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1);
1267 basic_respond_to = rb_method_node(rb_cObject, idRespond_to);
1268 rb_register_mark_object((VALUE)basic_respond_to);
1269
511dc44a » Laurent Sansonetti
2008-02-25 initial import
1270 rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1);
1271 rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1);
1272 rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1273 rb_define_private_method(rb_cModule, "public", rb_mod_public, -1);
1274 rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1);
1275 rb_define_private_method(rb_cModule, "private", rb_mod_private, -1);
1276 rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1);
1277
1278 rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1);
1279 rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1);
1280 rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1);
1281 rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1);
1282 rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
1283 rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
1284
1285 rb_define_singleton_method(rb_vm_top_self(), "public", top_public, -1);
1286 rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1);
1287
1288 object_id = rb_intern("object_id");
1289 __send__ = rb_intern("__send__");
1290 eqq = rb_intern("===");
1291 each = rb_intern("each");
1292 aref = rb_intern("[]");
1293 aset = rb_intern("[]=");
1294 match = rb_intern("=~");
1295 missing = rb_intern("method_missing");
1296 added = rb_intern("method_added");
1297 singleton_added = rb_intern("singleton_method_added");
1298 removed = rb_intern("method_removed");
1299 singleton_removed = rb_intern("singleton_method_removed");
1300 undefined = rb_intern("method_undefined");
1301 singleton_undefined = rb_intern("singleton_method_undefined");
511dc44a » Laurent Sansonetti
2008-02-25 initial import
1302 }
26d0e1f6 » Laurent Sansonetti
2008-06-05 merge with ruby trunk r16762 + better/faster objc-like dispatcher
1303
Something went wrong with that request. Please try again.