Ruby: internal.h Source File

Ruby 3.3.4p94 (2024-07-09 revision be1089c8ec5ba40e09b1553e36b3174bf4014d9d)

internal.h
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/gc.h */
44#undef NEWOBJ_OF
45#undef RB_NEWOBJ_OF
46
47/* internal/hash.h */
48#undef RHASH_IFNONE
49#undef RHASH_SIZE
50#undef RHASH_TBL
51#undef RHASH_EMPTY_P
52
53/* internal/struct.h */
54#undef RSTRUCT_LEN
55#undef RSTRUCT_PTR
56#undef RSTRUCT_SET
57#undef RSTRUCT_GET
58
59/* Also, we keep the following macros here. They are expected to be
60 * overridden in each headers. */
61
62/* internal/array.h */
63#define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
64
65/* internal/io.h */
66#define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
67
68/* internal/string.h */
69#define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
70
71/* internal/symbol.h */
72#define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
73
74/* internal/vm.h */
75#define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
76#define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
77
78
79/* MRI debug support */
80
81/* gc.c */
82void rb_obj_info_dump(VALUE obj);
83void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
84
85/* debug.c */
86
87RUBY_SYMBOL_EXPORT_BEGIN
88void ruby_debug_breakpoint(void);
89PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
90RUBY_SYMBOL_EXPORT_END
91
92// show obj data structure without any side-effect
93#define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
94
95// same as rp, but add message header
96#define rp_m(msg, obj) do { \
97 fputs((msg), stderr); \
98 rb_obj_info_dump((VALUE)(obj)); \
99} while (0)
100
101// `ruby_debug_breakpoint()` does nothing,
102// but breakpoint is set in run.gdb, so `make gdb` can stop here.
103#define bp() ruby_debug_breakpoint()
104
105#define RBOOL(v) ((v) ? Qtrue : Qfalse)
106#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
107
108#ifndef __MINGW32__
109#undef memcpy
110#define memcpy ruby_nonempty_memcpy
111#endif
112#endif /* RUBY_INTERNAL_H */
ruby.h
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40