mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Avoid C++ strict aliasing warning.
Based on code proposed by @dearblue to avoid the warning: `dereferencing type-punned pointer will break strict-aliasing rules`.
This commit is contained in:
@@ -33,9 +33,7 @@ struct RArray {
|
|||||||
} aux;
|
} aux;
|
||||||
mrb_value *ptr;
|
mrb_value *ptr;
|
||||||
} heap;
|
} heap;
|
||||||
#if defined(__cplusplus)
|
void *ary[3];
|
||||||
mrb_value ary[MRB_ARY_EMBED_LEN_MAX];
|
|
||||||
#endif
|
|
||||||
} as;
|
} as;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,11 +46,7 @@ struct RArray {
|
|||||||
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
|
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
|
||||||
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
|
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
|
||||||
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
|
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
|
||||||
#if defined(__cplusplus)
|
#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary))
|
||||||
#define ARY_EMBED_PTR(a) (a)->as.ary
|
|
||||||
#else
|
|
||||||
#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
|
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
|
||||||
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
|
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
|
||||||
|
|||||||
Reference in New Issue
Block a user