Ensured that 32-bit targets use aligned pointers for 8-byte fields.

On 32-bit targets (including WASM), the base message pointer was aligned to 4 instead of 8, causing reads to 8-byte fields to fail, since TypedArray does not support unaligned reads.

The pointer was 4-byte aligned because upb adds the size of its "internal" pointer before returning the `upb_Message*`.  We should probably stop doing this, and instead have the MiniTable offsets reflect their full and true offset from the pointer returned by `malloc()`.

PiperOrigin-RevId: 552486609
pull/13675/head^2
Joshua Haberman 2 years ago committed by Copybara-Service
parent 1cd9076541
commit 7bde72661c
  1. 8
      upb/message/internal.h

@ -86,7 +86,13 @@ typedef struct {
} upb_Message_InternalData;
typedef struct {
upb_Message_InternalData* internal;
union {
upb_Message_InternalData* internal;
// Force 8-byte alignment, since the data members may contain members that
// require 8-byte alignment.
double d;
};
/* Message data follows. */
} upb_Message_Internal;

Loading…
Cancel
Save