diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c30b837b9d..6b856a1083 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7364,7 +7364,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (!upb_IsLittleEndian()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -7586,7 +7586,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (upb_IsLittleEndian()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -7910,7 +7910,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -8637,12 +8637,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -8693,18 +8693,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (tag || !upb_IsLittleEndian()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, elem_size); } @@ -9059,7 +9059,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 0d3b3539b4..09232c3e6d 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -4104,8 +4104,8 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ -#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ +#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ // Must be last. @@ -4173,6 +4173,7 @@ TAGBYTES(o) TAGBYTES(r) #undef F +#undef UTF8 #undef TAGBYTES /* sub-message fields *********************************************************/ @@ -4195,9 +4196,9 @@ TAGBYTES(s) TAGBYTES(o) TAGBYTES(r) -#undef TAGBYTES -#undef SIZES #undef F +#undef SIZES +#undef TAGBYTES #undef UPB_PARSE_PARAMS @@ -4206,7 +4207,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -12942,6 +12943,44 @@ void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); #endif /* UPB_HASH_INT_TABLE_H_ */ +#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ +#define UPB_BASE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool upb_IsLittleEndian(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { + if (upb_IsLittleEndian()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { + if (upb_IsLittleEndian()) return val; + + const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; + const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); + return hi | lo; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ + #ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ #define UPB_WIRE_INTERNAL_CONSTANTS_H_ @@ -13078,43 +13117,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} - -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ - #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ @@ -13262,7 +13264,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + uval = upb_BigEndian32(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13275,7 +13277,7 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + uval = upb_BigEndian64(uval); memcpy(val, &uval, 8); return ptr + 8; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 87f95d0ab1..0b5f52e154 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6880,7 +6880,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (!upb_IsLittleEndian()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -7102,7 +7102,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (upb_IsLittleEndian()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -7426,7 +7426,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -8153,12 +8153,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -8209,18 +8209,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (tag || !upb_IsLittleEndian()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, elem_size); } @@ -8575,7 +8575,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index dfa9ffe1bc..302e9c2937 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -4106,8 +4106,8 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ -#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ +#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ // Must be last. @@ -4175,6 +4175,7 @@ TAGBYTES(o) TAGBYTES(r) #undef F +#undef UTF8 #undef TAGBYTES /* sub-message fields *********************************************************/ @@ -4197,9 +4198,9 @@ TAGBYTES(s) TAGBYTES(o) TAGBYTES(r) -#undef TAGBYTES -#undef SIZES #undef F +#undef SIZES +#undef TAGBYTES #undef UPB_PARSE_PARAMS @@ -4208,7 +4209,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -12714,6 +12715,44 @@ void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); #endif /* UPB_HASH_INT_TABLE_H_ */ +#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ +#define UPB_BASE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool upb_IsLittleEndian(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { + if (upb_IsLittleEndian()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { + if (upb_IsLittleEndian()) return val; + + const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; + const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); + return hi | lo; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ + #ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ #define UPB_WIRE_INTERNAL_CONSTANTS_H_ @@ -12850,43 +12889,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} - -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ - #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ @@ -13034,7 +13036,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + uval = upb_BigEndian32(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13047,7 +13049,7 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + uval = upb_BigEndian64(uval); memcpy(val, &uval, 8); return ptr + 8; }