Beispiel #1
0
static VALUE
rb_mod_modfunc(VALUE module, SEL sel, int argc, VALUE *argv)
{
    int i;

    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	// TODO change scope!
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	ID id = rb_to_id(argv[i]);
	IMP imp;
	rb_vm_method_node_t *node;
	SEL sel;

	if (!rb_vm_lookup_method2((Class)module, id, &sel, &imp, &node)) {
	    // Methods are checked in set_method_visibility().
	    rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	}

	rb_vm_define_method2(*(Class *)module, sel, node, false);
    }

    return module;
}
Beispiel #2
0
static VALUE
rb_mod_modfunc(VALUE module, SEL sel, int argc, VALUE *argv)
{
    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	rb_vm_set_current_scope(module, SCOPE_MODULE_FUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (int i = 0; i < argc; i++) {
	ID id = rb_to_id(argv[i]);
	IMP imp = NULL;
	rb_vm_method_node_t *node = NULL;
	SEL sel = 0;

	if (rb_vm_lookup_method2((Class)module, id, &sel, &imp, &node)
		|| (TYPE(module) == T_MODULE
		    && rb_vm_lookup_method2((Class)rb_cObject, id, &sel,
			&imp, &node))) {
	    rb_vm_define_method2(*(Class *)module, sel, node, -1, false);
	}
	else {
	    rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	}
    }

    return module;
}
Beispiel #3
0
static void
set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
{
    secure_visibility(self);
    for (int i = 0; i < argc; i++) {
	rb_export_method(self, rb_to_id(argv[i]), ex);
    }
}
Beispiel #4
0
static void
set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex)
{
    int i;
    secure_visibility(self);
    for (i = 0; i < argc; i++) {
	rb_export_method(self, rb_to_id(argv[i]), ex);
    }
    rb_clear_cache_by_class(self);
}
Beispiel #5
0
static VALUE
rb_mod_private(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PRIVATE);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
Beispiel #6
0
static VALUE
rb_mod_protected(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PROTECTED);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PROTECTED);
    }
    return module;
}
Beispiel #7
0
static VALUE
rb_mod_public(int argc, VALUE *argv, VALUE module)
{
    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_PUBLIC);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PUBLIC);
    }
    return module;
}
Beispiel #8
0
static VALUE
rb_mod_private(VALUE module, SEL sel, int argc, VALUE *argv)
{
    secure_visibility(module);
    if (argc == 0) {
	rb_vm_set_current_scope(module, SCOPE_PRIVATE);
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
Beispiel #9
0
static VALUE
rb_mod_private(VALUE module, SEL sel, int argc, VALUE *argv)
{
    secure_visibility(module);
    if (argc == 0) {
	// TODO change scope!
    }
    else {
	set_method_visibility(module, argc, argv, NOEX_PRIVATE);
    }
    return module;
}
static void
set_method_visibility(VALUE self, int argc, VALUE *argv, rb_method_flag_t ex)
{
    int i;
    secure_visibility(self);
    for (i = 0; i < argc; i++) {
	VALUE v = argv[i];
	ID id = rb_check_id(&v);
	if (!id) {
	    rb_print_undef_str(self, v);
	}
	rb_export_method(self, id, ex);
    }
    rb_clear_cache_by_class(self);
}
Beispiel #11
0
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    NODE *fbody;

    if (TYPE(module) != T_MODULE) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    fbody = search_method(m, id, &m);
	    if (fbody == 0) {
		fbody = search_method(rb_cObject, id, &m);
	    }
	    if (fbody == 0 || fbody->nd_body == 0) {
		rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
	    }
	    if (nd_type(fbody->nd_body->nd_body) != NODE_ZSUPER) {
		break;		/* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_add_method(rb_singleton_class(module), id, fbody->nd_body->nd_body,
		      NOEX_PUBLIC);
    }
    return module;
}
static VALUE
rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
{
    int i;
    ID id;
    const rb_method_entry_t *me;

    if (!RB_TYPE_P(module, T_MODULE)) {
	rb_raise(rb_eTypeError, "module_function must be called for modules");
    }

    secure_visibility(module);
    if (argc == 0) {
	SCOPE_SET(NOEX_MODFUNC);
	return module;
    }

    set_method_visibility(module, argc, argv, NOEX_PRIVATE);

    for (i = 0; i < argc; i++) {
	VALUE m = module;

	id = rb_to_id(argv[i]);
	for (;;) {
	    me = search_method(m, id);
	    if (me == 0) {
		me = search_method(rb_cObject, id);
	    }
	    if (UNDEFINED_METHOD_ENTRY_P(me)) {
		rb_print_undef(module, id, 0);
	    }
	    if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
		break; /* normal case: need not to follow 'super' link */
	    }
	    m = RCLASS_SUPER(m);
	    if (!m)
		break;
	}
	rb_method_entry_set(rb_singleton_class(module), id, me, NOEX_PUBLIC);
    }
    return module;
}