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"
21#include "transient_heap.h"
28 AREF_HASH_THRESHOLD = 10
36static ID id_members, id_back_members, id_keyword_init;
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);
75 if (!RB_TYPE_P(members,
T_ARRAY)) {
94struct_member_pos_ideal(
VALUE name,
long mask)
97 return (
SYM2ID(name) >> (ID_SCOPE_SHIFT - 1)) & mask;
101struct_member_pos_probe(
long prev,
long mask)
104 return (prev * AREF_HASH_UNIT + 2) & mask;
111 const long members_length =
RARRAY_LEN(members);
113 if (members_length <= AREF_HASH_THRESHOLD) {
117 long i, j, mask = 64;
120 while (mask < members_length * AREF_HASH_UNIT) mask *= 2;
122 back = rb_ary_hidden_new(mask + 1);
123 rb_ary_store(back, mask,
INT2FIX(members_length));
126 for (i=0; i < members_length; i++) {
129 j = struct_member_pos_ideal(name, mask);
133 rb_ary_store(back, j, name);
134 rb_ary_store(back, j + 1,
INT2FIX(i));
137 j = struct_member_pos_probe(j, mask);
154 if (UNLIKELY(
NIL_P(back))) {
157 if (UNLIKELY(!RB_TYPE_P(back,
T_ARRAY))) {
163 if (mask <= AREF_HASH_THRESHOLD) {
164 if (UNLIKELY(RSTRUCT_LEN(s) != mask)) {
166 "struct size differs (%ld required %ld given)",
167 mask, RSTRUCT_LEN(s));
169 for (j = 0; j < mask; j++) {
182 j = struct_member_pos_ideal(name, mask);
191 j = struct_member_pos_probe(j, mask);
207rb_struct_s_members_m(
VALUE klass)
211 return rb_ary_dup(members);
227rb_struct_members_m(
VALUE obj)
236 int i = struct_member_pos(obj, slot);
238 return RSTRUCT_GET(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)
257 rb_make_metaclass(nstr,
RBASIC(klass)->klass);
268 if (!rb_is_const_name(name)) {
269 rb_name_err_raise(
"identifier %1$s needs to be constant",
274 rb_warn(
"redefining constant %"PRIsVALUE
"::%"PRIsVALUE, super, name);
280NORETURN(
static void invalid_struct_pos(
VALUE s,
VALUE idx));
285 rb_add_method_optimized(nstr,
SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_AREF,
FIX2UINT(off), METHOD_VISI_PUBLIC);
291 rb_add_method_optimized(nstr,
SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_ASET,
FIX2UINT(off), METHOD_VISI_PUBLIC);
295rb_struct_s_inspect(
VALUE klass)
298 if (
RTEST(rb_struct_s_keyword_init(klass))) {
305rb_data_s_new(
int argc,
const VALUE *argv,
VALUE klass)
308 if (argc > 1 || !RB_TYPE_P(argv[0],
T_HASH)) {
309 rb_error_arity(argc, 0, 0);
314 VALUE members = struct_ivar_get(klass, id_members);
315 int num_members = RARRAY_LENINT(members);
317 rb_check_arity(argc, 0, num_members);
318 VALUE arg_hash = rb_hash_new_with_size(argc);
319 for (
long i=0; i<argc; i++) {
320 VALUE k = rb_ary_entry(members, i), v = argv[i];
321 rb_hash_aset(arg_hash, k, v);
345rb_struct_s_keyword_init_p(
VALUE obj)
350#define rb_struct_s_keyword_init_p rb_struct_s_keyword_init
357 members = struct_set_members(nstr, members);
367 for (i=0; i< len; i++) {
372 define_aref_method(nstr, sym, off);
384 members = struct_set_members(subclass, members);
395 for (i=0; i< len; i++) {
399 define_aref_method(subclass, sym, off);
408 return struct_alloc(klass);
412struct_make_members_list(va_list ar)
415 VALUE ary, list = rb_ident_hash_new();
416 st_table *tbl = RHASH_TBL_RAW(list);
418 RBASIC_CLEAR_CLASS(list);
420 while ((mem = va_arg(ar,
char*)) != 0) {
421 VALUE sym = rb_sym_intern_ascii_cstr(mem);
422 if (st_insert(tbl, sym,
Qtrue)) {
426 ary = rb_hash_keys(list);
428 RBASIC_CLEAR_CLASS(ary);
447 klass = anonymous_struct(super);
450 struct_set_members(klass, members);
469 members = struct_make_members_list(ar);
472 return struct_define_without_accessor(outer, class_name, super, alloc, members);
482 members = struct_make_members_list(ar);
485 return struct_define_without_accessor(0, class_name, super, alloc, members);
495 ary = struct_make_members_list(ar);
500 return setup_struct(st, ary);
510 ary = struct_make_members_list(ar);
643rb_struct_s_def(
int argc,
VALUE *argv,
VALUE klass)
651 argc = rb_scan_args(argc, argv,
"1*:", NULL, NULL, &opt);
662 static ID keyword_ids[1];
664 if (!keyword_ids[0]) {
665 keyword_ids[0] = rb_intern(
"keyword_init");
668 if (UNDEF_P(keyword_init)) {
671 else if (
RTEST(keyword_init)) {
672 keyword_init =
Qtrue;
676 rest = rb_ident_hash_new();
677 RBASIC_CLEAR_CLASS(rest);
679 tbl = RHASH_TBL_RAW(rest);
680 for (i=0; i<argc; i++) {
682 if (rb_is_attrset_sym(mem)) {
685 if (st_insert(tbl, mem,
Qtrue)) {
689 rest = rb_hash_keys(rest);
691 RBASIC_CLEAR_CLASS(rest);
694 st = anonymous_struct(klass);
697 st = new_struct(name, klass);
699 setup_struct(st, rest);
709num_members(
VALUE klass)
712 members = struct_ivar_get(klass, id_members);
713 if (!RB_TYPE_P(members,
T_ARRAY)) {
724 VALUE unknown_keywords;
727static int rb_struct_pos(
VALUE s,
VALUE *name);
733 int i = rb_struct_pos(args->self, &key);
735 if (
NIL_P(args->unknown_keywords)) {
736 args->unknown_keywords = rb_ary_new();
738 rb_ary_push(args->unknown_keywords, key);
741 rb_struct_modify(args->self);
742 RSTRUCT_SET(args->self, i, val);
748rb_struct_initialize_m(
int argc,
const VALUE *argv,
VALUE self)
751 rb_struct_modify(self);
752 long n = num_members(klass);
754 rb_mem_clear((
VALUE *)RSTRUCT_CONST_PTR(self), n);
758 bool keyword_init =
false;
759 switch (rb_struct_s_keyword_init(klass)) {
761 if (argc > 1 || !RB_TYPE_P(argv[0],
T_HASH)) {
762 rb_error_arity(argc, 0, 0);
769 if (argc > 1 || !RB_TYPE_P(argv[0],
T_HASH)) {
777 rb_mem_clear((
VALUE *)RSTRUCT_CONST_PTR(self), n);
779 arg.unknown_keywords =
Qnil;
781 if (arg.unknown_keywords !=
Qnil) {
783 RSTRING_PTR(rb_ary_join(arg.unknown_keywords,
rb_str_new2(
", "))));
790 for (
long i=0; i<argc; i++) {
791 RSTRUCT_SET(self, i, argv[i]);
794 rb_mem_clear((
VALUE *)RSTRUCT_CONST_PTR(self)+argc, n-argc);
803 rb_struct_initialize_m(RARRAY_LENINT(values),
RARRAY_CONST_PTR(values), self);
810struct_heap_alloc(
VALUE st,
size_t len)
815 RSTRUCT_TRANSIENT_SET(st);
819 RSTRUCT_TRANSIENT_UNSET(st);
824#if USE_TRANSIENT_HEAP
826rb_struct_transient_heap_evacuate(
VALUE obj,
int promote)
828 if (RSTRUCT_TRANSIENT_P(obj)) {
829 const VALUE *old_ptr = rb_struct_const_heap_ptr(obj);
831 long len = RSTRUCT_LEN(obj);
838 new_ptr = struct_heap_alloc(obj, len);
841 RSTRUCT(obj)->as.heap.ptr = new_ptr;
847struct_alloc(
VALUE klass)
852 n = num_members(klass);
854 if (0 < n && n <= RSTRUCT_EMBED_LEN_MAX) {
855 RBASIC(st)->flags &= ~RSTRUCT_EMBED_LEN_MASK;
856 RBASIC(st)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
857 rb_mem_clear((
VALUE *)st->as.ary, n);
860 st->as.heap.ptr = struct_heap_alloc((
VALUE)st, n);
861 rb_mem_clear((
VALUE *)st->as.heap.ptr, n);
877 VALUE tmpargs[16], *mem = tmpargs;
882 if (size > numberof(tmpargs)) {
883 tmpargs[0] = rb_ary_hidden_new(size);
884 mem = RARRAY_PTR(tmpargs[0]);
886 va_start(args, klass);
887 for (i=0; i<size; i++) {
888 mem[i] = va_arg(args,
VALUE);
924rb_struct_each(
VALUE s)
929 for (i=0; i<RSTRUCT_LEN(s); i++) {
959rb_struct_each_pair(
VALUE s)
966 if (rb_block_pair_yield_optimizable()) {
967 for (i=0; i<RSTRUCT_LEN(s); i++) {
968 VALUE key = rb_ary_entry(members, i);
969 VALUE value = RSTRUCT_GET(s, i);
970 rb_yield_values(2, key, value);
974 for (i=0; i<RSTRUCT_LEN(s); i++) {
975 VALUE key = rb_ary_entry(members, i);
976 VALUE value = RSTRUCT_GET(s, i);
984inspect_struct(
VALUE s,
VALUE prefix,
int recur)
990 char first = RSTRING_PTR(cname)[0];
992 if (recur || first !=
'#') {
1000 len = RSTRUCT_LEN(s);
1002 for (i=0; i<len; i++) {
1009 else if (first !=
'#') {
1043rb_struct_inspect(
VALUE s)
1064rb_struct_to_a(
VALUE s)
1066 return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_CONST_PTR(s));
1093rb_struct_to_h(
VALUE s)
1095 VALUE h = rb_hash_new_with_size(RSTRUCT_LEN(s));
1100 for (i=0; i<RSTRUCT_LEN(s); i++) {
1101 VALUE k = rb_ary_entry(members, i), v = RSTRUCT_GET(s, i);
1103 rb_hash_set_pair(h, rb_yield_values(2, k, v));
1105 rb_hash_aset(h, k, v);
1128rb_struct_deconstruct_keys(
VALUE s,
VALUE keys)
1134 return rb_struct_to_h(s);
1136 if (UNLIKELY(!RB_TYPE_P(keys,
T_ARRAY))) {
1138 "wrong argument type %"PRIsVALUE
" (expected Array or nil)",
1143 return rb_hash_new_with_size(0);
1148 int i = rb_struct_pos(s, &key);
1152 rb_hash_aset(h, key, RSTRUCT_GET(s, i));
1164 if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
1168 for (i=0, len=RSTRUCT_LEN(copy); i<len; i++) {
1169 RSTRUCT_SET(copy, i, RSTRUCT_GET(s, i));
1182 return struct_member_pos(s, idx);
1184 else if (RB_TYPE_P(idx,
T_STRING)) {
1186 if (
NIL_P(idx))
return -1;
1187 return struct_member_pos(s, idx);
1192 len = RSTRUCT_LEN(s);
1200 else if (len <= i) {
1212 long i =
FIX2INT(idx), len = RSTRUCT_LEN(s);
1223 rb_name_err_raise(
"no member '%1$s' in struct", s, idx);
1256 int i = rb_struct_pos(s, &idx);
1257 if (i < 0) invalid_struct_pos(s, idx);
1258 return RSTRUCT_GET(s, i);
1294 int i = rb_struct_pos(s, &idx);
1295 if (i < 0) invalid_struct_pos(s, idx);
1296 rb_struct_modify(s);
1297 RSTRUCT_SET(s, i, val);
1307 return rb_struct_lookup_default(s, idx,
Qnil);
1313 int i = rb_struct_pos(s, &idx);
1314 if (i < 0)
return notfound;
1315 return RSTRUCT_GET(s, i);
1319struct_entry(
VALUE s,
long n)
1360rb_struct_values_at(
int argc,
VALUE *argv,
VALUE s)
1362 return rb_get_values_at(s, RSTRUCT_LEN(s), argc, argv, struct_entry);
1386rb_struct_select(
int argc,
VALUE *argv,
VALUE s)
1391 rb_check_arity(argc, 0, 0);
1393 result = rb_ary_new();
1394 for (i = 0; i < RSTRUCT_LEN(s); i++) {
1396 rb_ary_push(result, RSTRUCT_GET(s, i));
1408 if (recur)
return Qtrue;
1409 len = RSTRUCT_LEN(s);
1410 for (i=0; i<len; i++) {
1411 if (!
rb_equal(RSTRUCT_GET(s, i), RSTRUCT_GET(s2, i)))
return Qfalse;
1440 if (s == s2)
return Qtrue;
1443 if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
1444 rb_bug(
"inconsistent struct");
1470rb_struct_hash(
VALUE s)
1477 len = RSTRUCT_LEN(s);
1478 for (i = 0; i < len; i++) {
1479 n = rb_hash(RSTRUCT_GET(s, i));
1491 if (recur)
return Qtrue;
1492 len = RSTRUCT_LEN(s);
1493 for (i=0; i<len; i++) {
1494 if (!
rb_eql(RSTRUCT_GET(s, i), RSTRUCT_GET(s2, i)))
return Qfalse;
1521 if (s == s2)
return Qtrue;
1524 if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
1525 rb_bug(
"inconsistent struct");
1583rb_struct_dig(
int argc,
VALUE *argv,
VALUE self)
1586 self = rb_struct_lookup(self, *argv);
1587 if (!--argc)
return self;
1589 return rb_obj_dig(argc, argv, self,
Qnil);
1710rb_data_s_def(
int argc,
VALUE *argv,
VALUE klass)
1717 rest = rb_ident_hash_new();
1718 RBASIC_CLEAR_CLASS(rest);
1720 tbl = RHASH_TBL_RAW(rest);
1721 for (i=0; i<argc; i++) {
1723 if (rb_is_attrset_sym(mem)) {
1726 if (st_insert(tbl, mem,
Qtrue)) {
1730 rest = rb_hash_keys(rest);
1732 RBASIC_CLEAR_CLASS(rest);
1734 data_class = anonymous_struct(klass);
1735 setup_data(data_class, rest);
1754#define rb_data_s_members_m rb_struct_s_members_m
1807rb_data_initialize_m(
int argc,
const VALUE *argv,
VALUE self)
1810 rb_struct_modify(self);
1811 VALUE members = struct_ivar_get(klass, id_members);
1815 if (num_members > 0) {
1816 rb_exc_raise(rb_keyword_error_new(
"missing", members));
1820 if (argc > 1 || !RB_TYPE_P(argv[0],
T_HASH)) {
1821 rb_error_arity(argc, 0, 0);
1825 VALUE missing = rb_ary_diff(members, rb_hash_keys(argv[0]));
1826 rb_exc_raise(rb_keyword_error_new(
"missing", missing));
1830 rb_mem_clear((
VALUE *)RSTRUCT_CONST_PTR(self), num_members);
1832 arg.unknown_keywords =
Qnil;
1834 if (arg.unknown_keywords !=
Qnil) {
1835 rb_exc_raise(rb_keyword_error_new(
"unknown", arg.unknown_keywords));
1845 copy = rb_struct_init_copy(copy, s);
1846 RB_OBJ_FREEZE_RAW(copy);
1881rb_data_with(
int argc,
const VALUE *argv,
VALUE self)
1884 rb_scan_args(argc, argv,
"0:", &kwargs);
1885 if (
NIL_P(kwargs)) {
1890 rb_struct_init_copy(copy, self);
1894 arg.unknown_keywords =
Qnil;
1898 RB_OBJ_FREEZE_RAW(copy);
1900 if (arg.unknown_keywords !=
Qnil) {
1901 rb_exc_raise(rb_keyword_error_new(
"unknown", arg.unknown_keywords));
1927rb_data_inspect(
VALUE s)
1953#define rb_data_equal rb_struct_equal
1973#define rb_data_eql rb_struct_eql
1997#define rb_data_hash rb_struct_hash
2027#define rb_data_to_h rb_struct_to_h
2042#define rb_data_members_m rb_struct_members_m
2073#define rb_data_deconstruct rb_struct_to_a
2105#define rb_data_deconstruct_keys rb_struct_deconstruct_keys
2279 rb_define_method(rb_cData,
"deconstruct_keys", rb_data_deconstruct_keys, 1);
2288 id_members = rb_intern(
"__members__");
2289 id_back_members = rb_intern(
"__members_back__");
2290 id_keyword_init = rb_intern(
"__keyword_init__");
#define RUBY_ASSERT(expr)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level 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_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
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_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 NEWOBJ_OF
Old name of RB_NEWOBJ_OF.
#define FL_UNSET_RAW
Old name of RB_FL_UNSET_RAW.
#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 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_RAW
Old name of RB_OBJ_FREEZE_RAW.
#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 LONG2FIX
Old name of RB_INT2FIX.
#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 LONG2NUM
Old name of RB_LONG2NUM.
#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 FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define OBJ_WB_UNPROTECT
Old name of RB_OBJ_WB_UNPROTECT.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_eTypeError
TypeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_eIndexError
IndexError exception.
VALUE rb_class_superclass(VALUE klass)
Queries the parent of the given 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 ...
int rb_eql(VALUE lhs, VALUE rhs)
Checks for equality of the passed objects, in terms of Object#eql?.
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_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
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.
Defines RBIMPL_HAS_BUILTIN.
#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().
#define rb_check_frozen
Just another name of rb_check_frozen.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
ID rb_id_attrset(ID id)
Calculates an ID of attribute writer.
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_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_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
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.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
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.
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_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(), except it takes an instance of rb_cString.
VALUE rb_yield(VALUE val)
Yields the block.
#define rb_long2int
Just another name of rb_long2int_inline.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#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.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define RBASIC(obj)
Convenient casting macro.
#define RGENGC_WB_PROTECTED_STRUCT
This is a compile-time flag to enable/disable write barrier for struct RStruct.
#define RHASH_SIZE(h)
Queries the size of the hash.
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 should be a hash of keywords.
#define RTEST
This is an old name of RB_TEST.
uintptr_t VALUE
Type that represents a Ruby object.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.