Get rid of type-punning pointer casts
[ruby.git] / internal.h
blob4fb99d1c088a2565ae615a12d0545b8315fad0a1
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 #define UNDEF_P RB_UNDEF_P
29 #define NIL_OR_UNDEF_P RB_NIL_OR_UNDEF_P
31 #include "ruby/ruby.h"
33 /* Following macros were formerly defined in this header but moved to somewhere
34 * else. In order to detect them we undef here. */
36 /* internal/array.h */
37 #undef RARRAY_AREF
39 /* internal/class.h */
40 #undef RClass
41 #undef RCLASS_SUPER
43 /* internal/hash.h */
44 #undef RHASH_IFNONE
45 #undef RHASH_SIZE
46 #undef RHASH_TBL
47 #undef RHASH_EMPTY_P
49 /* internal/struct.h */
50 #undef RSTRUCT_LEN
51 #undef RSTRUCT_PTR
52 #undef RSTRUCT_SET
53 #undef RSTRUCT_GET
55 /* Also, we keep the following macros here. They are expected to be
56 * overridden in each headers. */
58 /* internal/array.h */
59 #define rb_ary_new_from_args(...) rb_nonexistent_symbol(__VA_ARGS__)
61 /* internal/io.h */
62 #define rb_io_fptr_finalize(...) rb_nonexistent_symbol(__VA_ARGS__)
64 /* internal/string.h */
65 #define rb_fstring_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
67 /* internal/symbol.h */
68 #define rb_sym_intern_ascii_cstr(...) rb_nonexistent_symbol(__VA_ARGS__)
70 /* internal/vm.h */
71 #define rb_funcallv(...) rb_nonexistent_symbol(__VA_ARGS__)
72 #define rb_method_basic_definition_p(...) rb_nonexistent_symbol(__VA_ARGS__)
75 /* MRI debug support */
77 /* gc.c */
78 void rb_obj_info_dump(VALUE obj);
79 void rb_obj_info_dump_loc(VALUE obj, const char *file, int line, const char *func);
81 /* debug.c */
83 RUBY_SYMBOL_EXPORT_BEGIN
84 void ruby_debug_breakpoint(void);
85 PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
86 RUBY_SYMBOL_EXPORT_END
88 // show obj data structure without any side-effect
89 #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING)
91 // same as rp, but add message header
92 #define rp_m(msg, obj) do { \
93 fputs((msg), stderr); \
94 rb_obj_info_dump((VALUE)(obj)); \
95 } while (0)
97 // `ruby_debug_breakpoint()` does nothing,
98 // but breakpoint is set in run.gdb, so `make gdb` can stop here.
99 #define bp() ruby_debug_breakpoint()
101 #define RBOOL(v) ((v) ? Qtrue : Qfalse)
102 #define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
104 #ifndef __MINGW32__
105 #undef memcpy
106 #define memcpy ruby_nonempty_memcpy
107 #endif
108 #endif /* RUBY_INTERNAL_H */