Ruby
2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
|
Go to the documentation of this file.
27 static ID id_members, id_back_members, id_keyword_init;
54 return struct_ivar_get(
klass, id_keyword_init);
60 VALUE members = struct_ivar_get(
klass, id_members);
91 struct_member_pos_probe(
long prev,
long mask)
101 const long members_length =
RARRAY_LEN(members);
107 long i, j,
mask = 64;
116 for (
i=0;
i < members_length;
i++) {
119 j = struct_member_pos_ideal(
name,
mask);
127 j = struct_member_pos_probe(j,
mask);
156 "struct size differs (%ld required %ld given)",
159 for (j = 0; j <
mask; j++) {
172 j = struct_member_pos_ideal(
name,
mask);
181 j = struct_member_pos_probe(j,
mask);
214 int i = struct_member_pos(
obj, slot);
234 #define N_REF_FUNC numberof(ref_func)
250 rb_struct_modify(
VALUE s)
323 members = struct_set_members(nstr, members);
340 define_aref_method(nstr,
sym, off);
351 return struct_alloc(
klass);
355 struct_make_members_list(
va_list ar)
362 while ((mem =
va_arg(ar,
char*)) != 0) {
389 klass = anonymous_struct(super);
392 struct_set_members(
klass, members);
411 members = struct_make_members_list(ar);
414 return struct_define_without_accessor(outer, class_name, super, alloc, members);
424 members = struct_make_members_list(ar);
427 return struct_define_without_accessor(0, class_name, super, alloc, members);
437 ary = struct_make_members_list(ar);
442 return setup_struct(
st,
ary);
452 ary = struct_make_members_list(ar);
540 static ID keyword_ids[1];
542 if (!keyword_ids[0]) {
543 keyword_ids[0] =
rb_intern(
"keyword_init");
546 if (keyword_init ==
Qundef) {
574 setup_struct(
st, rest);
587 members = struct_ivar_get(
klass, id_members);
608 int i = rb_struct_pos(args->
self, &
key);
616 rb_struct_modify(args->
self);
628 rb_struct_modify(
self);
639 if (
arg.unknown_keywords !=
Qnil) {
679 #if USE_TRANSIENT_HEAP
684 const VALUE *old_ptr = rb_struct_const_heap_ptr(
obj);
693 new_ptr = struct_heap_alloc(
obj,
len);
715 st->as.heap.ptr = struct_heap_alloc((
VALUE)
st,
n);
776 rb_struct_each(
VALUE s)
807 rb_struct_each_pair(
VALUE s)
839 if (
recur || first !=
'#') {
856 else if (first !=
'#') {
884 rb_struct_inspect(
VALUE s)
902 rb_struct_to_a(
VALUE s)
925 rb_struct_to_h(
VALUE s)
949 return rb_struct_to_h(s);
953 "wrong argument type %"PRIsVALUE" (expected Array or nil)",
963 int i = rb_struct_pos(s, &
key);
997 return struct_member_pos(s, idx);
1001 if (
NIL_P(idx))
return -1;
1002 return struct_member_pos(s, idx);
1015 else if (
len <=
i) {
1063 int i = rb_struct_pos(s, &idx);
1064 if (
i < 0) invalid_struct_pos(s, idx);
1090 int i = rb_struct_pos(s, &idx);
1091 if (
i < 0) invalid_struct_pos(s, idx);
1092 rb_struct_modify(s);
1103 return rb_struct_lookup_default(s, idx,
Qnil);
1109 int i = rb_struct_pos(s, &idx);
1110 if (
i < 0)
return notfound;
1115 struct_entry(
VALUE s,
long n)
1211 rb_bug(
"inconsistent struct");
1227 rb_struct_hash(
VALUE s)
1235 for (
i = 0;
i <
len;
i++) {
1272 rb_bug(
"inconsistent struct");
1317 if (!--
argc)
return self;
1393 id_back_members =
rb_intern(
"__members_back__");
1394 id_keyword_init =
rb_intern(
"__keyword_init__");
int rb_is_const_name(VALUE name)
VALUE rb_check_symbol(volatile VALUE *namep)
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
int rb_is_const_id(ID id)
const rb_iseq_t * rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_struct_init_copy(VALUE copy, VALUE s)
VALUE rb_mod_remove_const(VALUE, VALUE)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
MJIT_FUNC_EXPORTED VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
FUNC_MINIMIZED(VALUE rb_struct_lookup(VALUE s, VALUE idx))
#define RB_PASS_CALLED_KEYWORDS
VALUE rb_ident_hash_new(void)
VALUE rb_struct_alloc(VALUE klass, VALUE values)
VALUE rb_struct_members(VALUE s)
void rb_warn(const char *fmt,...)
VALUE rb_struct_aset(VALUE s, VALUE idx, VALUE val)
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
#define RBASIC_CLEAR_CLASS(obj)
VALUE rb_struct_lookup(VALUE s, VALUE idx)
VALUE rb_to_symbol(VALUE name)
rb_control_frame_t *FUNC_FASTCALL() rb_vm_opt_struct_aset(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)
VALUE rb_struct_new(VALUE klass,...)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_class_new_instance_kw(int, const VALUE *, VALUE, int)
VALUE rb_equal(VALUE, VALUE)
Same as Object#===, case equality.
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define RB_TYPE_P(obj, type)
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_get_values_at(VALUE obj, long olen, int argc, const VALUE *argv, VALUE(*func)(VALUE, long))
int rb_is_attrset_sym(VALUE sym)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
MJIT_FUNC_EXPORTED VALUE rb_hash_keys(VALUE hash)
#define RSTRUCT_TRANSIENT_SET(st)
VALUE rb_struct_s_keyword_init(VALUE klass)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
VALUE rb_struct_define(const char *name,...)
#define RSTRUCT_EMBED_LEN_MAX
int st_insert(st_table *tab, st_data_t key, st_data_t value)
char ary[RSTRING_EMBED_LEN_MAX+1]
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int rb_eql(VALUE, VALUE)
Determines if obj1 and obj2 are equal in terms of Object::eql?.
VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
MJIT_FUNC_EXPORTED VALUE rb_hash_new_with_size(st_index_t size)
#define RARRAY_LENINT(ary)
#define UNLIMITED_ARGUMENTS
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ary_entry(VALUE ary, long offset)
NORETURN(static void invalid_struct_pos(VALUE s, VALUE idx))
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
void st_clear(st_table *tab)
#define rb_check_frozen(obj)
#define RSTRUCT_TRANSIENT_P(st)
VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound)
rb_control_frame_t *FUNC_FASTCALL rb_insn_func_t(rb_execution_context_t *, rb_control_frame_t *)
#define RGENGC_WB_PROTECTED_STRUCT
#define RSTRUCT_EMBED_LEN_MASK
VALUE rb_ary_tmp_new(long capa)
void rb_struct_transient_heap_evacuate(VALUE obj, int promote)
VALUE rb_struct_aref(VALUE s, VALUE idx)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_struct_alloc_noinit(VALUE klass)
st_index_t rb_hash_start(st_index_t)
#define RARRAY_AREF(a, i)
#define RSTRUCT_EMBED_LEN_SHIFT
void * rb_transient_heap_alloc(VALUE obj, size_t req_size)
VALUE rb_struct_getmember(VALUE obj, ID id)
void rb_mem_clear(VALUE *mem, long size)
VALUE rb_struct_size(VALUE s)
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
struct rb_encoding_entry * list
const rb_iseq_t * rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
#define RSTRUCT_SET(st, idx, v)
VALUE rb_hash_set_pair(VALUE hash, VALUE arg)
VALUE rb_struct_define_under(VALUE outer, const char *name,...)
VALUE rb_str_to_str(VALUE)
VALUE rb_class_new(VALUE super)
Creates a new class.
RUBY_EXTERN VALUE rb_cObject
#define FL_UNSET_RAW(x, f)
VALUE rb_str_append(VALUE, VALUE)
void rb_bug(const char *fmt,...)
#define OBJ_INIT_COPY(obj, orig)
#define RSTRUCT_TRANSIENT_UNSET(st)
#define rb_hash_uint(h, i)
VALUE rb_ary_join(VALUE ary, VALUE sep)
VALUE rb_struct_define_without_accessor(const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
char str[HTML_ESCAPE_MAX_LEN+1]
#define RARRAY_CONST_PTR(s)
#define MEMCPY(p1, p2, type, n)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE(* rb_alloc_func_t)(VALUE)
#define OBJ_FREEZE_RAW(x)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
int rb_is_local_id(ID id)
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
#define RSTRUCT_GET(st, idx)
VALUE rb_class_name(VALUE)
VALUE rb_class_path(VALUE)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
VALUE rb_ary_dup(VALUE ary)
VALUE rb_struct_initialize(VALUE self, VALUE values)
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
int rb_const_defined_at(VALUE, ID)
VALUE rb_struct_s_members(VALUE klass)
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
#define rb_name_err_raise(mesg, recv, name)
void rb_undef_alloc_func(VALUE)
#define UNREACHABLE_RETURN(val)
VALUE rb_mod_module_eval(int, const VALUE *, VALUE)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
rb_control_frame_t *FUNC_FASTCALL() rb_vm_opt_struct_aref(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp)
#define RSTRUCT_CONST_PTR(st)
NOINLINE(static VALUE rb_struct_lookup_default(VALUE s, VALUE idx, VALUE notfound))