diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/bindings/lua/upb.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c index 2b05938..87b39e6 100644 --- a/upb/bindings/lua/upb.c +++ b/upb/bindings/lua/upb.c @@ -1341,10 +1341,21 @@ static size_t align_up(size_t val, size_t align) { return val % align == 0 ? val : val + align - (val % align); } -#define CHARPTR_AT(msg, ofs) ((char*)msg + sizeof(lupb_msg) + ofs) - /* If we always read/write as a consistent type to each value, this shouldn't - * violate aliasing. */ + * violate aliasing. + * + * Note that the slightly prettier option of: + * + * *(type*)(&msg->data[ofs]) + * + * ...is potentially more questionable wrt the C standard and aliasing. + * Does the expression &msg->data[ofs] "access the stored value"? If so, + * this would violate aliasing. So instead we use the expression: + * + * (char*)msg + sizeof(lupb_msg) + ofs + * + * ...which unambigiously is doing nothing but calculating a pointer address. */ +#define CHARPTR_AT(msg, ofs) ((char*)msg + sizeof(lupb_msg) + ofs) #define DEREF(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs) lupb_msg *lupb_msg_check(lua_State *L, int narg) { |