Ruby  2.4.2p198(2017-09-14revision59899)
Macros | Enumerations | Functions | Variables
struct.c File Reference
#include "internal.h"
#include "vm_core.h"
#include "id.h"
Include dependency graph for struct.c:

Go to the source code of this file.

Macros

#define N_REF_FUNC   numberof(ref_func)
 

Enumerations

enum  { AREF_HASH_UNIT = 5, AREF_HASH_THRESHOLD = 10 }
 

Functions

const rb_iseq_trb_method_for_self_aref (VALUE name, VALUE arg, rb_insn_func_t func)
 
const rb_iseq_trb_method_for_self_aset (VALUE name, VALUE arg, rb_insn_func_t func)
 
static VALUE struct_alloc (VALUE)
 
static VALUE struct_ivar_get (VALUE c, ID id)
 
VALUE rb_struct_s_members (VALUE klass)
 
VALUE rb_struct_members (VALUE s)
 
static long struct_member_pos_ideal (VALUE name, long mask)
 
static long struct_member_pos_probe (long prev, long mask)
 
static VALUE struct_set_members (VALUE klass, VALUE members)
 
static int struct_member_pos (VALUE s, VALUE name)
 
static VALUE rb_struct_s_members_m (VALUE klass)
 
static VALUE rb_struct_members_m (VALUE obj)
 
VALUE rb_struct_getmember (VALUE obj, ID id)
 
static VALUE rb_struct_ref0 (VALUE obj)
 
static VALUE rb_struct_ref1 (VALUE obj)
 
static VALUE rb_struct_ref2 (VALUE obj)
 
static VALUE rb_struct_ref3 (VALUE obj)
 
static VALUE rb_struct_ref4 (VALUE obj)
 
static VALUE rb_struct_ref5 (VALUE obj)
 
static VALUE rb_struct_ref6 (VALUE obj)
 
static VALUE rb_struct_ref7 (VALUE obj)
 
static VALUE rb_struct_ref8 (VALUE obj)
 
static VALUE rb_struct_ref9 (VALUE obj)
 
static void rb_struct_modify (VALUE s)
 
static VALUE anonymous_struct (VALUE klass)
 
static VALUE new_struct (VALUE name, VALUE super)
 
static void define_aref_method (VALUE nstr, VALUE name, VALUE off)
 
static void define_aset_method (VALUE nstr, VALUE name, VALUE off)
 
static VALUE setup_struct (VALUE nstr, VALUE members)
 
VALUE rb_struct_alloc_noinit (VALUE klass)
 
static VALUE struct_make_members_list (va_list ar)
 
static VALUE struct_define_without_accessor (VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, VALUE members)
 
