Ruby: proc.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Functions | Variables
proc.c File Reference
`#include "eval_intern.h"`
`#include "gc.h"`
`#include "internal.h"`
`#include "internal/class.h"`
`#include "internal/error.h"`
`#include "internal/eval.h"`
`#include "internal/object.h"`
`#include "internal/proc.h"`
`#include "internal/symbol.h"`
`#include "iseq.h"`
`#include "vm_core.h"`

Go to the source code of this file.

## Data Structures
struct | METHOD
struct | cfunc_proc_t

## Macros
#define | NO_CLOBBERED(v) (v)
#define | UPDATE_TYPED_REFERENCE(_type, _ref) *(_type*)&_ref = (_type)rb_gc_location((VALUE)_ref)
#define | UPDATE_REFERENCE(_ref) UPDATE_TYPED_REFERENCE(VALUE, _ref)
#define | attached id__attached__
#define | IS_METHOD_PROC_IFUNC(ifunc) ((ifunc)->func == bmcall)
#define | check_argc(argc) (argc)
#define | MSG(s) rb_fstring_lit("undefined method `%1$s' for"s" `%2$s'")

## Functions
const rb_cref_t * | rb_vm_cref_in_context (VALUE self, VALUE cbase)
VALUE | rb_proc_alloc (VALUE klass)
VALUE | rb_obj_is_proc (VALUE proc)
VALUE | rb_proc_lambda_p (VALUE procval)
VALUE | rb_binding_alloc (VALUE klass)
VALUE | rb_binding_new (void)
struct vm_ifunc * | rb_vm_ifunc_new (rb_block_call_func_t func, const void *data, int min_argc, int max_argc)
VALUE | rb_func_proc_new (rb_block_call_func_t func, VALUE val)
VALUE | rb_func_lambda_new (rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
VALUE | rb_block_proc (void)
VALUE | rb_block_lambda (void)
VALUE | rb_proc_call_kw (VALUE self, VALUE args, int kw_splat)
VALUE | rb_proc_call (VALUE self, VALUE args)
VALUE | rb_proc_call_with_block_kw (VALUE self, int argc, const VALUE *argv, VALUE passed_procval, int kw_splat)
VALUE | rb_proc_call_with_block (VALUE self, int argc, const VALUE *argv, VALUE passed_procval)
int | rb_proc_arity (VALUE self)
int | rb_block_pair_yield_optimizable (void)
int | rb_block_arity (void)
int | rb_block_min_max_arity (int *max)
const rb_iseq_t * | rb_proc_get_iseq (VALUE self, int *is_proc)
VALUE | rb_iseq_location (const rb_iseq_t *iseq)
VALUE | rb_proc_location (VALUE self)
VALUE | rb_unnamed_parameters (int arity)
st_index_t | rb_hash_proc (st_index_t hash, VALUE prc)
VALUE | rb_sym_to_proc (VALUE sym)
VALUE | rb_block_to_s (VALUE self, const struct rb_block *block, const char *additional_info)
VALUE | rb_obj_is_method (VALUE m)
void | rb_method_name_error (VALUE klass, VALUE str)
VALUE | rb_obj_method (VALUE obj, VALUE vid)
VALUE | rb_obj_public_method (VALUE obj, VALUE vid)
VALUE | rb_obj_singleton_method (VALUE obj, VALUE vid)
VALUE | rb_method_call_kw (int argc, const VALUE *argv, VALUE method, int kw_splat)
VALUE | rb_method_call (int argc, const VALUE *argv, VALUE method)
VALUE | rb_method_call_with_block_kw (int argc, const VALUE *argv, VALUE method, VALUE passed_procval, int kw_splat)
VALUE | rb_method_call_with_block (int argc, const VALUE *argv, VALUE method, VALUE passed_procval)
int | rb_method_entry_arity (const rb_method_entry_t *me)
int | rb_mod_method_arity (VALUE mod, ID id)
int | rb_obj_method_arity (VALUE obj, ID id)
VALUE | rb_callable_receiver (VALUE callable)
const rb_method_definition_t * | rb_method_def (VALUE method)
const rb_iseq_t * | rb_method_iseq (VALUE method)
VALUE | rb_method_entry_location (const rb_method_entry_t *me)
VALUE | rb_method_location (VALUE method)
VALUE | rb_proc_new (rb_block_call_func_t func, VALUE val)
VALUE | rb_find_defined_class_by_owner (VALUE current_class, VALUE target_owner)
rb_cref_t * | rb_vm_cref_new_toplevel (void)
void | Init_Proc (void)
void | Init_Binding (void)

## Variables
VALUE | rb_cUnboundMethod
VALUE | rb_cMethod
VALUE | rb_cBinding
VALUE | rb_cProc
const rb_data_type_t | ruby_binding_data_type

## Macro Definition Documentation

## ◆ attached

#define attached id__attached__

Definition at line 53 of file proc.c.

## ◆ check_argc

#define check_argc | ( |  | argc | ) | (argc)

Definition at line 962 of file proc.c.

## ◆ IS_METHOD_PROC_IFUNC

#define IS_METHOD_PROC_IFUNC | ( |  | ifunc | ) | ((ifunc)->func == bmcall)

Definition at line 57 of file proc.c.

## ◆ MSG

#define MSG | ( |  | s | ) | rb_fstring_lit("undefined method `%1$s' for"s" `%2$s'")

## ◆ NO_CLOBBERED

#define NO_CLOBBERED | ( |  | v | ) | (v)

Definition at line 27 of file proc.c.

## ◆ UPDATE_REFERENCE

#define UPDATE_REFERENCE | ( |  | _ref | ) | UPDATE_TYPED_REFERENCE(VALUE, _ref)

Definition at line 31 of file proc.c.

## ◆ UPDATE_TYPED_REFERENCE

#define UPDATE_TYPED_REFERENCE | ( |  | _type,
|  |  | _ref
| ) |  | *(_type*)&_ref = (_type)rb_gc_location((VALUE)_ref)

