14#include "internal/class.h"
15#include "internal/error.h"
16#include "internal/hash.h"
17#include "internal/object.h"
18#include "internal/proc.h"
19#include "internal/struct.h"
20#include "internal/symbol.h"
27 AREF_HASH_THRESHOLD = 10
35static ID id_members, id_back_members, id_keyword_init;
43 VALUE ivar = rb_attr_get(c,
id);
53 ivar = rb_attr_get(c,
id);
62rb_struct_s_keyword_init(
VALUE klass)
64 return struct_ivar_get(klass, id_keyword_init);
70 VALUE members = struct_ivar_get(klass, id_members);
86 if (RSTRUCT_LEN_RAW(s) !=
RARRAY_LEN(members)) {
87 rb_raise(
rb_eTypeError,
"struct size differs (%"PRIdLEN
" required %"PRIdLEN
" given)",
97 return (
SYM2ID(name) >> (ID_SCOPE_SHIFT - 1)) & mask;
104 return (prev * AREF_HASH_UNIT + 2) & mask;
113 if (members_length <= AREF_HASH_THRESHOLD) {
120 while (mask < members_length * AREF_HASH_UNIT) mask *= 2;
126 for (i=0; i < members_length; i++) {
129 j = struct_member_pos_ideal(name, mask);
137 j = struct_member_pos_probe(j, mask);
154 if (UNLIKELY(
NIL_P(back))) {
163 if (mask <= AREF_HASH_THRESHOLD) {
164 if (UNLIKELY(RSTRUCT_LEN_RAW(s) != mask)) {
166 "struct size differs (%"PRIdLEN
" required %"PRIdLEN
" given)",
167 mask, RSTRUCT_LEN_RAW(s));
169 for (j = 0; j < mask; j++) {
177 rb_raise(
rb_eTypeError,
"struct size differs (%d required %"PRIdLEN
" given)",
182 j = struct_member_pos_ideal(name, mask);
191 j = struct_member_pos_probe(j, mask);
207rb_struct_s_members_m(
VALUE klass)
227rb_struct_members_m(
VALUE obj)
236 int i = struct_member_pos(obj, slot);
238 return RSTRUCT_GET_RAW(obj, i);
240 rb_name_err_raise(
"'%1$s' is not a struct member", obj,
ID2SYM(
id));
246rb_struct_modify(
VALUE s)
252anonymous_struct(
VALUE klass)
255 rb_make_metaclass(nstr,
RBASIC(klass)->klass);
259NORETURN(
static void invalid_struct_pos(
VALUE s,
VALUE idx));
264 rb_add_method_optimized(nstr,
SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_AREF,
FIX2UINT(
off), METHOD_VISI_PUBLIC);
268rb_struct_define_aref_method(
VALUE nstr,
ID name,
unsigned int off)
270 rb_add_method_optimized(nstr, name, OPTIMIZED_METHOD_TYPE_STRUCT_AREF,
off, METHOD_VISI_PUBLIC);
276 rb_add_method_optimized(nstr,
SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_ASET,
FIX2UINT(
off), METHOD_VISI_PUBLIC);
280rb_struct_s_inspect(
VALUE klass)
283 if (
RTEST(rb_struct_s_keyword_init(klass))) {
289static VALUE rb_data_initialize_m(
int argc,
const VALUE *argv,
VALUE self);
295data_initialize_default_p(
VALUE klass)
298 return cme && cme->def->type == VM_METHOD_TYPE_CFUNC &&
299 cme->def->body.cfunc.func == (rb_cfunc_t)rb_data_initialize_m;
303rb_data_s_new(
int argc,
const VALUE *argv,
VALUE klass)
307 rb_error_arity(argc, 0, 0);
312 VALUE members = struct_ivar_get(klass, id_members);
316 if (argc == num_members && data_initialize_default_p(klass)) {
319 RSTRUCT_SET_RAW(self, i, argv[i]);
324 VALUE arg_hash = rb_hash_new_capa(argc);
327 rb_hash_aset(arg_hash, k, v);
351rb_struct_s_keyword_init_p(
VALUE obj)
356#define rb_struct_s_keyword_init_p rb_struct_s_keyword_init
363 members = struct_set_members(nstr, members);
373 for (i=0; i<
len; i++) {
378 define_aref_method(nstr, sym,
off);
379 define_aset_method(nstr,
ID2SYM(rb_id_attrset(
id)),
off);
390 members = struct_set_members(subclass, members);
401 for (i=0; i<
len; i++) {
405 define_aref_method(subclass, sym,
off);
414 return struct_alloc(klass);
418struct_make_members_list(va_list ar)
421 VALUE ary, list = rb_ident_hash_new();
422 RBASIC_CLEAR_CLASS(list);
423 while ((mem = va_arg(ar,
char*)) != 0) {
424 VALUE sym = rb_sym_intern_ascii_cstr(mem);
425 if (
RTEST(rb_hash_has_key(list, sym))) {
426 rb_raise(rb_eArgError,
"duplicate member: %s", mem);
428 rb_hash_aset(list, sym,
Qtrue);
430 ary = rb_hash_keys(list);
431 RBASIC_CLEAR_CLASS(ary);
443 if (!rb_is_const_name(name)) {
444 rb_name_err_raise(
"identifier %1$s needs to be constant",
450 rb_warn(
"redefining constant %"PRIsVALUE
"::%"PRIsVALUE, outer, name);
461 VALUE klass = anonymous_struct(super);
462 struct_set_members(klass, members);
473 struct_register_under(outer, name, klass);
474 rb_vm_register_global_object(klass);
489 members = struct_make_members_list(ar);
492 return struct_define_without_accessor(outer, class_name, super, alloc, members);
502 members = struct_make_members_list(ar);
505 return struct_define_without_accessor(0, class_name, super, alloc, members);
513 va_start(ar, class_name);
514 VALUE ary = struct_make_members_list(ar);
518 setup_struct(klass, ary);
522 struct_register_under(
rb_cStruct, name, klass);
523 rb_vm_register_global_object(klass);
538 ary = struct_make_members_list(ar);
669rb_struct_s_def(
int argc,
VALUE *argv,
VALUE super)
675 if (argc >= 1 && !
SYMBOL_P(argv[0])) {
682 static ID keyword_ids[1];
684 if (!keyword_ids[0]) {
685 keyword_ids[0] = rb_intern(
"keyword_init");
688 if (UNDEF_P(keyword_init)) {
691 else if (
RTEST(keyword_init)) {
692 keyword_init =
Qtrue;
696 VALUE rest = rb_ident_hash_new();
697 RBASIC_CLEAR_CLASS(rest);
698 for (
int i = 0; i < argc; i++) {
700 if (rb_is_attrset_sym(mem)) {
701 rb_raise(rb_eArgError,
"invalid struct member: %"PRIsVALUE, mem);
703 if (
RTEST(rb_hash_has_key(rest, mem))) {
704 rb_raise(rb_eArgError,
"duplicate member: %"PRIsVALUE, mem);
706 rb_hash_aset(rest, mem,
Qtrue);
708 rest = rb_hash_keys(rest);
709 RBASIC_CLEAR_CLASS(rest);
712 VALUE klass = anonymous_struct(super);
713 setup_struct(klass, rest);
730num_members(
VALUE klass)
733 members = struct_ivar_get(klass, id_members);
735 rb_bug(
"broken members");
741rb_zjit_struct_num_members(
VALUE klass)
743 return num_members(klass);
751 VALUE unknown_keywords;
756static int rb_struct_pos(
VALUE s,
VALUE *name,
bool name_only);
758static int rb_struct_pos(
VALUE s,
VALUE *name,
bool name_only);
763 int i = rb_struct_pos(args->self, &key, name_only);
765 if (!args->unknown_keywords) {
771 rb_struct_modify(args->self);
772 RSTRUCT_SET_RAW(args->self, i, val);
781 struct_hash_aset(key, val, args,
false);
786rb_struct_initialize_m(
int argc,
const VALUE *argv,
VALUE self)
789 rb_struct_modify(self);
796 bool keyword_init =
false;
797 switch (rb_struct_s_keyword_init(klass)) {
800 rb_error_arity(argc, 0, 0);
819 if (UNLIKELY(arg.unknown_keywords)) {
820 rb_raise(rb_eArgError,
"unknown keywords: %"PRIsVALUE,
826 rb_raise(rb_eArgError,
"struct size differs");
829 RSTRUCT_SET_RAW(self, i, argv[i]);
848struct_heap_alloc(
VALUE st,
size_t len)
853STATIC_ASSERT(robject_rstruct_fields_offset, offsetof(
struct RObject, as.
extended) == offsetof(
struct RStruct, fields_obj));
858 size_t embedded_size = offsetof(
struct RStruct, as.ary) + (
sizeof(
VALUE) * n);
859 const rb_len_t embed_len_max = RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT;
860 return n > 0 && n <= embed_len_max && rb_gc_size_allocatable_p(embedded_size);
864rb_zjit_struct_embedded_p(
rb_len_t num_members)
866 return struct_embedded_p(num_members);
870struct_alloc(
VALUE klass)
873 size_t embedded_size = offsetof(
struct RStruct, as.ary) + (
sizeof(
VALUE) * n);
876 if (struct_embedded_p(n)) {
877 flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
879 VALUE st = rb_newobj(GET_EC(), klass, flags, ROOT_SHAPE_ID | SHAPE_ID_LAYOUT_EXTENDED,
true, embedded_size);
880 RSTRUCT_SET_FIELDS_OBJ(st, 0);
886 VALUE obj = rb_newobj(GET_EC(), klass, flags, ROOT_SHAPE_ID | SHAPE_ID_LAYOUT_EXTENDED,
true,
sizeof(
struct RStruct));
887 struct RStruct *st = RSTRUCT(obj);
890 st->as.heap.ptr = NULL;
893 st->as.heap.ptr = struct_heap_alloc((
VALUE)st, n);
903rb_zjit_class_has_struct_allocator(
VALUE klass)
913 VALUE members = struct_ivar_get(klass, id_members);
928 VALUE tmpargs[16], *mem = tmpargs;
933 if (size > numberof(tmpargs)) {
937 va_start(args, klass);
938 for (i=0; i<size; i++) {
939 mem[i] = va_arg(args,
VALUE);
975rb_struct_each(
VALUE s)
980 for (i=0; i<RSTRUCT_LEN_RAW(s); i++) {
1010rb_struct_each_pair(
VALUE s)
1017 if (rb_block_pair_yield_optimizable()) {
1018 for (i=0; i<RSTRUCT_LEN_RAW(s); i++) {
1020 VALUE value = RSTRUCT_GET_RAW(s, i);
1025 for (i=0; i<RSTRUCT_LEN_RAW(s); i++) {
1027 VALUE value = RSTRUCT_GET_RAW(s, i);
1035inspect_struct(
VALUE s,
VALUE prefix,
int recur)
1041 char first = RSTRING_PTR(cname)[0];
1043 if (recur || first !=
'#') {
1052 len = RSTRUCT_LEN_RAW(s);
1054 for (i=0; i<
len; i++) {
1093rb_struct_inspect(
VALUE s)
1112rb_struct_to_a(
VALUE s)
1114 return rb_ary_new4(RSTRUCT_LEN_RAW(s), RSTRUCT_CONST_PTR(s));
1141rb_struct_to_h(
VALUE s)
1143 VALUE h = rb_hash_new_capa(RSTRUCT_LEN_RAW(s));
1148 for (i=0; i<RSTRUCT_LEN_RAW(s); i++) {
1153 rb_hash_aset(h, k, v);
1176rb_struct_deconstruct_keys(
VALUE s,
VALUE keys)
1178 return deconstruct_keys(s, keys,
false);
1182deconstruct_keys(
VALUE s,
VALUE keys,
bool name_only)
1188 return rb_struct_to_h(s);
1192 "wrong argument type %"PRIsVALUE
" (expected Array or nil)",
1197 return rb_hash_new();
1202 int i = rb_struct_pos(s, &key, name_only);
1206 rb_hash_aset(h, key, RSTRUCT_GET_RAW(s, i));
1218 if (RSTRUCT_LEN_RAW(copy) != RSTRUCT_LEN_RAW(s)) {
1222 for (i=0,
len=RSTRUCT_LEN_RAW(copy); i<
len; i++) {
1223 RSTRUCT_SET_RAW(copy, i, RSTRUCT_GET_RAW(s, i));
1230rb_struct_pos(
VALUE s,
VALUE *name,
bool name_only)
1236 return struct_member_pos(s, idx);
1240 if (
NIL_P(idx))
return -1;
1241 return struct_member_pos(s, idx);
1246 len = RSTRUCT_LEN_RAW(s);
1254 else if (
len <= i) {
1268 rb_raise(
rb_eIndexError,
"offset %"PRIdLEN
" too small for struct(size:%"PRIdLEN
")",
1272 rb_raise(
rb_eIndexError,
"offset %"PRIdLEN
" too large for struct(size:%"PRIdLEN
")",
1277 rb_name_err_raise(
"no member '%1$s' in struct", s, idx);
1310 int i = rb_struct_pos(s, &idx,
false);
1311 if (i < 0) invalid_struct_pos(s, idx);
1312 return RSTRUCT_GET_RAW(s, i);
1348 int i = rb_struct_pos(s, &idx,
false);
1349 if (i < 0) invalid_struct_pos(s, idx);
1350 rb_struct_modify(s);
1351 RSTRUCT_SET_RAW(s, i, val);
1356NOINLINE(
static VALUE rb_struct_lookup_default(
VALUE s,
VALUE idx,
VALUE notfound,
bool name_only));
1361 return rb_struct_lookup_default(s, idx,
Qnil,
false);
1365rb_struct_lookup_default(
VALUE s,
VALUE idx,
VALUE notfound,
bool name_only)
1367 int i = rb_struct_pos(s, &idx, name_only);
1368 if (i < 0)
return notfound;
1369 return RSTRUCT_GET_RAW(s, i);
1414rb_struct_values_at(
int argc,
VALUE *argv,
VALUE s)
1438rb_struct_select(
int argc,
VALUE *argv,
VALUE s)
1446 for (i = 0; i < RSTRUCT_LEN_RAW(s); i++) {
1460 if (recur)
return Qtrue;
1461 len = RSTRUCT_LEN_RAW(s);
1462 for (i=0; i<
len; i++) {
1463 if (!rb_equal(RSTRUCT_GET_RAW(s, i), RSTRUCT_GET_RAW(s2, i)))
return Qfalse;
1492 if (s == s2)
return Qtrue;
1495 if (RSTRUCT_LEN_RAW(s) != RSTRUCT_LEN_RAW(s2)) {
1496 rb_bug(
"inconsistent struct");
1522rb_struct_hash(
VALUE s)
1529 len = RSTRUCT_LEN_RAW(s);
1530 for (i = 0; i <
len; i++) {
1531 n = rb_hash(RSTRUCT_GET_RAW(s, i));
1543 if (recur)
return Qtrue;
1544 len = RSTRUCT_LEN_RAW(s);
1545 for (i=0; i<
len; i++) {
1546 if (!rb_eql(RSTRUCT_GET_RAW(s, i), RSTRUCT_GET_RAW(s2, i)))
return Qfalse;
1573 if (s == s2)
return Qtrue;
1576 if (RSTRUCT_LEN_RAW(s) != RSTRUCT_LEN_RAW(s2)) {
1577 rb_bug(
"inconsistent struct");
1598 return LEN2NUM(RSTRUCT_LEN_RAW(s));
1634rb_struct_dig(
int argc,
VALUE *argv,
VALUE self)
1637 self = rb_struct_lookup(self, *argv);
1638 if (!--argc)
return self;
1640 return rb_obj_dig(argc, argv, self,
Qnil);
1759rb_data_s_def(
int argc,
VALUE *argv,
VALUE super)
1761 VALUE rest = rb_ident_hash_new();
1762 RBASIC_CLEAR_CLASS(rest);
1763 for (
int i = 0; i < argc; i++) {
1765 if (rb_is_attrset_sym(mem)) {
1766 rb_raise(rb_eArgError,
"invalid data member: %"PRIsVALUE, mem);
1768 if (
RTEST(rb_hash_has_key(rest, mem))) {
1769 rb_raise(rb_eArgError,
"duplicate member: %"PRIsVALUE, mem);
1771 rb_hash_aset(rest, mem,
Qtrue);
1773 rest = rb_hash_keys(rest);
1774 RBASIC_CLEAR_CLASS(rest);
1777 VALUE klass = anonymous_struct(super);
1778 setup_data(klass, rest);
1794 va_start(ar, super);
1795 ary = struct_make_members_list(ar);
1797 if (!super) super = rb_cData;
1798 VALUE klass = setup_data(anonymous_struct(super), ary);
1799 rb_vm_register_global_object(klass);
1808 int i = struct_hash_aset(key, val, args,
true);
1809 if (i >= 0 && !args->found[i]) {
1810 args->found[i] =
true;
1811 args->missing_count--;
1827#define rb_data_s_members_m rb_struct_s_members_m
1881rb_data_initialize_m(
int argc,
const VALUE *argv,
VALUE self)
1883 rb_struct_modify(self);
1884 rb_len_t num_members = RSTRUCT_LEN_RAW(self);
1887 if (num_members > 0) {
1894 rb_error_arity(argc, 0, 0);
1897 VALUE found_buffer = 0;
1899 if (num_members > 0) {
1900 found =
ALLOCV_N(
bool, found_buffer, num_members);
1901 MEMZERO(found,
bool, num_members);
1906 .missing_count = num_members,
1914 if (UNLIKELY(arg.missing_count > 0)) {
1918 for (
rb_len_t i = 0; i < num_members; i++) {
1922 rb_exc_raise(rb_keyword_error_new(
"missing", missing));
1926 if (UNLIKELY(arg.unknown_keywords)) {
1927 rb_exc_raise(rb_keyword_error_new(
"unknown", arg.unknown_keywords));
1937 copy = rb_struct_init_copy(copy, s);
1973rb_data_with(
int argc,
const VALUE *argv,
VALUE self)
1977 if (
NIL_P(kwargs)) {
1981 VALUE h = rb_struct_to_h(self);
1982 rb_hash_update_by(h, kwargs, 0);
2006rb_data_inspect(
VALUE s)
2032#define rb_data_equal rb_struct_equal
2052#define rb_data_eql rb_struct_eql
2076#define rb_data_hash rb_struct_hash
2106#define rb_data_to_h rb_struct_to_h
2121#define rb_data_members_m rb_struct_members_m
2152#define rb_data_deconstruct rb_struct_to_a
2187 return deconstruct_keys(s, keys,
true);
2338 rb_cData = rb_define_class(
"Data",
rb_cObject);
2362 rb_define_method(rb_cData,
"deconstruct_keys", rb_data_deconstruct_keys, 1);
2371 id_members = rb_intern(
"__members__");
2372 id_back_members = rb_intern(
"__members_back__");
2373 id_keyword_init = rb_intern(
"__keyword_init__");
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
static void RB_OBJ_FREEZE(VALUE obj)
Freeze the given object if it is not frozen yet.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_class_new(VALUE super)
Creates a new, anonymous class.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Identical to rb_define_class_under(), except it takes the name in ID instead of C's string.
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
int rb_keyword_given_p(void)
Determines if the current method is given a keyword argument.
int rb_block_given_p(void)
Determines if the current method is given a block.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define OBJ_INIT_COPY(obj, orig)
Old name of RB_OBJ_INIT_COPY.
#define T_STRING
Old name of RUBY_T_STRING.
#define INT2FIX
Old name of RB_INT2FIX.
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
#define LEN2NUM
Old name of RB_LEN2NUM.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define ID2SYM
Old name of RB_ID2SYM.
#define T_STRUCT
Old name of RUBY_T_STRUCT.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define SYM2ID
Old name of RB_SYM2ID.
#define FIX2UINT
Old name of RB_FIX2UINT.
#define CLASS_OF
Old name of rb_class_of.
#define rb_ary_new4
Old name of rb_ary_new_from_values.
#define FIX2INT
Old name of RB_FIX2INT.
#define T_HASH
Old name of RUBY_T_HASH.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define NUM2LEN
Old name of RB_NUM2LEN.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_eTypeError
TypeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eIndexError
IndexError exception.
VALUE rb_class_superclass(VALUE klass)
Queries the parent of the given class.
VALUE rb_cObject
Object class.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_class_new_instance_kw(int argc, const VALUE *argv, VALUE klass, int kw_splat)
Identical to rb_class_new_instance(), except you can specify how to handle the last element of the gi...
VALUE rb_mEnumerable
Enumerable module.
VALUE rb_cStruct
Struct class.
VALUE rb_class_new_instance_pass_kw(int argc, const VALUE *argv, VALUE klass)
Identical to rb_class_new_instance(), except it passes the passed keywords if any to the #initialize ...
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
VALUE rb_enc_interned_str_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new_cstr(), except it returns a "f"string.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_entry(VALUE ary, rb_len_t off)
Queries an element of an array.
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_new_capa(rb_len_t capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
void rb_ary_store(VALUE ary, rb_len_t key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_hidden_new(rb_len_t capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
void rb_mem_clear(VALUE *buf, rb_len_t len)
Fills the memory region with a series of RUBY_Qnil.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
VALUE rb_get_values_at(VALUE obj, rb_len_t olen, int argc, const VALUE *argv, VALUE(*func)(VALUE obj, rb_len_t oidx))
This was a generalisation of Array#values_at, Struct#values_at, and MatchData#values_at.
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
#define rb_hash_end(h)
Just another name of st_hash_end.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...)
Identical to rb_struct_define_without_accessor(), except it defines the class under the specified nam...
VALUE rb_struct_define_under(VALUE space, const char *name,...)
Identical to rb_struct_define(), except it defines the class under the specified namespace instead of...
VALUE rb_struct_new(VALUE klass,...)
Creates an instance of the given struct.
VALUE rb_struct_initialize(VALUE self, VALUE values)
Mass-assigns a struct's fields.
VALUE rb_struct_define_without_accessor(const char *name, VALUE super, rb_alloc_func_t func,...)
Identical to rb_struct_define(), except it does not define accessor methods.
VALUE rb_struct_define(const char *name,...)
Defines a struct class.
VALUE rb_struct_alloc(VALUE klass, VALUE values)
Identical to rb_struct_new(), except it takes the field values as a Ruby array.
VALUE rb_data_define(VALUE super,...)
Defines an anonymous data class.
VALUE rb_struct_alloc_noinit(VALUE klass)
Allocates an instance of the given class.
VALUE rb_struct_s_members(VALUE klass)
Queries the list of the names of the fields of the given struct class.
VALUE rb_struct_members(VALUE self)
Queries the list of the names of the fields of the class of the given struct object.
VALUE rb_struct_getmember(VALUE self, ID key)
Identical to rb_struct_aref(), except it takes ID instead of VALUE.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_exec_recursive_paired(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE p, VALUE h)
Identical to rb_exec_recursive(), except it checks for the recursion on the ordered pair of { g,...
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_mod_remove_const(VALUE space, VALUE name)
Resembles Module#remove_const.
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
void rb_set_class_path_string(VALUE klass, VALUE space, VALUE name)
Identical to rb_set_class_path(), except it accepts the name as Ruby's string instead of C's.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
VALUE(* rb_alloc_func_t)(VALUE klass)
This is the type of functions that ruby calls when trying to allocate an object.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
rb_alloc_func_t rb_get_alloc_func(VALUE klass)
Queries the allocator function of a class.
VALUE rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
Identical to rb_obj_instance_eval(), except it evaluates within the context of module.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
VALUE rb_check_symbol(volatile VALUE *namep)
Identical to rb_check_id(), except it returns an instance of rb_cSymbol instead.
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
VALUE rb_to_symbol(VALUE name)
Identical to rb_intern_str(), except it generates a dynamic symbol if necessary.
ID rb_to_id(VALUE str)
Identical to rb_intern_str(), except it tries to convert the parameter object to an instance of rb_cS...
int off
Offset inside of ptr.
int len
Length of the buffer.
VALUE rb_yield_values(int n,...)
Identical to rb_yield(), except it takes variadic number of parameters and pass them to the block.
VALUE rb_yield(VALUE val)
Yields the block.
#define rb_len2int
Just another name of rb_len2int_inline.
#define MEMZERO(p, type, n)
Handy macro to erase a region of memory.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
#define RARRAY_LEN
Just another name of rb_array_len.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
static VALUE * RARRAY_PTR(VALUE ary)
Wild use of a C pointer.
#define RARRAY_AREF(a, i)
References an object in an array.
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define RBASIC(obj)
Convenient casting macro.
VALUE rb_str_to_str(VALUE obj)
Identical to rb_check_string_type(), except it raises exceptions in case of conversion failures.
VALUE rb_struct_aset(VALUE st, VALUE k, VALUE v)
Resembles Struct#[]=.
VALUE rb_struct_size(VALUE st)
Returns the number of struct members.
VALUE rb_struct_aref(VALUE st, VALUE k)
Resembles Struct#[].
#define InitVM(ext)
This macro is for internal use.
#define RB_PASS_KEYWORDS
Pass keywords, final argument must be a hash of keywords.
#define RTEST
This is an old name of RB_TEST.
VALUE extended
When an object slot is too small or too complex to store instance variables inline,...
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.