19 #define PROC_NEW_REQUIRES_BLOCK 0 21 #if !defined(__GNUC__) || __GNUC__ < 5 || defined(__MINGW32__) 22 # define NO_CLOBBERED(v) (*(volatile VALUE *)&(v)) 24 # define NO_CLOBBERED(v) (v) 45 #define attached id__attached__ 49 #define IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall) 128 int8_t safe_level, int8_t is_from_method, int8_t is_lambda);
389 rb_scan_args(argc, argv,
"12", &args[0], &args[2], &args[3]);
405 for (i=0; i<iseq->body->local_table_size; i++) {
406 if (iseq->body->local_table[i] == lid) {
619 proc = &sproc->
basic;
670 arity.argc.min = min_argc;
671 arity.argc.max = max_argc;
700 #if !PROC_NEW_REQUIRES_BLOCK 708 goto return_existing_proc;
728 return_existing_proc:
864 #if SIZEOF_LONG > SIZEOF_INT 868 if (argc > INT_MAX || argc < 0) {
870 (
unsigned long)argc);
875 #define check_argc(argc) (argc) 1062 VALUE procval = block_handler;
1097 block = &proc->
block;
1098 if (is_proc) *is_proc = !proc->
is_lambda;
1110 if (is_proc) *is_proc = 0;
1130 if (!iseq)
return Qnil;
1156 int n = (arity < 0) ? ~arity : arity;
1206 enum {SYM_PROC_CACHE_SIZE = 67};
1212 if (!sym_proc_cache) {
1219 index = (
id % SYM_PROC_CACHE_SIZE) << 1;
1222 if (aryp[index] == sym) {
1223 return aryp[index + 1];
1228 aryp[index + 1] = proc;
1274 const char *is_lambda;
1276 block = &proc->
block;
1277 is_lambda = proc->
is_lambda ?
" (lambda)" :
"";
1326 struct METHOD *data = ptr;
1335 return sizeof(
struct METHOD);
1365 if (obj ==
Qundef)
return 0;
1408 if (!error)
return Qnil;
1414 if (!error)
return Qnil;
1464 return mnew_from_me(me, klass, obj,
id, mclass, scope);
1471 return defined_class ? defined_class : me->
owner;
1512 VALUE klass1, klass2;
1572 struct METHOD *orig, *data;
1576 &method_data_type, data);
1651 #define MSG(s) rb_fstring_cstr("undefined method `%1$s' for"s" `%2$s'") 1691 return mnew(klass, obj,
id, mclass, scope);
1895 int is_method =
FALSE;
1905 #if PROC_NEW_REQUIRES_BLOCK 1936 "wrong argument type %s (expected Proc/Method)",
1948 "can't bind singleton method to a different class");
1952 "bind argument must be a subclass of % "PRIsVALUE,
2028 rb_warning(
"main.define_method in the wrapped load is effective only in wrapper module");
2057 struct METHOD *orig, *data;
2097 int argc,
const VALUE *argv,
VALUE passed_procval)
2106 int argc,
const VALUE *argv,
VALUE passed_procval,
2128 const struct METHOD *data;
2138 if (safe < safe_level_to_run) {
2240 struct METHOD *data, *bound;
2251 "singleton method called for a different object");
2290 if (!def)
return *max = 0;
2291 switch (def->
type) {
2321 case OPTIMIZED_METHOD_TYPE_SEND:
2324 case OPTIMIZED_METHOD_TYPE_CALL:
2336 rb_bug(
"rb_method_entry_min_max_arity: invalid method entry type (%d)", def->
type);
2344 return min == max ? min : -min-1;
2413 const struct METHOD *data;
2436 const struct METHOD *data;
2439 return data->
me->
def;
2445 switch (def->
type) {
2478 switch (def->
type) {
2503 if (!me)
return Qnil;
2579 const char *sharp =
"#";
2581 VALUE defined_class;
2589 mklass = data->
klass;
2608 else if (data->
recv == v) {
2622 if (defined_class != mklass) {
2708 const struct METHOD *data;
2714 if (!super_class)
return Qnil;
2716 if (!me)
return Qnil;
2764 new_ep = &new_body[env->
ep - env->
env];
2797 block = &proc->
block;
2808 block = &proc->
block;
2875 VALUE proc, passed, arity;
2884 if (!
NIL_P(passed_proc)) {
2885 rb_warn(
"given block not used");
#define UNDEFINED_REFINED_METHOD_P(def)
static VALUE method_name(VALUE obj)
static VALUE bind_local_variables(VALUE bindval)
static VALUE bind_local_variable_set(VALUE bindval, VALUE sym, VALUE val)
const rb_iseq_t * rb_method_iseq(VALUE method)
static int VM_ENV_ESCAPED_P(const VALUE *ep)
static int method_min_max_arity(VALUE, int *max)
static VALUE rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
static const rb_method_entry_t * original_method_entry(VALUE mod, ID id)
#define UNDEFINED_METHOD_ENTRY_P(me)
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
rb_iseq_t * rb_iseq_new(NODE *node, VALUE name, VALUE path, VALUE absolute_path, const rb_iseq_t *parent, enum iseq_type type)
static VALUE rb_method_curry(int argc, const VALUE *argv, VALUE self)
static size_t binding_memsize(const void *ptr)
int rb_block_min_max_arity(int *max)
VALUE rb_proc_alloc(VALUE klass)
VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me)
static VALUE method_arity_m(VALUE method)
static void vm_passed_block_handler_set(rb_thread_t *th, VALUE block_handler)
VALUE rb_obj_public_method(VALUE obj, VALUE vid)
void rb_bug(const char *fmt,...)
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex)
static VALUE proc_to_proc(VALUE self)
#define RUBY_TYPED_FREE_IMMEDIATELY
VALUE(* rb_block_call_func_t)(ANYARGS)
static VALUE proc_hash(VALUE self)
static const rb_data_type_t proc_data_type
void rb_print_undef(VALUE klass, ID id, rb_method_visibility_t visi)
VALUE rb_ary_freeze(VALUE ary)
static VALUE bind_eval(int argc, VALUE *argv, VALUE bindval)
static VALUE umethod_bind(VALUE method, VALUE recv)
static VALUE mnew_from_me(const rb_method_entry_t *me, VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
static VALUE method_original_name(VALUE obj)
const rb_method_entry_t * rb_method_entry_clone(const rb_method_entry_t *me)
static int max(int a, int b)
static unsigned int hash(str, len) register const char *str
void rb_undef_alloc_func(VALUE)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
#define GetProcPtr(obj, ptr)
#define rb_name_err_raise_str(mesg, recv, name)
int rb_mod_method_arity(VALUE mod, ID id)
static const rb_iseq_t * rb_iseq_check(const rb_iseq_t *iseq)
static int rb_method_entry_min_max_arity(const rb_method_entry_t *me, int *max)
st_index_t rb_hash_end(st_index_t)
static VALUE proc_curry(int argc, const VALUE *argv, VALUE self)
static void proc_mark(void *ptr)
#define TypedData_Get_Struct(obj, type, data_type, sval)
static const VALUE * get_local_variable_ptr(const rb_env_t **envp, ID lid)
static const rb_iseq_t * vm_proc_iseq(VALUE procval)
struct rb_iseq_constant_body::@196::@197 flags
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static const rb_method_definition_t * method_def(VALUE method)
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
static VALUE localjump_reason(VALUE exc)
#define TH_JUMP_TAG(th, st)
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, int argc, const VALUE *argv, VALUE passed_block_handler)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define VM_BLOCK_HANDLER_NONE
VALUE rb_str_buf_new2(const char *)
SSL_METHOD *(* func)(void)
static int rb_proc_min_max_arity(VALUE self, int *max)
rb_method_entry_t * rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def)
static VALUE VM_BH_TO_SYMBOL(VALUE block_handler)
VALUE rb_ary_tmp_new(long capa)
static VALUE method_to_proc(VALUE method)
struct rb_iseq_constant_body * body
static VALUE method_clone(VALUE self)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_proc_lambda_p(VALUE procval)
#define RBASIC_SET_CLASS(obj, cls)
VALUE rb_iv_get(VALUE, const char *)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
#define RUBY_MARK_LEAVE(msg)
struct rb_iseq_constant_body::@196 param
parameter information
VALUE rb_obj_is_kind_of(VALUE, VALUE)
VALUE rb_obj_method_location(VALUE obj, ID id)
static VALUE unnamed_parameters(int arity)
void rb_gc_mark(VALUE ptr)
void rb_method_name_error(VALUE klass, VALUE str)
static VALUE proc_clone(VALUE self)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
static VALUE method_super_method(VALUE method)
VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self)
static const rb_cref_t * method_cref(VALUE method)
VALUE rb_method_call(int argc, const VALUE *argv, VALUE method)
static VALUE method_inspect(VALUE method)
static VALUE rb_proc_s_new(int argc, VALUE *argv, VALUE klass)
VALUE env[VM_ENV_DATA_SIZE+1]
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_str_buf_append(VALUE, VALUE)
static VALUE proc_dup(VALUE self)
static size_t bm_memsize(const void *ptr)
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
#define rb_name_err_raise(mesg, recv, name)
#define VM_ENV_DATA_INDEX_ME_CREF
const char * rb_obj_classname(VALUE)
static int rb_vm_block_min_max_arity(const struct rb_block *block, int *max)
VALUE rb_proc_new(VALUE(*func)(ANYARGS), VALUE val)
static void block_setup(struct rb_block *block, VALUE block_handler)
static VALUE method_hash(VALUE method)
static VALUE method_eq(VALUE method, VALUE other)
static VALUE call_method_data_safe(rb_thread_t *th, const struct METHOD *data, int argc, const VALUE *argv, VALUE passed_procval, int safe)
static const struct rb_captured_block * VM_BH_TO_CAPT_BLOCK(VALUE block_handler)
static int method_arity(VALUE)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
#define RB_TYPE_P(obj, type)
static VALUE mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE obj, ID id, VALUE mclass, int scope, int error)
VALUE rb_proc_create(VALUE klass, const struct rb_block *block, int8_t safe_level, int8_t is_from_method, int8_t is_lambda)
rb_cref_t * rb_vm_cref_new_toplevel(void)
#define RUBY_TYPED_WB_PROTECTED
unsigned short first_lineno
VALUE rb_obj_is_method(VALUE m)
#define rb_intern_str(string)
VALUE rb_class_name(VALUE)
static VALUE rb_mod_instance_method(VALUE mod, VALUE vid)
#define RUBY_SAFE_LEVEL_MAX
static int rb_obj_is_iseq(VALUE iseq)
int rb_block_given_p(void)
const rb_env_t * rb_vm_env_prev_env(const rb_env_t *env)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda)
#define GetBindingPtr(obj, ptr)
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_str_buf_cat2(VALUE, const char *)
RUBY_EXTERN VALUE rb_mKernel
VALUE rb_iseq_first_lineno(const rb_iseq_t *iseq)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE proc_arity(VALUE self)
struct vm_ifunc_argc argc
struct rb_method_definition_struct *const def
static VALUE sym_proc_new(VALUE klass, VALUE sym)
void rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static VALUE rb_proc_parameters(VALUE self)
static const struct rb_captured_block * VM_BH_TO_ISEQ_BLOCK(VALUE block_handler)
#define RUBY_MARK_ENTER(msg)
static VALUE call_method_data(rb_thread_t *th, const struct METHOD *data, int argc, const VALUE *argv, VALUE passed_procval)
void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE cls, const char *mesg)
const rb_data_type_t ruby_binding_data_type
#define CLONESETUP(clone, obj)
VALUE rb_binding_new(void)
static void vm_block_type_set(const struct rb_block *block, enum rb_block_type type)
static unsigned long VM_ENV_FLAGS(const VALUE *ep, long flag)
RUBY_EXTERN VALUE rb_cModule
void rb_gc_register_mark_object(VALUE obj)
#define MEMCPY(p1, p2, type, n)
static const rb_env_t * vm_env_new(VALUE *env_ep, VALUE *env_body, unsigned int env_size, const rb_iseq_t *iseq)
const struct rb_iseq_constant_body::@196::rb_iseq_param_keyword * keyword
static VALUE rb_method_parameters(VALUE method)
VALUE rb_block_proc(void)
static VALUE rb_f_binding(VALUE self)
static const rb_env_t * VM_ENV_ENVVAL_PTR(const VALUE *ep)
#define VM_ENV_DATA_INDEX_SPECVAL
const rb_method_entry_t *const me
static VALUE rb_mod_define_method(int argc, VALUE *argv, VALUE mod)
static VALUE proc_to_block_handler(VALUE procval)
VALUE rb_block_lambda(void)
static VALUE proc_to_s_(VALUE self, const rb_proc_t *proc)
static VALUE vm_block_self(const struct rb_block *block)
VALUE rb_mod_method_location(VALUE mod, ID id)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
static VALUE bmcall(VALUE, VALUE, int, VALUE *, VALUE)
#define RARRAY_CONST_PTR(a)
static const struct rb_block * vm_proc_block(VALUE procval)
union rb_method_definition_struct::@144 body
VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val)
VALUE rb_sprintf(const char *format,...)
static void block_mark(const struct rb_block *block)
static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc)
VALUE rb_include_class_new(VALUE module, VALUE super)
const rb_method_entry_t * rb_method_entry(VALUE klass, ID id)
static const rb_iseq_t * method_def_iseq(const rb_method_definition_t *def)
static enum rb_block_handler_type vm_block_handler_type(VALUE block_handler)
static void binding_free(void *ptr)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE rb_mod_public_instance_method(VALUE mod, VALUE vid)
VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp)
const VALUE * rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars)
static const VALUE * vm_block_ep(const struct rb_block *block)
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
static VALUE mnew_missing(VALUE klass, VALUE obj, ID id, VALUE mclass)
#define METHOD_ENTRY_VISI(me)
int rb_obj_method_arity(VALUE obj, ID id)
static VALUE proc_binding(VALUE self)
const rb_cref_t * rb_vm_cref_in_context(VALUE self, VALUE cbase)
VALUE rb_vm_top_self(void)
static VALUE cfunc_proc_new(VALUE klass, VALUE ifunc, int8_t is_lambda)
static VALUE binding_dup(VALUE self)
const VALUE defined_class
rb_method_visibility_t method_visi
static enum rb_block_type vm_block_type(const struct rb_block *block)
const struct rb_method_entry_struct *const original_me
#define VM_ENV_DATA_INDEX_FLAGS
static struct vm_ifunc * rb_vm_ifunc_proc_new(VALUE(*func)(ANYARGS), const void *data)
static VALUE method_owner(VALUE obj)
const struct vm_ifunc * ifunc
#define IS_METHOD_PROC_IFUNC(ifunc)
static VALUE method_receiver(VALUE obj)
const rb_method_entry_t * rb_method_entry_at(VALUE obj, ID id)
static VALUE make_curry_proc(VALUE proc, VALUE passed, VALUE arity)
struct rb_captured_block captured
static VALUE mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
#define VM_ENV_DATA_INDEX_ENV
void rb_set_safe_level_force(int)
const rb_callable_method_entry_t * rb_callable_method_entry_without_refinements(VALUE klass, ID id)
static VALUE mlambda(VALUE method)
VALUE rb_mRubyVMFrozenCore
static VALUE VM_BH_TO_PROC(VALUE block_handler)
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
static const rb_env_t * env_clone(const rb_env_t *env, const rb_cref_t *cref)
VALUE rb_proc_location(VALUE self)
#define UNLIMITED_ARGUMENTS
const VALUE * rb_vm_ep_local_ep(const VALUE *ep)
st_index_t rb_hash_proc(st_index_t hash, VALUE prc)
const rb_callable_method_entry_t * rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class)
static void bm_mark(void *ptr)
static VALUE bind_local_variable_defined_p(VALUE bindval, VALUE sym)
#define RARRAY_AREF(a, i)
static int respond_to_missing_p(VALUE klass, VALUE obj, VALUE sym, int scope)
VALUE rb_method_location(VALUE method)
VALUE rb_ary_plus(VALUE x, VALUE y)
#define RBASIC_CLASS(obj)
#define RUBY_FREE_LEAVE(msg)
const rb_iseq_t * rb_proc_get_iseq(VALUE self, int *is_proc)
#define RUBY_FREE_ENTER(msg)
static VALUE VM_ENV_PROCVAL(const VALUE *ep)
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
VALUE rb_str_catf(VALUE str, const char *format,...)
VALUE rb_proc_call(VALUE self, VALUE args)
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
const struct rb_block block
VALUE rb_obj_singleton_method(VALUE obj, VALUE vid)
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
VALUE rb_proc_call_with_block(VALUE self, int argc, const VALUE *argv, VALUE passed_procval)
st_index_t rb_hash_uint(st_index_t, st_index_t)
VALUE rb_sym_to_proc(VALUE sym)
int rb_is_local_name(VALUE name)
int rb_method_basic_definition_p(VALUE, ID)
#define RUBY_MARK_UNLESS_NULL(ptr)
VALUE rb_method_call_with_block(int argc, const VALUE *argv, VALUE method, VALUE passed_procval)
struct vm_ifunc * rb_vm_ifunc_new(VALUE(*func)(ANYARGS), const void *data, int min_argc, int max_argc)
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
#define VM_UNREACHABLE(func)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_ary_dup(VALUE ary)
int rb_is_local_id(ID id)
VALUE rb_obj_method(VALUE obj, VALUE vid)
static VALUE bind_receiver(VALUE bindval)
static VALUE binding_clone(VALUE self)
static VALUE proc_new(VALUE klass, int8_t is_lambda)
static const char proc_without_block[]
static VALUE proc_to_s(VALUE self)
static const rb_data_type_t method_data_type
static ID check_local_id(VALUE bindval, volatile VALUE *pname)
int rb_proc_arity(VALUE self)
static VALUE bind_local_variable_get(VALUE bindval, VALUE sym)
static VALUE obj_method(VALUE obj, VALUE vid, int scope)
void rb_warning(const char *fmt,...)
static VALUE localjump_xvalue(VALUE exc)
static const rb_scope_visibility_t * CREF_SCOPE_VISI(const rb_cref_t *cref)
#define CONST_ID(var, str)
static const rb_callable_method_entry_t * method_callable_method_entry(const struct METHOD *data)
VALUE rb_vm_env_local_variables(const rb_env_t *env)
#define RUBY_TYPED_DEFAULT_FREE
enum rb_method_definition_struct::@144::method_optimized_type optimize_type
const rb_iseq_t *const iseqptr
static VALUE method_def_location(const rb_method_definition_t *def)
static VALUE top_define_method(int argc, VALUE *argv, VALUE obj)
static void binding_mark(void *ptr)
static VALUE VM_ENV_ENVVAL(const VALUE *ep)
VALUE rb_method_entry_location(const rb_method_entry_t *me)
const rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id)
VALUE rb_class_search_ancestor(VALUE klass, VALUE super)
VALUE rb_class_inherited_p(VALUE mod, VALUE arg)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
static size_t proc_memsize(const void *ptr)
static VALUE method_entry_defined_class(const rb_method_entry_t *me)
static int rb_iseq_min_max_arity(const rb_iseq_t *iseq, int *max)
VALUE rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
void rb_warn(const char *fmt,...)
#define Check_TypedStruct(v, t)
static VALUE iseq_location(const rb_iseq_t *iseq)
VALUE rb_binding_alloc(VALUE klass)
union rb_captured_block::@202 code
static VALUE mproc(VALUE method)
st_index_t rb_hash_start(st_index_t)
#define RB_OBJ_WRITE(a, slot, b)
VALUE rb_obj_is_proc(VALUE proc)
int rb_method_entry_arity(const rb_method_entry_t *me)
rb_iseq_location_t location
static VALUE method_unbind(VALUE obj)
static const struct rb_captured_block * VM_BH_TO_IFUNC_BLOCK(VALUE block_handler)
#define IFUNC_NEW(a, b, c)
VALUE rb_obj_class(VALUE)