Ruby: internal.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

internal.h
Go to the documentation of this file.
1#ifndef RUBY_INTERNAL_H /*-*-C-*-vi:se ft=c:*/
2#define RUBY_INTERNAL_H 1
13#include "ruby/internal/config.h"
14
15#ifdef __cplusplus
16# error not for C++
17#endif
18
19#define LIKELY(x) RB_LIKELY(x)
20#define UNLIKELY(x) RB_UNLIKELY(x)
21
22#define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
23#define roomof(x, y) (((x) + (y) - 1) / (y))
24#define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
25
26/* Prevent compiler from reordering access */
27#define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
28
29#include "ruby/ruby.h"
30
31/* Following macros were formerly defined in this header but moved to somewhere
32 * else. In order to detect them we undef here. */
33
34/* internal/array.h */
35#undef RARRAY_AREF
36
37/* internal/class.h */
38#undef RClass
39#undef RCLASS_SUPER
40
41/* internal/gc.h */
42#undef NEWOBJ_OF
43#undef RB_NEWOBJ_OF
44#undef RB_OBJ_WRITE
45
46/* internal/hash.h */
47#undef RHASH_IFNONE
48#undef RHASH_SIZE
49#undef RHASH_TBL
50#undef RHASH_EMPTY_P
51
52/* internal/object.h */
53#undef ROBJECT_IV_INDEX_TBL
54
55/* internal/struct.h */
56#undef RSTRUCT_LEN
57#undef RSTRUCT_PTR
58#undef RSTRUCT_SET
59#undef RSTRUCT_GET
60
61/* Also, we keep the following macros here. They are expected to be
62 * overridden in each headers. */
63
64/* internal/array.h */
65#define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
66
67/* internal/io.h */
68#define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
69
70/* internal/string.h */
71#define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
72
73/* internal/symbol.h */
74#define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
75
76/* internal/vm.h */
77#define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
78#define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
79
80
81/* MRI debug support */
82
83/* gc.c */
84void rb_obj_info_dump(VALUE obj);
85void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
86
87/* debug.c */
88
89RUBY_SYMBOL_EXPORT_BEGIN
90void ruby_debug_breakpoint(void);
91 PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
92RUBY_SYMBOL_EXPORT_END
93
94// show obj data structure without any side-effect
95#define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
96
97// same as rp, but add message header
98#define rp_m(msg, obj) do { \
99 fprintf(stderr, "%s", (msg)); \
100 rb_obj_info_dump((VALUE)obj); \
101} while (0)
102
103// `ruby_debug_breakpoint()` does nothing,
104// but breakpoint is set in run.gdb, so `make gdb` can stop here.
105#define bp() ruby_debug_breakpoint()
106
107#endif /* RUBY_INTERNAL_H */
PRINTF_ARGS
#define PRINTF_ARGS(decl, string_index, first_to_check)
Definition: attributes.h:112
config.h
Thin wrapper to ruby/config.h.
ruby_debug_breakpoint
void ruby_debug_breakpoint(void)
Definition: debug.c:158
ruby_debug_printf
void ruby_debug_printf(const char *,...)
Definition: debug.c:108
rb_obj_info_dump_loc
void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func)
Definition: gc.c:12512
rb_obj_info_dump
void rb_obj_info_dump(VALUE obj)
Definition: gc.c:12505
ruby.h
file
Definition: gzappend.c:170
VALUE
unsigned long VALUE
Definition: value.h:38