Definition at line 30 of file proc.c.

## Function Documentation

## ◆ Init_Binding()

void Init_Binding | ( | void |  | ) |

Definition at line 4228 of file proc.c.

References CLASS_OF, rb_cBinding, rb_cObject, rb_define_class(), rb_define_global_function, rb_define_method, rb_undef_alloc_func(), and rb_undef_method().

## ◆ Init_Proc()

void Init_Proc | ( | void |  | ) |

Definition at line 4075 of file proc.c.

References CLASS_OF, METHOD_VISI_PUBLIC, OPTIMIZED_METHOD_TYPE_CALL, rb_add_method(), rb_cMethod, rb_cModule, rb_cObject, rb_cProc, rb_cUnboundMethod, rb_define_alias(), rb_define_class(), rb_define_global_function, rb_define_method, rb_define_private_method, rb_define_singleton_method, rb_eException, rb_eLocalJumpError, rb_eStandardError, rb_eSysStackError, rb_intern(), rb_method_location(), rb_mKernel, rb_obj_method(), rb_obj_public_method(), rb_obj_singleton_method(), rb_proc_dup(), rb_proc_lambda_p(), rb_proc_location(), rb_singleton_class(), rb_undef_alloc_func(), rb_undef_method(), rb_vm_register_special_exception, rb_vm_top_self(), ruby_error_sysstack, and VM_METHOD_TYPE_OPTIMIZED.

## ◆ rb_binding_alloc()

VALUE rb_binding_alloc | ( | VALUE | klass | ) |

Definition at line 331 of file proc.c.

References ruby_binding_data_type, and TypedData_Make_Struct.

Referenced by rb_vm_make_binding().

## ◆ rb_binding_new()

VALUE rb_binding_new | ( | void |  | ) |

Definition at line 364 of file proc.c.

References rb_execution_context_struct::cfp, and rb_vm_make_binding().

Referenced by Init_VM().

## ◆ rb_block_arity()

int rb_block_arity | ( | void |  | ) |

Definition at line 1193 of file proc.c.

References block_handler_type_proc, block_handler_type_symbol, rb_execution_context_struct::cfp, GetProcPtr, max, rb_block::proc, rb_eArgError, rb_raise(), rb_vm_frame_block_handler(), UNLIMITED_ARGUMENTS, and VM_BLOCK_HANDLER_NONE.

