26 static ID id_members, id_back_members;
53 VALUE members = struct_ivar_get(klass, id_members);
77 struct_member_pos_ideal(
VALUE name,
long mask)
84 struct_member_pos_probe(
long prev,
long mask)
94 const long members_length =
RARRAY_LEN(members);
100 long i, j, mask = 64;
109 for (i=0; i < members_length; i++) {
112 j = struct_member_pos_ideal(name, mask);
120 j = struct_member_pos_probe(j, mask);
151 "struct size differs (%ld required %ld given)",
154 for (j = 0; j < mask; j++) {
167 j = struct_member_pos_ideal(name, mask);
175 j = struct_member_pos_probe(j, mask);
180 rb_struct_s_members_m(
VALUE klass)
199 rb_struct_members_m(
VALUE obj)
208 int i = struct_member_pos(obj, slot);
228 #define N_REF_FUNC numberof(ref_func) 244 rb_struct_modify(
VALUE s)
251 anonymous_struct(
VALUE klass)
300 const VALUE *ptr_members;
303 members = struct_set_members(nstr, members);
311 for (i=0; i<
len; i++) {
319 define_aref_method(nstr, ptr_members[i], off);
330 return struct_alloc(klass);
334 struct_make_members_list(va_list ar)
341 while ((mem = va_arg(ar,
char*)) != 0) {
368 klass = anonymous_struct(super);
371 struct_set_members(klass, members);
390 members = struct_make_members_list(ar);
393 return struct_define_without_accessor(outer, class_name, super, alloc, members);
403 members = struct_make_members_list(ar);
406 return struct_define_without_accessor(0, class_name, super, alloc, members);
416 ary = struct_make_members_list(ar);
421 return setup_struct(st, ary);
431 ary = struct_make_members_list(ar);
512 for (i=0; i<
argc; i++) {
523 st = anonymous_struct(klass);
526 st = new_struct(name, klass);
528 setup_struct(st, rest);
537 num_members(
VALUE klass)
540 members = struct_ivar_get(klass, id_members);
551 rb_struct_initialize_m(
int argc,
const VALUE *argv,
VALUE self)
556 rb_struct_modify(
self);
557 n = num_members(klass);
561 for (i=0; i<
argc; i++) {
577 struct_alloc(
VALUE klass)
582 n = num_members(klass);
616 va_start(args, klass);
617 for (i=0; i<
size; i++) {
618 mem[i] = va_arg(args,
VALUE);
651 rb_struct_each(
VALUE s)
682 rb_struct_each_pair(
VALUE s)
714 if (recur || first !=
'#') {
724 for (i=0; i<
len; i++) {
731 else if (first !=
'#') {
760 rb_struct_inspect(
VALUE s)
778 rb_struct_to_a(
VALUE s)
795 rb_struct_to_h(
VALUE s)
832 return struct_member_pos(s, idx);
836 if (
NIL_P(idx))
return -1;
837 return struct_member_pos(s, idx);
898 int i = rb_struct_pos(s, &idx);
899 if (i < 0) invalid_struct_pos(s, idx);
925 int i = rb_struct_pos(s, &idx);
926 if (i < 0) invalid_struct_pos(s, idx);
938 return rb_struct_lookup_default(s, idx,
Qnil);
944 int i = rb_struct_pos(s, &idx);
945 if (i < 0)
return notfound;
950 struct_entry(
VALUE s,
long n)
970 rb_struct_values_at(
int argc,
VALUE *argv,
VALUE s)
990 rb_struct_select(
int argc,
VALUE *argv,
VALUE s)
1008 recursive_equal(
VALUE s,
VALUE s2,
int recur)
1013 if (recur)
return Qtrue;
1017 for (i=0; i<
len; i++) {
1041 if (s == s2)
return Qtrue;
1045 rb_bug(
"inconsistent struct");
1061 rb_struct_hash(
VALUE s)
1071 for (i = 0; i <
len; i++) {
1085 if (recur)
return Qtrue;
1089 for (i=0; i<
len; i++) {
1107 if (s == s2)
return Qtrue;
1111 rb_bug(
"inconsistent struct");
1152 rb_struct_dig(
int argc,
VALUE *argv,
VALUE self)
1156 if (!--argc)
return self;
1228 id_back_members =
rb_intern(
"__members_back__");
#define RBASIC_CLEAR_CLASS(obj)
FUNC_MINIMIZED(VALUE rb_struct_lookup(VALUE s, VALUE idx))
NOINLINE(static VALUE rb_struct_lookup_default(VALUE s, VALUE idx, VALUE notfound))
VALUE rb_struct_s_members(VALUE klass)
void rb_warn(const char *fmt,...)
void rb_bug(const char *fmt,...)
VALUE rb_ary_entry(VALUE ary, long offset)
void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
#define RSTRUCT_CONST_PTR(st)
VALUE rb_yield_values(int n,...)
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.
VALUE rb_struct_define(const char *name,...)
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_struct_initialize(VALUE self, VALUE values)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
st_index_t rb_hash_end(st_index_t)
#define OBJ_INIT_COPY(obj, orig)
int rb_is_const_id(ID id)
void rb_check_trusted(VALUE obj)
void rb_mem_clear(register VALUE *mem, register long size)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_struct_getmember(VALUE obj, ID id)
VALUE rb_struct_aset(VALUE s, VALUE idx, VALUE val)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE rb_struct_alloc(VALUE klass, VALUE values)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_hash_new_with_size(st_index_t size)
#define rb_name_err_raise(mesg, recv, name)
VALUE rb_hash_keys(VALUE hash)
NORETURN(static void invalid_struct_pos(VALUE s, VALUE idx))
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_struct_aref(VALUE s, VALUE idx)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
#define RB_TYPE_P(obj, type)
VALUE rb_get_values_at(VALUE obj, long olen, int argc, const VALUE *argv, VALUE(*func)(VALUE, long))
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
#define RGENGC_WB_PROTECTED_STRUCT
VALUE rb_equal(VALUE, VALUE)
call-seq: obj === other -> true or false
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
void rb_ary_store(VALUE ary, long idx, VALUE val)
char ary[RSTRING_EMBED_LEN_MAX+1]
VALUE rb_struct_define_under(VALUE outer, const char *name,...)
#define OBJ_FREEZE_RAW(x)
VALUE rb_struct_new(VALUE klass,...)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
#define RARRAY_CONST_PTR(a)
int rb_is_const_name(VALUE name)
VALUE rb_to_symbol(VALUE name)
VALUE rb_class_path(VALUE)
VALUE rb_mod_module_eval(int, const VALUE *, VALUE)
VALUE rb_struct_size(VALUE s)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_assoc_new(VALUE car, VALUE cdr)
rb_control_frame_t *FUNC_FASTCALL() rb_vm_opt_struct_aref(rb_thread_t *th, rb_control_frame_t *reg_cfp)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
VALUE rb_struct_define_without_accessor(const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
const rb_iseq_t * rb_method_for_self_aset(VALUE name, VALUE arg, rb_insn_func_t func)
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
#define RARRAY_LENINT(ary)
VALUE rb_sym_intern_ascii_cstr(const char *ptr)
register unsigned int len
#define RSTRUCT_SET(st, idx, v)
int rb_const_defined_at(VALUE, ID)
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
VALUE rb_ident_hash_new(void)
#define RSTRUCT_GET(st, idx)
#define UNLIMITED_ARGUMENTS
#define RARRAY_AREF(a, i)
const rb_iseq_t * rb_method_for_self_aref(VALUE name, VALUE arg, rb_insn_func_t func)
rb_control_frame_t *FUNC_FASTCALL rb_insn_func_t(rb_thread_t *, rb_control_frame_t *)
VALUE rb_mod_remove_const(VALUE, VALUE)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
st_index_t rb_hash_uint(st_index_t, st_index_t)
struct rb_encoding_entry * list
VALUE rb_ary_dup(VALUE ary)
int rb_is_local_id(ID id)
VALUE rb_check_symbol(volatile VALUE *namep)
int rb_eql(VALUE, VALUE)
Determines if obj1 and obj2 are equal in terms of Object::eql?.
VALUE rb_struct_alloc_noinit(VALUE klass)
VALUE rb_struct_members(VALUE s)
void st_clear(st_table *)
#define rb_check_frozen(obj)
rb_control_frame_t *FUNC_FASTCALL() rb_vm_opt_struct_aset(rb_thread_t *th, rb_control_frame_t *reg_cfp)
VALUE(* rb_alloc_func_t)(VALUE)
VALUE rb_struct_lookup(VALUE s, VALUE idx)
VALUE rb_class_new(VALUE super)
Creates a new class.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
VALUE rb_str_to_str(VALUE)
st_index_t rb_hash_start(st_index_t)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_struct_init_copy(VALUE copy, VALUE s)