Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
|
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)
319 setup_struct(
VALUE nstr,
VALUE members,
int keyword_init)
324 if (keyword_init) new_func = struct_new_kw;
326 members = struct_set_members(nstr, members);
343 define_aref_method(nstr,
sym, off);
354 return struct_alloc(
klass);
358 struct_make_members_list(
va_list ar)
365 while ((mem =
va_arg(ar,
char*)) != 0) {
392 klass = anonymous_struct(super);
395 struct_set_members(
klass, members);
414 members = struct_make_members_list(ar);
417 return struct_define_without_accessor(outer, class_name, super, alloc, members);
427 members = struct_make_members_list(ar);
430 return struct_define_without_accessor(0, class_name, super, alloc, members);
440 ary = struct_make_members_list(ar);
445 return setup_struct(
st,
ary, 0);
455 ary = struct_make_members_list(ar);
543 static ID keyword_ids[1];
545 if (!keyword_ids[0]) {
546 keyword_ids[0] =
rb_intern(
"keyword_init");
549 if (keyword_init ==
Qundef) {
577 setup_struct(
st, rest, (
int)keyword_init);
590 members = struct_ivar_get(
klass, id_members);
611 int i = rb_struct_pos(args->
self, &
key);
619 rb_struct_modify(args->
self);
631 rb_struct_modify(
self);
642 if (
arg.unknown_keywords !=
Qnil) {
682 #if USE_TRANSIENT_HEAP
687 const VALUE *old_ptr = rb_struct_const_heap_ptr(
obj);
696 new_ptr = struct_heap_alloc(
obj,
len);
718 st->as.heap.ptr = struct_heap_alloc((
VALUE)
st,
n);
779 rb_struct_each(
VALUE s)
810 rb_struct_each_pair(
VALUE s)
842 if (
recur || first !=
'#') {
859 else if (first !=
'#') {
887 rb_struct_inspect(
VALUE s)
905 rb_struct_to_a(
VALUE s)
928 rb_struct_to_h(
VALUE s)
952 return rb_struct_to_h(s);
956 "wrong argument type %"PRIsVALUE" (expected Array or nil)",
966 int i = rb_struct_pos(s, &
key);
1000 return struct_member_pos(s, idx);
1004 if (
NIL_P(idx))
return -1;
1005 return struct_member_pos(s, idx);
1018 else if (
len <=
i) {
1066 int i = rb_struct_pos(s, &idx);
1067 if (
i < 0) invalid_struct_pos(s, idx);
1093 int i = rb_struct_pos(s, &idx);
1094 if (
i < 0) invalid_struct_pos(s, idx);
1095 rb_struct_modify(s);
1106 return rb_struct_lookup_default(s, idx,
Qnil);
1112 int i = rb_struct_pos(s, &idx);
1113 if (
i < 0)
return notfound;
1118 struct_entry(
VALUE s,
long n)
1214 rb_bug(
"inconsistent struct");
1230 rb_struct_hash(
VALUE s)
1238 for (
i = 0;
i <
len;
i++) {
1275 rb_bug(
"inconsistent struct");
1320 if (!--
argc)
return self;
1396 id_back_members =
rb_intern(
"__members_back__");
1397 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 RSTRUCT_EMBED_LEN_SHIFT
#define RARRAY_AREF(a, i)
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)
#define RARRAY_CONST_PTR(a)
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 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))