## ◆ rb_block_lambda()

VALUE rb_block_lambda | ( | void |  | ) |

Definition at line 845 of file proc.c.

References FALSE, rb_cProc, and TRUE.

## ◆ rb_block_min_max_arity()

int rb_block_min_max_arity | ( | int * | max | ) |

Definition at line 1226 of file proc.c.

References rb_execution_context_struct::cfp, max, rb_eArgError, rb_raise(), rb_vm_frame_block_handler(), and VM_BLOCK_HANDLER_NONE.

## ◆ rb_block_pair_yield_optimizable()

int rb_block_pair_yield_optimizable | ( | void |  | ) |

Definition at line 1158 of file proc.c.

References block_handler_type_proc, block_handler_type_symbol, rb_execution_context_struct::cfp, GetProcPtr, max, rb_block::proc, rb_eArgError, rb_raise(), rb_vm_frame_block_handler(), and VM_BLOCK_HANDLER_NONE.

## ◆ rb_block_proc()

VALUE rb_block_proc | ( | void |  | ) |

Definition at line 826 of file proc.c.

References FALSE, and rb_cProc.

Referenced by rb_f_trace_var(), rb_method_call(), and rb_method_call_kw().

## ◆ rb_block_to_s()

VALUE rb_block_to_s | ( | VALUE | self,
|  | const struct rb_block * | block,
|  | const char * | additional_info
| ) |  |

Definition at line 1491 of file proc.c.

References rb_block::as, block_type_ifunc, block_type_iseq, block_type_proc, block_type_symbol, rb_iseq_struct::body, rb_block::captured, rb_captured_block::code, rb_iseq_location_struct::first_lineno, FIX2INT, rb_captured_block::ifunc, rb_captured_block::iseq, rb_iseq_constant_body::location, PRIsVALUE, rb_block::proc, rb_iseq_path(), rb_obj_class(), rb_sprintf(), rb_str_cat_cstr, rb_str_catf(), str, and rb_block::symbol.

## ◆ rb_callable_receiver()

VALUE rb_callable_receiver | ( | VALUE | callable | ) |

Definition at line 2787 of file proc.c.

References Qundef, rb_funcall(), rb_intern(), rb_obj_is_method(), and rb_obj_is_proc().

## ◆ rb_find_defined_class_by_owner()

VALUE rb_find_defined_class_by_owner | ( | VALUE | current_class,
|  | VALUE | target_owner
| ) |  |

Definition at line 3011 of file vm_insnhelper.c.

References FL_TEST, RBASIC_CLASS, RCLASS_SUPER, RICLASS_IS_ORIGIN, RTEST, T_CLASS, and T_ICLASS.

## ◆ rb_func_lambda_new()

VALUE rb_func_lambda_new | ( | rb_block_call_func_t | func,
|  | VALUE | val,
|  | int | min_argc,
|  | int | max_argc
| ) |  |

Definition at line 742 of file proc.c.

References vm_ifunc::func, rb_cProc, and rb_vm_ifunc_new().

## ◆ rb_func_proc_new()

VALUE rb_func_proc_new | ( | rb_block_call_func_t | func,
|  | VALUE | val
| ) |  |

Definition at line 735 of file proc.c.

References vm_ifunc::func, and rb_cProc.

## ◆ rb_hash_proc()

st_index_t rb_hash_proc | ( | st_index_t | hash,
|  | VALUE | prc
| ) |  |

Definition at line 1433 of file proc.c.

References GetProcPtr, rb_block::proc, and rb_hash_uint.

## ◆ rb_iseq_location()

VALUE rb_iseq_location | ( | const rb_iseq_t * | iseq | ) |

Definition at line 1373 of file proc.c.

## ◆ rb_method_call()

VALUE rb_method_call | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | method
| ) |  |

Definition at line 2398 of file proc.c.

References argc, argv, Qnil, rb_block_given_p(), rb_block_proc(), and rb_method_call_with_block().

## ◆ rb_method_call_kw()

