9#include "internal/bits.h"
10#include "internal/error.h"
11#include "internal/hash.h"
12#include "internal/proc.h"
13#include "internal/sanitizers.h"
14#include "internal/set_table.h"
15#include "internal/symbol.h"
16#include "internal/variable.h"
17#include "ruby_assert.h"
30#include "internal/gc.h"
36 union {
double d; st_index_t i;} u;
41static const uint64_t prime1 = ((uint64_t)0x2e0bb864 << 32) | 0xe9ea7df5;
42static const uint32_t prime2 = 0x830fcab9;
45mult_and_mix(uint64_t m1, uint64_t m2)
47#if defined HAVE_UINT128_T
48 uint128_t r = (uint128_t) m1 * (uint128_t) m2;
49 return (uint64_t) (r >> 64) ^ (uint64_t) r;
51 uint64_t hm1 = m1 >> 32, hm2 = m2 >> 32;
52 uint64_t lm1 = m1, lm2 = m2;
53 uint64_t v64_128 = hm1 * hm2;
54 uint64_t v32_96 = hm1 * lm2 + lm1 * hm2;
55 uint64_t v1_32 = lm1 * lm2;
57 return (v64_128 + (v32_96 >> 32)) ^ ((v32_96 << 32) + v1_32);
62key64_hash(uint64_t key, uint32_t seed)
64 return mult_and_mix(key + seed, prime1);
68#define set_index_hash(index) key64_hash(rb_hash_start(index), prime2)
71set_ident_hash(st_data_t n)
80 n ^= dbl_to_index(rb_float_value(n));
84 return (st_index_t)set_index_hash((st_index_t)n);
100static ID id_each_entry;
104static ID id_set_iter_lev;
106#define RSET_INITIALIZED FL_USER1
107#define RSET_LEV_MASK (FL_USER13 | FL_USER14 | FL_USER15 | \
108 FL_USER16 | FL_USER17 | FL_USER18 | FL_USER19)
109#define RSET_LEV_SHIFT (FL_USHIFT + 13)
110#define RSET_LEV_MAX 127
112#define SET_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(SET_DEBUG, expr, #expr)
114#define RSET_SIZE(set) set_table_size(RSET_TABLE(set))
115#define RSET_EMPTY(set) (RSET_SIZE(set) == 0)
116#define RSET_SIZE_NUM(set) SIZET2NUM(RSET_SIZE(set))
117#define RSET_IS_MEMBER(sobj, item) set_lookup(RSET_TABLE(set), (st_data_t)(item))
118#define RSET_COMPARE_BY_IDENTITY(set) (RSET_TABLE(set)->type == &identhash)
125mark_key(st_data_t key, st_data_t data)
127 rb_gc_mark_movable((
VALUE)key);
136 if (sobj->table.entries) set_foreach(&sobj->table, mark_key, 0);
142 free((&sobj->table)->bins);
143 free((&sobj->table)->entries);
150 set_free_embedded(sobj);
151 memset(&sobj->table, 0,
sizeof(sobj->table));
155set_size(
const void *ptr)
159 return (
unsigned long)set_memsize(&sobj->table) -
sizeof(sobj->table);
163set_foreach_replace(st_data_t key, st_data_t argp,
int error)
165 if (rb_gc_location((
VALUE)key) != (
VALUE)key) {
173set_replace_ref(st_data_t *key, st_data_t argp,
int existing)
175 if (rb_gc_location((
VALUE)*key) != (
VALUE)*key) {
176 *key = rb_gc_location((
VALUE)*key);
183set_update_references(
void *ptr)
186 set_foreach_with_replace(&sobj->table, set_foreach_replace, set_replace_ref, 0);
195 .dcompact = set_update_references,
197 .flags = RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE
209iter_lev_in_ivar(
VALUE set)
214 SET_ASSERT(lev >= 0);
215 return (
unsigned long)lev;
221iter_lev_in_ivar_set(
VALUE set,
unsigned long lev)
223 SET_ASSERT(lev >= RSET_LEV_MAX);
225 rb_ivar_set_internal(set, id_set_iter_lev,
LONG2FIX((
long)lev));
228static inline unsigned long
229iter_lev_in_flags(
VALUE set)
231 return (
unsigned long)((
RBASIC(set)->flags >> RSET_LEV_SHIFT) & RSET_LEV_MAX);
235iter_lev_in_flags_set(
VALUE set,
unsigned long lev)
237 SET_ASSERT(lev <= RSET_LEV_MAX);
238 RBASIC(set)->flags = ((
RBASIC(set)->flags & ~RSET_LEV_MASK) | ((
VALUE)lev << RSET_LEV_SHIFT));
242set_iterating_p(
VALUE set)
244 return iter_lev_in_flags(set) > 0;
248set_iter_lev_inc(
VALUE set)
250 unsigned long lev = iter_lev_in_flags(set);
251 if (lev == RSET_LEV_MAX) {
252 lev = iter_lev_in_ivar(set) + 1;
259 iter_lev_in_flags_set(set, lev);
260 if (lev < RSET_LEV_MAX)
return;
262 iter_lev_in_ivar_set(set, lev);
266set_iter_lev_dec(
VALUE set)
268 unsigned long lev = iter_lev_in_flags(set);
269 if (lev == RSET_LEV_MAX) {
270 lev = iter_lev_in_ivar(set);
271 if (lev > RSET_LEV_MAX) {
272 iter_lev_in_ivar_set(set, lev-1);
275 rb_attr_delete(set, id_set_iter_lev);
280 iter_lev_in_flags_set(set, lev - 1);
284set_foreach_ensure(
VALUE set)
286 set_iter_lev_dec(set);
294 set_foreach_func *func;
299set_iter_status_check(
int status)
301 if (status == ST_CONTINUE) {
309set_foreach_iter(st_data_t key, st_data_t argp,
int error)
313 if (error)
return ST_STOP;
316 int status = (*arg->func)((
VALUE)key, arg->arg);
318 if (RSET_TABLE(arg->set) != tbl) {
322 return set_iter_status_check(status);
326set_foreach_call(
VALUE arg)
330 ret = set_foreach_check(RSET_TABLE(set), set_foreach_iter,
331 (st_data_t)arg, (st_data_t)
Qundef);
339set_iter(
VALUE set, set_foreach_func *func,
VALUE farg)
349 set_foreach_call((
VALUE)&arg);
352 set_iter_lev_inc(set);
353 rb_ensure(set_foreach_call, (
VALUE)&arg, set_foreach_ensure, set);
357NORETURN(
static void no_new_item(
void));
361 rb_raise(
rb_eRuntimeError,
"can't add a new item into set during iteration");
365set_compact_after_delete(
VALUE set)
367 if (!set_iterating_p(set)) {
368 set_compact_table(RSET_TABLE(set));
376 key = rb_hash_key_str(key);
377 if (key_addr) *key_addr = key;
379 int ret = set_insert(tab, (st_data_t)key);
387 return set_table_insert_wb(RSET_TABLE(set), set, key, key_addr);
391set_alloc_with_size(
VALUE klass, st_index_t size)
397 set_init_table_with_size(&sobj->table, &objhash, size);
404set_s_alloc(
VALUE klass)
406 return set_alloc_with_size(klass, 0);
410set_s_create(
int argc,
VALUE *argv,
VALUE klass)
412 VALUE set = set_alloc_with_size(klass, argc);
416 for (i=0; i < argc; i++) {
417 set_table_insert_wb(table, set, argv[i], NULL);
427 rb_raise(rb_eArgError,
"value must be a set");
432enum_method_id(
VALUE other)
435 return id_each_entry;
441 rb_raise(rb_eArgError,
"value must be enumerable");
448 return RSET_SIZE_NUM(set);
455 set_insert_wb(set, element, &element);
463 set_insert_wb(set, element, &element);
486set_i_initialize(
int argc,
VALUE *argv,
VALUE set)
488 if (
RBASIC(set)->flags & RSET_INITIALIZED) {
491 RBASIC(set)->flags |= RSET_INITIALIZED;
496 if (argc > 0 && (other = argv[0]) !=
Qnil) {
503 if (block_given) key =
rb_yield(key);
504 set_table_insert_wb(into, set, key, NULL);
509 rb_block_given_p() ? set_initialize_with_block : set_initialize_without_block,
520 if (set == other)
return set;
522 if (set_iterating_p(set)) {
529 set_free_embedded(sobj);
530 set_copy(&sobj->table, RSET_TABLE(other));
531 rb_gc_writebarrier_remember(set);
537set_inspect_i(st_data_t key, st_data_t arg)
541 if (args[1] ==
Qtrue) {
559 str = rb_sprintf(
"%"PRIsVALUE
"[...]", klass_name);
563 str = rb_sprintf(
"%"PRIsVALUE
"[", klass_name);
565 set_iter(set, set_inspect_i, (st_data_t)args);
587set_i_inspect(
VALUE set)
593set_to_a_i(st_data_t key, st_data_t arg)
611 st_index_t size = RSET_SIZE(set);
614 if (size == 0)
return ary;
616 if (ST_DATA_COMPATIBLE_P(
VALUE)) {
618 size = set_keys(RSET_TABLE(set), ptr, size);
620 rb_gc_writebarrier_remember(ary);
621 rb_ary_set_len(ary, size);
624 set_iter(set, set_to_a_i, (st_data_t)ary);
650 rb_warn_deprecated(
"passing arguments to Set#to_set", NULL);
690 rb_check_frozen(set);
691 if (set_iterating_p(set)) {
692 if (!set_lookup(RSET_TABLE(set), (st_data_t)item)) {
697 set_insert_wb(set, item, NULL);
716 rb_check_frozen(set);
717 if (set_iterating_p(set)) {
718 if (!set_lookup(RSET_TABLE(set), (st_data_t)item)) {
724 return set_insert_wb(set, item, NULL) ?
Qnil : set;
738 rb_check_frozen(set);
739 if (set_delete(RSET_TABLE(set), (st_data_t *)&item)) {
740 set_compact_after_delete(set);
755 rb_check_frozen(set);
756 if (set_delete(RSET_TABLE(set), (st_data_t *)&item)) {
757 set_compact_after_delete(set);
764set_delete_if_i(st_data_t key, st_data_t dummy)
778set_i_delete_if(
VALUE set)
781 rb_check_frozen(set);
782 set_iter(set, set_delete_if_i, 0);
783 set_compact_after_delete(set);
796set_i_reject(
VALUE set)
799 rb_check_frozen(set);
802 size_t n = set_table_size(table);
803 set_iter(set, set_delete_if_i, 0);
805 if (n == set_table_size(table))
return Qnil;
807 set_compact_after_delete(set);
812set_classify_i(st_data_t key, st_data_t tmp)
815 VALUE hash = args[0];
817 VALUE set = rb_hash_lookup2(hash, hash_key,
Qundef);
819 set = set_s_alloc(args[1]);
820 rb_hash_aset(hash, hash_key, set);
846set_i_classify(
VALUE set)
850 args[0] = rb_hash_new();
852 set_iter(set, set_classify_i, (st_data_t)args);
858set_divide_union_find_root(
long *uf_parents,
long index,
long *tmp_array)
860 long root = uf_parents[index];
861 long update_size = 0;
862 while (root != index) {
863 tmp_array[update_size++] = index;
865 root = uf_parents[index];
867 for (
long j = 0; j < update_size; j++) {
868 long idx = tmp_array[j];
869 uf_parents[idx] = root;
875set_divide_union_find_merge(
long *uf_parents,
long i,
long j,
long *tmp_array)
877 long root_i = set_divide_union_find_root(uf_parents, i, tmp_array);
878 long root_j = set_divide_union_find_root(uf_parents, j, tmp_array);
879 if (root_i != root_j) uf_parents[root_j] = root_i;
883set_divide_arity2(
VALUE set)
886 long size, *uf_parents, *tmp_array;
888 VALUE items = set_i_to_a(set);
891 tmp_array =
ALLOCV_N(
long, tmp, size);
892 uf_parents =
ALLOCV_N(
long, uf, size);
893 for (
long i = 0; i < size; i++) {
896 for (
long i = 0; i < size - 1; i++) {
898 for (
long j = i + 1; j < size; j++) {
902 set_divide_union_find_merge(uf_parents, i, j, tmp_array);
906 VALUE final_set = set_s_create(0, 0, rb_cSet);
907 VALUE hash = rb_hash_new();
908 for (
long i = 0; i < size; i++) {
910 long root = set_divide_union_find_root(uf_parents, i, tmp_array);
913 set = set_s_create(0, 0, set_class);
914 rb_hash_aset(hash,
LONG2FIX(root), set);
915 set_i_add(final_set, set);
924static void set_merge_enum_into(
VALUE set,
VALUE arg);
950set_i_divide(
VALUE set)
954 if (rb_block_arity() == 2) {
955 return set_divide_arity2(set);
958 VALUE values = rb_hash_values(set_i_classify(set));
959 set = set_alloc_with_size(rb_cSet,
RARRAY_LEN(values));
960 set_merge_enum_into(set, values);
965set_clear_i(st_data_t key, st_data_t dummy)
981set_i_clear(
VALUE set)
983 rb_check_frozen(set);
984 if (RSET_SIZE(set) == 0)
return set;
985 if (set_iterating_p(set)) {
986 set_iter(set, set_clear_i, 0);
989 set_clear(RSET_TABLE(set));
990 set_compact_after_delete(set);
1002set_intersection_i(st_data_t key, st_data_t tmp)
1005 if (set_lookup(data->other, key)) {
1006 set_table_insert_wb(data->into, data->set, key, NULL);
1015 set_intersection_i((st_data_t)i, (st_data_t)data);
1034 set_table *ntable = RSET_TABLE(new_set);
1038 if (set_table_size(stable) >= set_table_size(otable)) {
1049 set_iter(set, set_intersection_i, (st_data_t)&data);
1057 rb_block_call(other, enum_method_id(other), 0, 0, set_intersection_block, (
VALUE)&data);
1090 return RBOOL(RSET_IS_MEMBER(set, item));
1099set_merge_i(st_data_t key, st_data_t data)
1102 set_table_insert_wb(args->into, args->set, key, NULL);
1109 VALUE element = key;
1110 set_insert_wb(set, element, &element);
1120 .into = RSET_TABLE(set)
1122 set_iter(arg, set_merge_i, (st_data_t)&args);
1128 set_table_insert_wb(into, set,
RARRAY_AREF(arg, i), NULL);
1147 rb_raise(rb_eArgError,
"no keywords accepted");
1150 if (set_iterating_p(set)) {
1154 rb_check_frozen(set);
1158 for (i=0; i < argc; i++) {
1159 set_merge_enum_into(set, argv[i]);
1168 rb_check_frozen(set);
1174 size_t size = set_table_size(old);
1176 set_table *
new = set_init_table_with_size(NULL,
type, size);
1181 set_iter(set, set_merge_i, (st_data_t)&args);
1182 set_free_embedded(sobj);
1183 memcpy(&sobj->table,
new,
sizeof(*
new));
1187 sobj->table.type =
type;
1200set_i_compare_by_identity(
VALUE set)
1202 if (RSET_COMPARE_BY_IDENTITY(set))
return set;
1204 if (set_iterating_p(set)) {
1208 return set_reset_table_with_type(set, &identhash);
1219set_i_compare_by_identity_p(
VALUE set)
1221 return RBOOL(RSET_COMPARE_BY_IDENTITY(set));
1231set_i_size(
VALUE set)
1233 return RSET_SIZE_NUM(set);
1243set_i_empty(
VALUE set)
1245 return RBOOL(RSET_EMPTY(set));
1249set_xor_i(st_data_t key, st_data_t data)
1254 if (set_table_insert_wb(table, set, element, &element)) {
1255 set_delete(table, &element);
1280 set_merge_enum_into(new_set, other);
1282 set_iter(set, set_xor_i, (st_data_t)new_set);
1300 set_merge_enum_into(set, other);
1305set_remove_i(st_data_t key, st_data_t from)
1307 set_delete((
struct set_table *)from, (st_data_t *)&key);
1314 rb_check_frozen(set);
1315 set_delete(RSET_TABLE(set), (st_data_t *)&key);
1323 set_iter(arg, set_remove_i, (st_data_t)RSET_TABLE(set));
1340 rb_check_frozen(set);
1341 set_remove_enum_from(set, other);
1358 return set_i_subtract(
rb_obj_dup(set), other);
1362set_each_i(st_data_t key, st_data_t dummy)
1378set_i_each(
VALUE set)
1381 set_iter(set, set_each_i, 0);
1386set_collect_i(st_data_t key, st_data_t data)
1401set_i_collect(
VALUE set)
1404 rb_check_frozen(set);
1407 set_iter(set, set_collect_i, (st_data_t)new_set);
1408 set_i_initialize_copy(set, new_set);
1414set_keep_if_i(st_data_t key, st_data_t into)
1431set_i_keep_if(
VALUE set)
1434 rb_check_frozen(set);
1436 set_iter(set, set_keep_if_i, (st_data_t)RSET_TABLE(set));
1450set_i_select(
VALUE set)
1453 rb_check_frozen(set);
1456 size_t n = set_table_size(table);
1457 set_iter(set, set_keep_if_i, (st_data_t)table);
1459 return (n == set_table_size(table)) ?
Qnil : set;
1476 rb_check_frozen(set);
1479 set_i_initialize_copy(set, other);
1482 if (set_iterating_p(set)) {
1487 enum_method_id(other);
1489 set_clear(RSET_TABLE(set));
1490 set_merge_enum_into(set, other);
1504set_i_reset(
VALUE set)
1506 if (set_iterating_p(set)) {
1510 return set_reset_table_with_type(set, RSET_TABLE(set)->
type);
1516set_flatten_merge_i(st_data_t item, st_data_t arg)
1519 VALUE set = args[0];
1521 VALUE e_id = rb_obj_id(item);
1522 VALUE hash = args[2];
1523 switch(rb_hash_aref(hash, e_id)) {
1527 rb_raise(rb_eArgError,
"tried to flatten recursive Set");
1532 rb_hash_aset(hash, e_id,
Qtrue);
1533 set_flatten_merge(set, item, hash);
1534 rb_hash_aset(hash, e_id,
Qfalse);
1537 set_i_add(set, item);
1545 VALUE args[3] = {set, from, hash};
1546 set_iter(from, set_flatten_merge_i, (st_data_t)args);
1557set_i_flatten(
VALUE set)
1560 set_flatten_merge(new_set, set, rb_hash_new());
1565set_contains_set_i(st_data_t item, st_data_t arg)
1568 *(
bool *)arg =
true;
1582set_i_flatten_bang(
VALUE set)
1584 bool contains_set =
false;
1585 set_iter(set, set_contains_set_i, (st_data_t)&contains_set);
1586 if (!contains_set)
return Qnil;
1587 rb_check_frozen(set);
1588 return set_i_replace(set, set_i_flatten(set));
1597set_le_i(st_data_t key, st_data_t arg)
1600 if (set_lookup(data->table, key))
return ST_CONTINUE;
1609 .table = RSET_TABLE(other),
1612 set_iter(set, set_le_i, (st_data_t)&data);
1626 if (RSET_SIZE(set) >= RSET_SIZE(other))
return Qfalse;
1627 return set_le(set, other);
1640 if (RSET_SIZE(set) > RSET_SIZE(other))
return Qfalse;
1641 return set_le(set, other);
1654 if (RSET_SIZE(set) <= RSET_SIZE(other))
return Qfalse;
1655 return set_le(other, set);
1668 if (RSET_SIZE(set) < RSET_SIZE(other))
return Qfalse;
1669 return set_le(other, set);
1673set_intersect_i(st_data_t key, st_data_t arg)
1676 if (set_lookup((
set_table *)args[0], key)) {
1699 size_t set_size = RSET_SIZE(set);
1700 size_t other_size = RSET_SIZE(other);
1705 if (set_size < other_size) {
1707 args[0] = (
VALUE)RSET_TABLE(other);
1711 args[0] = (
VALUE)RSET_TABLE(set);
1713 set_iter(iter_arg, set_intersect_i, (st_data_t)args);
1720 rb_raise(rb_eArgError,
"value must be enumerable");
1739 return RBOOL(!
RTEST(set_i_intersect(set, other)));
1754 size_t set_size = RSET_SIZE(set);
1755 size_t other_size = RSET_SIZE(other);
1757 if (set_size < other_size) {
1758 if (set_le(set, other) ==
Qtrue) {
1762 else if (set_size > other_size) {
1763 if (set_le(other, set) ==
Qtrue) {
1767 else if (set_le(set, other) ==
Qtrue) {
1781set_eql_i(st_data_t item, st_data_t arg)
1785 if (!set_lookup(RSET_TABLE(data->set), item)) {
1793set_recursive_eql(
VALUE set,
VALUE dt,
int recur)
1795 if (recur)
return Qtrue;
1797 data->result =
Qtrue;
1798 set_iter(set, set_eql_i, dt);
1799 return data->result;
1812 if (set == other)
return Qtrue;
1816 size_t ssize = set_table_size(stable);
1817 size_t osize = set_table_size(otable);
1819 if (ssize != osize)
return Qfalse;
1820 if (ssize == 0 && osize == 0)
return Qtrue;
1821 if (stable->type != otable->type)
return Qfalse;
1829set_hash_i(st_data_t item, st_data_t(arg))
1831 st_index_t *hval = (st_index_t *)arg;
1832 st_index_t ival = rb_hash(item);
1833 *hval ^= rb_st_hash(&ival,
sizeof(st_index_t), 0);
1844set_i_hash(
VALUE set)
1846 st_index_t size = RSET_SIZE(set);
1847 st_index_t hval = rb_st_hash_start(size);
1850 set_iter(set, set_hash_i, (
VALUE)&hval);
1852 hval = rb_st_hash_end(hval);
1858set_to_hash_i(st_data_t key, st_data_t arg)
1865set_i_to_h(
VALUE set)
1867 st_index_t size = RSET_SIZE(set);
1869 if (RSET_COMPARE_BY_IDENTITY(set)) {
1870 hash = rb_ident_hash_new_with_size(size);
1873 hash = rb_hash_new_with_size(size);
1875 rb_hash_set_default(hash,
Qfalse);
1877 if (size == 0)
return hash;
1879 set_iter(set, set_to_hash_i, (st_data_t)hash);
1884compat_dumper(
VALUE set)
1892set_i_from_hash_i(st_data_t key, st_data_t val, st_data_t set)
1905 if (rb_hash_compare_by_id_p(hash)) set_i_compare_by_identity(set);
1906 rb_hash_stlike_foreach(hash, set_i_from_hash_i, (st_data_t)set);
1913 return set_i_from_hash(self,
rb_ivar_get(a, id_i_hash));
2135 id_set_iter_lev = rb_make_internal_id();
2161 rb_define_method(rb_cSet,
"compare_by_identity", set_i_compare_by_identity, 0);
2162 rb_define_method(rb_cSet,
"compare_by_identity?", set_i_compare_by_identity_p, 0);
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
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_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias 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.
#define rb_str_buf_cat2
Old name of rb_usascii_str_new_cstr.
#define Qundef
Old name of RUBY_Qundef.
#define CLASS_OF
Old name of rb_class_of.
#define LONG2FIX
Old name of RB_INT2FIX.
#define T_HASH
Old name of RUBY_T_HASH.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define POSFIXABLE
Old name of RB_POSFIXABLE.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_mEnumerable
Enumerable module.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_dup(VALUE obj)
Duplicates the given object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_obj_is_instance_of(VALUE obj, VALUE klass)
Queries if the given object is a direct instance of the given class.
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.
VALUE rb_cString
String class.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
VALUE rb_str_export_to_enc(VALUE obj, rb_encoding *enc)
Identical to rb_str_export(), except it additionally takes an encoding.
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv_public(), except you can pass the passed block.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
VALUE rb_str_buf_cat_ascii(VALUE dst, const char *src)
Identical to rb_str_cat_cstr(), except it additionally assumes the source string be a NUL terminated ...
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_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
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.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_PTR_USE(ary, ptr_name, expr)
Declares a section of code where raw pointers are used.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
#define RTEST
This is an old name of RB_TEST.
This is the struct that holds necessary info for a struct.
const char * wrap_struct_name
Name of structs of this kind.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.