From 33d1231ead8ffbeb97e6c97b9e9a06ace64abd65 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 6 Sep 2018 13:07:09 -0700 Subject: Added port_def.inc and port_undef.inc. --- upb/port_def.inc | 18 ++++++++++++++++++ upb/port_undef.inc | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 upb/port_def.inc create mode 100644 upb/port_undef.inc (limited to 'upb') diff --git a/upb/port_def.inc b/upb/port_def.inc new file mode 100644 index 0000000..33ff78c --- /dev/null +++ b/upb/port_def.inc @@ -0,0 +1,18 @@ + +#if UINTPTR_MAX == 0xffffffff +#define UPB_SIZE(size32, size64) size32 +#else +#define UPB_SIZE(size32, size64) size64 +#endif + +#define UPB_FIELD_AT(msg, fieldtype, offset) \ + *(fieldtype*)((const char*)(msg) + offset) + +#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \ + UPB_FIELD_AT(msg, int, case_offset) == case_val \ + ? UPB_FIELD_AT(msg, fieldtype, offset) \ + : default + +#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \ + UPB_FIELD_AT(msg, int, case_offset) = case_val; \ + UPB_FIELD_AT(msg, fieldtype, offset) = value; diff --git a/upb/port_undef.inc b/upb/port_undef.inc new file mode 100644 index 0000000..7db97ca --- /dev/null +++ b/upb/port_undef.inc @@ -0,0 +1,5 @@ + +#undef UPB_SIZE +#undef UPB_FIELD_AT +#undef UPB_READ_ONEOF +#undef UPB_WRITE_ONEOF -- cgit v1.2.3