VALUE rb_method_call_kw | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | method,
|  | int | kw_splat
| ) |  |

Definition at line 2391 of file proc.c.

References argc, argv, Qnil, rb_block_given_p(), rb_block_proc(), and rb_method_call_with_block_kw().

## ◆ rb_method_call_with_block()

VALUE rb_method_call_with_block | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | method,
|  | VALUE | passed_procval
| ) |  |

Definition at line 2434 of file proc.c.

References argc, argv, rb_method_call_with_block_kw(), and RB_NO_KEYWORDS.

Referenced by rb_method_call().

## ◆ rb_method_call_with_block_kw()

VALUE rb_method_call_with_block_kw | ( | int | argc,
|  | const VALUE * | argv,
|  | VALUE | method,
|  | VALUE | passed_procval,
|  | int | kw_splat
| ) |  |

Definition at line 2421 of file proc.c.

References argc, argv, Qundef, rb_eTypeError, rb_raise(), METHOD::recv, and TypedData_Get_Struct.

Referenced by rb_method_call_kw(), and rb_method_call_with_block().

## ◆ rb_method_def()

const rb_method_definition_t * rb_method_def | ( | VALUE | method | ) |

Definition at line 2802 of file proc.c.

References rb_method_entry_struct::def, METHOD::me, and TypedData_Get_Struct.

Referenced by rb_method_iseq(), and rb_method_location().

## ◆ rb_method_entry_arity()

int rb_method_entry_arity | ( | const rb_method_entry_t * | me | ) |

Definition at line 2684 of file proc.c.

References max, and METHOD::me.

Referenced by rb_mod_method_arity(), and rb_tracearg_parameters().

## ◆ rb_method_entry_location()

VALUE rb_method_entry_location | ( | const rb_method_entry_t * | me | ) |

Definition at line 2869 of file proc.c.

References rb_method_entry_struct::def, METHOD::me, and Qnil.

## ◆ rb_method_iseq()

const rb_iseq_t * rb_method_iseq | ( | VALUE | method | ) |

Definition at line 2835 of file proc.c.

References rb_method_def().

Referenced by rb_proc_get_iseq().

## ◆ rb_method_location()

VALUE rb_method_location | ( | VALUE | method | ) |

Definition at line 2884 of file proc.c.

References rb_method_def().

Referenced by Init_Proc().

## ◆ rb_method_name_error()

void rb_method_name_error | ( | VALUE | klass,
|  | VALUE | str
| ) |  |

Definition at line 1909 of file proc.c.

References attached, BUILTIN_TYPE, FL_SINGLETON, FL_TEST, METHOD::klass, MSG, Qundef, rb_ivar_get(), str, T_CLASS, and T_MODULE.

Referenced by rb_undef().

## ◆ rb_mod_method_arity()

int rb_mod_method_arity | ( | VALUE | mod,
|  | ID | id
| ) |  |

Definition at line 2773 of file proc.c.

References METHOD::me, mod, and rb_method_entry_arity().

Referenced by rb_obj_method_arity().

## ◆ rb_obj_is_method()

VALUE rb_obj_is_method | ( | VALUE | m | ) |

Definition at line 1590 of file proc.c.

References Qfalse, Qtrue, and rb_typeddata_is_kind_of().

Referenced by rb_callable_receiver(), and rb_econv_prepare_options().

## ◆ rb_obj_is_proc()

VALUE rb_obj_is_proc | ( | VALUE | proc | ) |

Definition at line 152 of file proc.c.

References Qfalse, Qtrue, and rb_typeddata_is_kind_of().

Referenced by rb_callable_receiver(), rb_econv_prepare_options(), rb_hash_set_default_proc(), and rb_raw_obj_info().

## ◆ rb_obj_method()

VALUE rb_obj_method | ( | VALUE | obj,
|  | VALUE | vid
| ) |  |

Definition at line 1992 of file proc.c.

References FALSE.

Referenced by Init_Proc().

## ◆ rb_obj_method_arity()

int rb_obj_method_arity | ( | VALUE | obj,
|  | ID | id
| ) |  |

Definition at line 2781 of file proc.c.