VALUE rb_struct_define_without_accessor_under (VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
 
VALUE rb_struct_define_without_accessor (const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
 
VALUE rb_struct_define (const char *name,...)
 
VALUE rb_struct_define_under (VALUE outer, const char *name,...)
 
static VALUE rb_struct_s_def (int argc, VALUE *argv, VALUE klass)
 
static long num_members (VALUE klass)
 
static VALUE rb_struct_initialize_m (int argc, const VALUE *argv, VALUE self)
 
VALUE rb_struct_initialize (VALUE self, VALUE values)
 
VALUE rb_struct_alloc (VALUE klass, VALUE values)
 
VALUE rb_struct_new (VALUE klass,...)
 
static VALUE struct_enum_size (VALUE s, VALUE args, VALUE eobj)
 
static VALUE rb_struct_each (VALUE s)
 
static VALUE rb_struct_each_pair (VALUE s)
 
static VALUE inspect_struct (VALUE s, VALUE dummy, int recur)
 
static VALUE rb_struct_inspect (VALUE s)
 
static VALUE rb_struct_to_a (VALUE s)
 
static VALUE rb_struct_to_h (VALUE s)
 
VALUE rb_struct_init_copy (VALUE copy, VALUE s)
 
static int rb_struct_pos (VALUE s, VALUE *name)
 
 NORETURN (static void invalid_struct_pos(VALUE s, VALUE idx))
 
static void invalid_struct_pos (VALUE s, VALUE idx)
 
VALUE rb_struct_aref (VALUE s, VALUE idx)
 
VALUE rb_struct_aset (VALUE s, VALUE idx, VALUE val)
 
 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_lookup (VALUE s, VALUE idx)
 
static VALUE rb_struct_lookup_default (VALUE s, VALUE idx, VALUE notfound)
 
static VALUE struct_entry (VALUE s, long n)
 
static VALUE rb_struct_values_at (int argc, VALUE *argv, VALUE s)
 
static VALUE rb_struct_select (int argc, VALUE *argv, VALUE s)
 
static VALUE recursive_equal (VALUE s, VALUE s2, int recur)
 
static VALUE rb_struct_equal (VALUE s, VALUE s2)
 
static VALUE rb_struct_hash (VALUE s)
 
static VALUE recursive_eql (VALUE s, VALUE s2, int recur)
 
static VALUE rb_struct_eql (VALUE s, VALUE s2)
 
VALUE rb_struct_size (VALUE s)
 
const VALUErb_struct_ptr (VALUE s)
 
static VALUE rb_struct_dig (int argc, VALUE *argv, VALUE self)
 
void InitVM_Struct (void)
 
void Init_Struct (void)
 

Variables

VALUE rb_cStruct
 
static ID id_members
 
static ID id_back_members
 
static VALUE(*const ref_func [])(VALUE)
 

Macro Definition Documentation

◆ N_REF_FUNC

#define N_REF_FUNC   numberof(ref_func)

Definition at line 228 of file struct.c.

Referenced by rb_struct_new(), and setup_struct().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
AREF_HASH_UNIT 
AREF_HASH_THRESHOLD 

Definition at line 17 of file struct.c.

Function Documentation

◆ anonymous_struct()

static VALUE anonymous_struct ( VALUE  klass)
static

◆ define_aref_method()

static void define_aref_method ( VALUE  nstr,
VALUE  name,
VALUE  off 
)
static

◆ define_aset_method()

static void define_aset_method ( VALUE  nstr,
VALUE  name,
VALUE  off 
)
static

◆ FUNC_MINIMIZED()

FUNC_MINIMIZED ( VALUE   rb_struct_lookupVALUE s, VALUE idx)

Referenced by rb_struct_aset().

◆ Init_Struct()

void Init_Struct ( void  )

Definition at line 1231 of file struct.c.

References id_back_members, id_members, InitVM, and rb_intern.

◆ InitVM_Struct()

void InitVM_Struct ( void  )

◆ inspect_struct()

static VALUE inspect_struct ( VALUE  s,
VALUE  dummy,
int  recur 
)
static

◆ invalid_struct_pos()

static void invalid_struct_pos ( VALUE  s,
VALUE  idx 
)
static

◆ new_struct()

static VALUE new_struct ( VALUE  name,
VALUE  super 
)
static

◆ NOINLINE()

NOINLINE ( static VALUE   rb_struct_lookup_defaultVALUE s, VALUE idx, VALUE notfound)

Referenced by rb_struct_aset().

◆ NORETURN()

NORETURN ( static void   invalid_struct_posVALUE s, VALUE idx)

Referenced by rb_struct_pos().

◆ num_members()

static long num_members ( VALUE  klass)
static

◆ rb_method_for_self_aref()

const rb_iseq_t* rb_method_for_self_aref ( VALUE  name,
VALUE  arg,
rb_insn_func_t  func 
)

Definition at line 7144 of file compile.c.

References for_self_aref(), and method_for_self().

Referenced by define_aref_method().

◆ rb_method_for_self_aset()

const rb_iseq_t* rb_method_for_self_aset ( VALUE  name,
VALUE  arg,
rb_insn_func_t  func 
)

Definition at line 7153 of file compile.c.

References for_self_aset(), and method_for_self().

Referenced by define_aset_method().

◆ rb_struct_alloc()

VALUE rb_struct_alloc ( VALUE  klass,
VALUE  values 
)

Definition at line 599 of file struct.c.

References RARRAY_CONST_PTR, RARRAY_LENINT, and rb_class_new_instance().

◆ rb_struct_alloc_noinit()

VALUE rb_struct_alloc_noinit ( VALUE  klass)

Definition at line 328 of file struct.c.

References struct_alloc().

Referenced by Init_thread_sync(), and range_alloc().

◆ rb_struct_aref()

VALUE rb_struct_aref ( VALUE  s,
VALUE  idx 
)

Definition at line 896 of file struct.c.

References invalid_struct_pos(), rb_struct_pos(), and RSTRUCT_GET.

Referenced by InitVM_Struct(), rb_vm_opt_struct_aref(), and struct_entry().

◆ rb_struct_aset()

VALUE rb_struct_aset ( VALUE  s,
VALUE  idx,
VALUE  val 
)

◆ rb_struct_define()

VALUE rb_struct_define ( const char *  name,
  ... 
)

◆ rb_struct_define_under()

VALUE rb_struct_define_under ( VALUE  outer,
const char *  name,
  ... 
)

◆ rb_struct_define_without_accessor()

VALUE rb_struct_define_without_accessor ( const char *  class_name,
VALUE  super,
rb_alloc_func_t  alloc,
  ... 
)

Definition at line 397 of file struct.c.

References struct_define_without_accessor(), and struct_make_members_list().

Referenced by Init_Range().

◆ rb_struct_define_without_accessor_under()

VALUE rb_struct_define_without_accessor_under ( VALUE  outer,
const char *  class_name,
VALUE  super,
rb_alloc_func_t  alloc,
  ... 
)

Definition at line 384 of file struct.c.

References struct_define_without_accessor(), and struct_make_members_list().

Referenced by Init_thread_sync().

◆ rb_struct_dig()

static VALUE rb_struct_dig ( int  argc,
VALUE argv,
VALUE  self 
)
static

Definition at line 1158 of file struct.c.

References argv, Qnil, rb_check_arity, rb_obj_dig(), rb_struct_lookup(), and UNLIMITED_ARGUMENTS.

Referenced by InitVM_Struct().

◆ rb_struct_each()

static VALUE rb_struct_each ( VALUE  s)
static

Definition at line 651 of file struct.c.

References rb_yield(), RETURN_SIZED_ENUMERATOR, RSTRUCT_GET, RSTRUCT_LEN, and struct_enum_size().

Referenced by InitVM_Struct().

◆ rb_struct_each_pair()

static VALUE rb_struct_each_pair ( VALUE  s)
static

◆ rb_struct_eql()

static VALUE rb_struct_eql ( VALUE  s,
VALUE  s2 
)
static

◆ rb_struct_equal()

static VALUE rb_struct_equal ( VALUE  s,
VALUE  s2 
)
static

◆ rb_struct_getmember()

VALUE rb_struct_getmember ( VALUE  obj,
ID  id 
)

Definition at line 205 of file struct.c.

References ID2SYM, rb_name_err_raise, RSTRUCT_GET, struct_member_pos(), and UNREACHABLE.

◆ rb_struct_hash()

static VALUE rb_struct_hash ( VALUE  s)
static

◆ rb_struct_init_copy()

VALUE rb_struct_init_copy ( VALUE  copy,
VALUE  s 
)

Definition at line 809 of file struct.c.

References len, OBJ_INIT_COPY, rb_eTypeError, rb_raise(), RSTRUCT_GET, RSTRUCT_LEN, and RSTRUCT_SET.

Referenced by InitVM_Struct(), and range_initialize_copy().

◆ rb_struct_initialize()

VALUE rb_struct_initialize ( VALUE  self,
VALUE  values 
)

Definition at line 571 of file struct.c.

References RARRAY_CONST_PTR, RARRAY_LENINT, and rb_struct_initialize_m().

Referenced by r_object0().

◆ rb_struct_initialize_m()

static VALUE rb_struct_initialize_m ( int  argc,
const VALUE argv,
VALUE  self 
)
static

◆ rb_struct_inspect()

static VALUE rb_struct_inspect ( VALUE  s)
static

Definition at line 760 of file struct.c.

References inspect_struct(), and rb_exec_recursive().

Referenced by InitVM_Struct().

◆ rb_struct_lookup()

VALUE rb_struct_lookup ( VALUE  s,
VALUE  idx 
)

Definition at line 936 of file struct.c.

References Qnil, and rb_struct_lookup_default().

Referenced by rb_obj_dig(), rb_struct_aset(), and rb_struct_dig().

◆ rb_struct_lookup_default()

static VALUE rb_struct_lookup_default ( VALUE  s,
VALUE  idx,
VALUE  notfound 
)
static

Definition at line 942 of file struct.c.

References rb_struct_pos(), and RSTRUCT_GET.

Referenced by rb_struct_aset(), and rb_struct_lookup().

◆ rb_struct_members()

VALUE rb_struct_members ( VALUE  s)

◆ rb_struct_members_m()

static VALUE rb_struct_members_m ( VALUE  obj)
static

Definition at line 199 of file struct.c.

References rb_obj_class(), and rb_struct_s_members_m().

Referenced by InitVM_Struct().

◆ rb_struct_modify()

static void rb_struct_modify ( VALUE  s)
static

Definition at line 244 of file struct.c.

References rb_check_frozen, and rb_check_trusted().

Referenced by rb_struct_aset(), and rb_struct_initialize_m().

◆ rb_struct_new()

VALUE rb_struct_new ( VALUE  klass,
  ... 
)

◆ rb_struct_pos()

static int rb_struct_pos ( VALUE  s,
VALUE name 
)
static

◆ rb_struct_ptr()

const VALUE* rb_struct_ptr ( VALUE  s)

Definition at line 1136 of file struct.c.

References RSTRUCT_CONST_PTR.

◆ rb_struct_ref0()

static VALUE rb_struct_ref0 ( VALUE  obj)
static

Definition at line 217 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref1()

static VALUE rb_struct_ref1 ( VALUE  obj)
static

Definition at line 218 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref2()

static VALUE rb_struct_ref2 ( VALUE  obj)
static

Definition at line 219 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref3()

static VALUE rb_struct_ref3 ( VALUE  obj)
static

Definition at line 220 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref4()

static VALUE rb_struct_ref4 ( VALUE  obj)
static

Definition at line 221 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref5()

static VALUE rb_struct_ref5 ( VALUE  obj)
static

Definition at line 222 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref6()

static VALUE rb_struct_ref6 ( VALUE  obj)
static

Definition at line 223 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref7()

static VALUE rb_struct_ref7 ( VALUE  obj)
static

Definition at line 224 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref8()

static VALUE rb_struct_ref8 ( VALUE  obj)
static

Definition at line 225 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_ref9()

static VALUE rb_struct_ref9 ( VALUE  obj)
static

Definition at line 226 of file struct.c.

References RSTRUCT_GET.

◆ rb_struct_s_def()

static VALUE rb_struct_s_def ( int  argc,
VALUE argv,
VALUE  klass 
)
static

◆ rb_struct_s_members()

VALUE rb_struct_s_members ( VALUE  klass)

◆ rb_struct_s_members_m()

static VALUE rb_struct_s_members_m ( VALUE  klass)
static

Definition at line 180 of file struct.c.

References rb_ary_dup(), and rb_struct_s_members().

Referenced by rb_struct_members_m(), and setup_struct().

◆ rb_struct_select()

static VALUE rb_struct_select ( int  argc,
VALUE argv,
VALUE  s 
)
static

◆ rb_struct_size()

VALUE rb_struct_size ( VALUE  s)

Definition at line 1130 of file struct.c.

References LONG2FIX, and RSTRUCT_LEN.

Referenced by InitVM_Struct(), and struct_enum_size().

◆ rb_struct_to_a()

static VALUE rb_struct_to_a ( VALUE  s)
static

Definition at line 778 of file struct.c.

References rb_ary_new4, RSTRUCT_CONST_PTR, and RSTRUCT_LEN.

Referenced by InitVM_Struct().

◆ rb_struct_to_h()

static VALUE rb_struct_to_h ( VALUE  s)
static

Definition at line 795 of file struct.c.

References rb_ary_entry(), rb_hash_aset(), rb_hash_new(), rb_struct_members(), RSTRUCT_GET, and RSTRUCT_LEN.

Referenced by InitVM_Struct().

◆ rb_struct_values_at()

static VALUE rb_struct_values_at ( int  argc,
VALUE argv,
VALUE  s 
)
static

Definition at line 970 of file struct.c.

References rb_get_values_at(), RSTRUCT_LEN, and struct_entry().

Referenced by InitVM_Struct().

◆ recursive_eql()

static VALUE recursive_eql ( VALUE  s,
VALUE  s2,
int  recur 
)
static

Definition at line 1080 of file struct.c.

References len, RString::ptr, Qfalse, Qtrue, rb_eql(), RSTRUCT_CONST_PTR, and RSTRUCT_LEN.

Referenced by rb_struct_eql().

◆ recursive_equal()

static VALUE recursive_equal ( VALUE  s,
VALUE  s2,
int  recur 
)
static

Definition at line 1008 of file struct.c.

References len, RString::ptr, Qfalse, Qtrue, rb_equal(), RSTRUCT_CONST_PTR, and RSTRUCT_LEN.

Referenced by rb_struct_equal().

◆ setup_struct()

static VALUE setup_struct ( VALUE  nstr,
VALUE  members 
)
static

◆ struct_alloc()

static VALUE struct_alloc ( VALUE  klass)
static

◆ struct_define_without_accessor()

static VALUE struct_define_without_accessor ( VALUE  outer,
const char *  class_name,
VALUE  super,
rb_alloc_func_t  alloc,
VALUE  members 
)
static

◆ struct_entry()

static VALUE struct_entry ( VALUE  s,
long  n 
)
static

Definition at line 950 of file struct.c.

References LONG2NUM, and rb_struct_aref().

Referenced by rb_struct_values_at().

◆ struct_enum_size()

static VALUE struct_enum_size ( VALUE  s,
VALUE  args,
VALUE  eobj 
)
static

Definition at line 626 of file struct.c.

References rb_struct_size().

Referenced by rb_struct_each(), rb_struct_each_pair(), and rb_struct_select().

◆ struct_ivar_get()

static VALUE struct_ivar_get ( VALUE  c,
ID  id 
)
inlinestatic

Definition at line 31 of file struct.c.

References NIL_P, Qnil, rb_attr_get(), rb_cStruct, rb_ivar_set(), and RCLASS_SUPER.

Referenced by num_members(), rb_struct_s_members(), and struct_member_pos().

◆ struct_make_members_list()

static VALUE struct_make_members_list ( va_list  ar)
static

◆ struct_member_pos()

static int struct_member_pos ( VALUE  s,
VALUE  name 
)
inlinestatic

◆ struct_member_pos_ideal()

static long struct_member_pos_ideal ( VALUE  name,
long  mask 
)
static

Definition at line 77 of file struct.c.

References ID_SCOPE_SHIFT, and SYM2ID.

Referenced by struct_member_pos(), and struct_set_members().

◆ struct_member_pos_probe()

static long struct_member_pos_probe ( long  prev,
long  mask 
)
static

Definition at line 84 of file struct.c.

References AREF_HASH_UNIT.

Referenced by struct_member_pos(), and struct_set_members().

◆ struct_set_members()

static VALUE struct_set_members ( VALUE  klass,
VALUE  members 
)
static

Variable Documentation

◆ id_back_members

ID id_back_members
static

Definition at line 26 of file struct.c.

Referenced by Init_Struct(), struct_member_pos(), and struct_set_members().

◆ id_members

ID id_members
static

Definition at line 26 of file struct.c.

Referenced by Init_Struct(), num_members(), rb_struct_s_members(), and struct_set_members().

◆ rb_cStruct

VALUE rb_cStruct

Definition at line 25 of file struct.c.

Referenced by InitVM_Struct(), rb_struct_define(), rb_struct_define_under(), and struct_ivar_get().

◆ ref_func

VALUE(*const ref_func[])(VALUE)
static
Initial value:
= {
}
static VALUE rb_struct_ref3(VALUE obj)
Definition: struct.c:220
static VALUE rb_struct_ref0(VALUE obj)
Definition: struct.c:217
static VALUE rb_struct_ref2(VALUE obj)
Definition: struct.c:219
static VALUE rb_struct_ref6(VALUE obj)
Definition: struct.c:223
static VALUE rb_struct_ref8(VALUE obj)
Definition: struct.c:225
static VALUE rb_struct_ref9(VALUE obj)
Definition: struct.c:226
static VALUE rb_struct_ref4(VALUE obj)
Definition: struct.c:221
static VALUE rb_struct_ref7(VALUE obj)
Definition: struct.c:224
static VALUE rb_struct_ref1(VALUE obj)
Definition: struct.c:218
static VALUE rb_struct_ref5(VALUE obj)
Definition: struct.c:222

Definition at line 230 of file struct.c.

Referenced by setup_struct().