Ruby 4.1.0dev (2026-08-15 revision d17a0d008310e36d1e16f9614c7ca01fe38cf3d6)
internal.h (d17a0d008310e36d1e16f9614c7ca01fe38cf3d6)
1#ifndef RUBY_INTERNAL_H /*-*-C-*-vi:se ft=c:*/
2#define RUBY_INTERNAL_H 1
12#include "ruby/internal/config.h"
13
14#ifdef __cplusplus
15# error not for C++
16#endif
17
18#define LIKELY(x) RB_LIKELY(x)
19#define UNLIKELY(x) RB_UNLIKELY(x)
20
21#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
22#define roomof(x, y) (((x) + (y) - 1) / (y))
23#define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
24
25/* Prevent compiler from reordering access */
26#define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
27
28#define UNDEF_P RB_UNDEF_P
29#define NIL_OR_UNDEF_P RB_NIL_OR_UNDEF_P
30
31#include "ruby/ruby.h"
32
33/* Following macros were formerly defined in this header but moved to somewhere
34 * else. In order to detect them we undef here. */
35
36/* internal/array.h */
37#undef RARRAY_AREF
38
39/* internal/class.h */
40#undef RClass
41#undef RCLASS_SUPER
42
43/* internal/hash.h */
44#undef RHASH_IFNONE
45#undef RHASH_SIZE
46#undef RHASH_TBL
47#undef RHASH_EMPTY_P
48
49/* internal/struct.h */
50#undef RSTRUCT_LEN
51#undef RSTRUCT_PTR
52#undef RSTRUCT_SET
53#undef RSTRUCT_GET
54
55/* Also, we keep the following macros here. They are expected to be
56 * overridden in each headers. */
57
58/* internal/array.h */
59#define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
60
61/* internal/string.h */
62#define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
63
64/* internal/symbol.h */
65#define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
66
67
68/* MRI debug support */
69
70/* gc.c */
71void rb_obj_info_dump(VALUE obj);
72void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
73
74/* debug.c */
75
76RUBY_SYMBOL_EXPORT_BEGIN
77void ruby_debug_breakpoint(void);
78PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
79RUBY_SYMBOL_EXPORT_END
80
81// show obj data structure without any side-effect
82#define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
83
84// same as rp, but add message header
85#define rp_m(msg, obj) do { \
86 fputs((msg), stderr); \
87 rb_obj_info_dump((VALUE)(obj)); \
88} while (0)
89
90// `ruby_debug_breakpoint()` does nothing,
91// but breakpoint is set in run.gdb, so `make gdb` can stop here.
92#define bp() ruby_debug_breakpoint()
93
94#define RBOOL(v) ((v) ? Qtrue : Qfalse)
95#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
96
97#ifndef __MINGW32__
98#undef memcpy
99#define memcpy ruby_nonempty_memcpy
100#endif
101#endif /* RUBY_INTERNAL_H */
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40