References CLASS_OF, and rb_mod_method_arity().

## ◆ rb_obj_public_method()

VALUE rb_obj_public_method | ( | VALUE | obj,
|  | VALUE | vid
| ) |  |

Definition at line 2005 of file proc.c.

References TRUE.

Referenced by Init_Proc().

## ◆ rb_obj_singleton_method()

VALUE rb_obj_singleton_method | ( | VALUE | obj,
|  | VALUE | vid
| ) |  |

Definition at line 2035 of file proc.c.

References rb_method_entry_struct::def, FALSE, ID2SYM, METHOD::klass, METHOD::me, NIL_P, Qundef, rb_check_id(), rb_cMethod, rb_method_entry_at(), rb_singleton_class_get(), RCLASS_ORIGIN, UNDEFINED_METHOD_ENTRY_P, UNDEFINED_REFINED_METHOD_P, and UNREACHABLE_RETURN.

Referenced by Init_Proc().

## ◆ rb_proc_alloc()

VALUE rb_proc_alloc | ( | VALUE | klass | ) |

Definition at line 145 of file proc.c.

References TypedData_Make_Struct.

## ◆ rb_proc_arity()

int rb_proc_arity | ( | VALUE | self | ) |

Definition at line 1126 of file proc.c.

References rb_proc_t::block, GetProcPtr, rb_proc_t::is_lambda, max, and UNLIMITED_ARGUMENTS.

## ◆ rb_proc_call()

VALUE rb_proc_call | ( | VALUE | self,
|  | VALUE | args
| ) |  |

Definition at line 981 of file proc.c.

References check_argc, GetProcPtr, RARRAY_CONST_PTR, RARRAY_LEN, RB_GC_GUARD, RB_NO_KEYWORDS, rb_vm_invoke_proc(), rb_captured_block::self, and VM_BLOCK_HANDLER_NONE.

Referenced by rb_call_end_proc().

## ◆ rb_proc_call_kw()

VALUE rb_proc_call_kw | ( | VALUE | self,
|  | VALUE | args,
|  | int | kw_splat
| ) |  |

Definition at line 966 of file proc.c.

References argc, argv, check_argc, GetProcPtr, RARRAY_CONST_PTR, RARRAY_LEN, RB_GC_GUARD, rb_vm_invoke_proc(), rb_captured_block::self, and VM_BLOCK_HANDLER_NONE.

## ◆ rb_proc_call_with_block()

VALUE rb_proc_call_with_block | ( | VALUE | self,
|  | int | argc,
|  | const VALUE * | argv,
|  | VALUE | passed_procval
| ) |  |

Definition at line 1013 of file proc.c.

References argc, argv, GetProcPtr, RB_GC_GUARD, RB_NO_KEYWORDS, rb_vm_invoke_proc(), and rb_captured_block::self.

## ◆ rb_proc_call_with_block_kw()

VALUE rb_proc_call_with_block_kw | ( | VALUE | self,
|  | int | argc,
|  | const VALUE * | argv,
|  | VALUE | passed_procval,
|  | int | kw_splat
| ) |  |

Definition at line 1001 of file proc.c.

References argc, argv, GetProcPtr, RB_GC_GUARD, rb_vm_invoke_proc(), and rb_captured_block::self.

## ◆ rb_proc_get_iseq()

const rb_iseq_t * rb_proc_get_iseq | ( | VALUE | self,
|  | int * | is_proc
| ) |  |

Definition at line 1242 of file proc.c.

References rb_block::as, block_type_ifunc, block_type_iseq, block_type_proc, block_type_symbol, rb_block::captured, rb_captured_block::code, vm_ifunc::data, GetProcPtr, rb_captured_block::ifunc, IS_METHOD_PROC_IFUNC, rb_captured_block::iseq, NULL, rb_block::proc, rb_method_iseq(), rb_proc_get_iseq(), and VM_UNREACHABLE.

Referenced by rb_proc_get_iseq(), rb_proc_location(), and rb_resolve_me_location().

## ◆ rb_proc_lambda_p()

VALUE rb_proc_lambda_p | ( | VALUE | procval | ) |

