diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-31 15:58:50 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-31 16:04:16 +0900 |
commit | b1aecef87364631b0001dd2aafc432931e19a98f (patch) | |
tree | 7132db2022addc42126a1992c312eb7566dd2df6 /internal.h | |
parent | ea42423908ed055f9039b1dce6e9a232a3b2dd90 (diff) | |
download | ruby-b1aecef87364631b0001dd2aafc432931e19a98f.tar.gz |
Use UNALIGNED_MEMBER_PTR
* internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR):
moved from eval_intern.h.
* compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries`
in `struct iseq_catch_table`.
* vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body`
in `rb_method_definition_t`.
Diffstat (limited to 'internal.h')
-rw-r--r-- | internal.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/internal.h b/internal.h index fcaffa26be..4312f8d442 100644 --- a/internal.h +++ b/internal.h @@ -2511,6 +2511,23 @@ rb_obj_builtin_type(VALUE obj) #define COMPILER_WARNING_PRAGMA(str) COMPILER_WARNING_PRAGMA_(str) #define COMPILER_WARNING_PRAGMA_(str) _Pragma(#str) +#if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \ + (defined(__clang__) || GCC_VERSION_SINCE(9, 0, 0)) +# define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \ + COMPILER_WARNING_PUSH; \ + COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \ + typeof(expr) unaligned_member_access_result = (expr); \ + COMPILER_WARNING_POP; \ + unaligned_member_access_result; \ +}) +#else +# define UNALIGNED_MEMBER_ACCESS(expr) expr +#endif +#define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem) + +#undef RB_OBJ_WRITE +#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ |