* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / internal.h
blob00a8295295984bbe98b5163e4957bc63cbf8bccc
1 #ifndef RUBY_INTERNAL_H /*-*-C-*-vi:se ft=c:*/
2 #define RUBY_INTERNAL_H 1
3 /**
4 * @author $Author$
5 * @date Tue May 17 11:42:20 JST 2011
6 * @copyright Copyright (C) 2011 Yukihiro Matsumoto
7 * @copyright This file is a part of the programming language Ruby.
8 * Permission is hereby granted, to either redistribute and/or
9 * modify this file, provided that the conditions mentioned in the
10 * file COPYING are met. Consult the file for details.
12 #include "ruby/internal/config.h"
14 #ifdef __cplusplus
15 # error not for C++
16 #endif
18 #define LIKELY(x) RB_LIKELY(x)
19 #define UNLIKELY(x) RB_UNLIKELY(x)
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))
25 /* Prevent compiler from reordering access */
26 #define ACCESS_ONCE(type,x) (*((volatile type *)&(x)))
28 #include "ruby/ruby.h"
30 /* Following macros were formerly defined in this header but moved to somewhere
31 * else. In order to detect them we undef here. */
33 /* internal/array.h */
34 #undef RARRAY_AREF
36 /* internal/class.h */
37 #undef RClass
38 #undef RCLASS_SUPER
40 /* internal/gc.h */
41 #undef NEWOBJ_OF
42 #undef RB_NEWOBJ_OF
43 #undef RB_OBJ_WRITE
45 /* internal/hash.h */
46 #undef RHASH_IFNONE
47 #undef RHASH_SIZE
48 #undef RHASH_TBL
49 #undef RHASH_EMPTY_P
51 /* internal/object.h */
52 #undef ROBJECT_IV_INDEX_TBL
54 /* internal/struct.h */
55 #undef RSTRUCT_LEN
56 #undef RSTRUCT_PTR
57 #undef RSTRUCT_SET
58 #undef RSTRUCT_GET
60 /* Also, we keep the following macros here. They are expected to be
61 * overridden in each headers. */
63 /* internal/array.h */
64 #define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
66 /* internal/io.h */
67 #define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
69 /* internal/string.h */
70 #define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
72 /* internal/symbol.h */
73 #define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
75 /* internal/vm.h */
76 #define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
77 #define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
80 /* MRI debug support */
82 /* gc.c */
83 void rb_obj_info_dump(VALUE obj);
84 void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
86 /* debug.c */
88 RUBY_SYMBOL_EXPORT_BEGIN
89 void ruby_debug_breakpoint(void);
90 PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
91 RUBY_SYMBOL_EXPORT_END
93 // show obj data structure without any side-effect
94 #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
96 // same as rp, but add message header
97 #define rp_m(msg, obj) do { \
98 fputs((msg), stderr); \
99 rb_obj_info_dump((VALUE)(obj)); \
100 } while (0)
102 // `ruby_debug_breakpoint()` does nothing,
103 // but breakpoint is set in run.gdb, so `make gdb` can stop here.
104 #define bp() ruby_debug_breakpoint()
106 #define RBOOL(v) ((v) ? Qtrue : Qfalse)
107 #define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
109 #endif /* RUBY_INTERNAL_H */