Definition at line 275 of file proc.c.

References GetProcPtr, rb_proc_t::is_lambda, Qfalse, and Qtrue.

Referenced by Init_Proc().

## ◆ rb_proc_location()

VALUE rb_proc_location | ( | VALUE | self | ) |

Definition at line 1387 of file proc.c.

References rb_proc_get_iseq().

Referenced by Init_Proc().

## ◆ rb_proc_new()

VALUE rb_proc_new | ( | rb_block_call_func_t | func,
|  | VALUE | val
| ) |  |

Definition at line 3145 of file proc.c.

References ruby::backward::cxxanyargs::rb_iterate().

## ◆ rb_sym_to_proc()

VALUE rb_sym_to_proc | ( | VALUE | sym | ) |

Definition at line 1443 of file proc.c.

References id, ID2SYM, rb_block::proc, Qfalse, Qnil, RARRAY_AREF, rb_ary_store(), rb_ary_tmp_new(), rb_cProc, rb_gc_register_mark_object(), sym, and SYM2ID.

Referenced by Init_String(), and rb_vm_bh_to_procval().

## ◆ rb_unnamed_parameters()

VALUE rb_unnamed_parameters | ( | int | arity | ) |

Definition at line 1393 of file proc.c.

References CONST_ID, ID2SYM, OBJ_FREEZE, rb_ary_new2, rb_ary_new3, rb_ary_push(), and rb_ary_store().

Referenced by rb_tracearg_parameters().

## ◆ rb_vm_cref_in_context()

const rb_cref_t * rb_vm_cref_in_context | ( | VALUE | self,
|  | VALUE | cbase
| ) |  |

Definition at line 1640 of file vm.c.

References rb_execution_context_struct::cfp, rb_control_frame_struct::ep, NULL, rb_vm_get_ruby_level_next_cfp(), and rb_control_frame_struct::self.

## ◆ rb_vm_cref_new_toplevel()

rb_cref_t * rb_vm_cref_new_toplevel | ( | void |  | ) |

Definition at line 309 of file vm.c.

## ◆ rb_vm_ifunc_new()

struct vm_ifunc * rb_vm_ifunc_new | ( | rb_block_call_func_t | func,
|  | const void * | data,
|  | int | min_argc,
|  | int | max_argc
| ) |  |

Definition at line 705 of file proc.c.

References vm_ifunc::argc, CHAR_BIT, imemo_ifunc, rb_eRangeError, rb_imemo_new(), rb_raise(), SIZEOF_VALUE, and UNLIMITED_ARGUMENTS.

Referenced by rb_func_lambda_new(), and rb_lambda_call().

## Variable Documentation

## ◆ rb_cBinding

VALUE rb_cBinding

Definition at line 45 of file proc.c.

Referenced by Init_Binding(), and rb_vm_make_binding().

## ◆ rb_cMethod

VALUE rb_cMethod

Definition at line 44 of file proc.c.

Referenced by Init_Proc(), and rb_obj_singleton_method().

## ◆ rb_cProc

VALUE rb_cProc

Definition at line 46 of file proc.c.

Referenced by Init_Proc(), rb_block_lambda(), rb_block_proc(), rb_func_lambda_new(), rb_func_proc_new(), rb_proc_dup(), rb_sym_to_proc(), and rb_vm_bh_to_procval().

## ◆ rb_cUnboundMethod

VALUE rb_cUnboundMethod

Definition at line 43 of file proc.c.

Referenced by Init_Proc().

## ◆ ruby_binding_data_type

const rb_data_type_t ruby_binding_data_type

Initial value:
= {
"binding",
{
binding_mark,
binding_free,
binding_memsize,
binding_compact,
},
0, 0, RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
}
RUBY_TYPED_FREE_IMMEDIATELY
@ RUBY_TYPED_FREE_IMMEDIATELY
Definition: rtypeddata.h:62
RUBY_TYPED_WB_PROTECTED
@ RUBY_TYPED_WB_PROTECTED
Definition: rtypeddata.h:64

Definition at line 319 of file proc.c.

Referenced by rb_binding_alloc().