From 5bded04d28ae3fbc29a358bcecdf9d823f90cf9d Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 25 Jan 2024 12:16:54 -0800 Subject: [PATCH] upb: add 'static' to UPB_FORCEINLINE() PiperOrigin-RevId: 601525709 --- upb/message/internal/accessors.h | 2 +- upb/port/def.inc | 6 +- upb/wire/decode.c | 103 +++++++++++++++---------------- upb/wire/encode.c | 4 +- upb/wire/eps_copy_input_stream.h | 6 +- upb/wire/internal/decode_fast.c | 54 ++++++++-------- upb/wire/internal/reader.h | 2 +- upb/wire/reader.h | 4 +- 8 files changed, 88 insertions(+), 93 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 1c15da54e1..dbfb2ed0ad 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -243,7 +243,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasExtension)( return UPB_PRIVATE(_upb_Message_Getext)(msg, ext) != NULL; } -static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( +UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/upb/port/def.inc b/upb/port/def.inc index 5d07592b07..c88ffdf3d8 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc @@ -117,17 +117,17 @@ Error, UINTPTR_MAX is undefined // Macros for function attributes on compilers that support them. #ifdef __GNUC__ -#define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) +#define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) static #define UPB_NOINLINE __attribute__((noinline)) #define UPB_NORETURN __attribute__((__noreturn__)) #define UPB_PRINTF(str, first_vararg) __attribute__((format (printf, str, first_vararg))) #elif defined(_MSC_VER) #define UPB_NOINLINE -#define UPB_FORCEINLINE +#define UPB_FORCEINLINE static #define UPB_NORETURN __declspec(noreturn) #define UPB_PRINTF(str, first_vararg) #else /* !defined(__GNUC__) */ -#define UPB_FORCEINLINE +#define UPB_FORCEINLINE static #define UPB_NOINLINE #define UPB_NORETURN #define UPB_PRINTF(str, first_vararg) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 07bb8cb452..d92733d2f5 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -166,8 +166,8 @@ static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, - uint64_t* val) { +const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, + uint64_t* val) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = byte; @@ -181,8 +181,8 @@ static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, - uint32_t* val) { +const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, + uint32_t* val) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = byte; @@ -199,8 +199,8 @@ static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { +const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, + uint32_t* size) { uint64_t size64; ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); if (size64 >= INT32_MAX || @@ -302,11 +302,10 @@ static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, - const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { +const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t expected_end_group) { if (--d->depth < 0) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); } @@ -319,9 +318,11 @@ static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { +const char* _upb_Decoder_DecodeSubMessage(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + int size) { int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); UPB_ASSERT(subl); @@ -331,10 +332,10 @@ static const char* _upb_Decoder_DecodeSubMessage( } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { +const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t number) { if (_upb_Decoder_IsDone(d, &ptr)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } @@ -344,16 +345,16 @@ static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, - const char* ptr, - uint32_t number) { +const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, const char* ptr, + uint32_t number) { return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownGroup( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { +const char* _upb_Decoder_DecodeKnownGroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field) { const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); UPB_ASSERT(subl); return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, @@ -383,10 +384,9 @@ static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, } UPB_FORCEINLINE -static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, - upb_Message* msg, const upb_MiniTableEnum* e, - const upb_MiniTableField* field, - wireval* val) { +bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTableEnum* e, + const upb_MiniTableField* field, wireval* val) { const uint32_t v = val->uint32_val; if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; @@ -420,9 +420,10 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeFixedPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { +const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTableField* field, + int lg2) { int mask = (1 << lg2) - 1; size_t count = val->size >> lg2; if ((val->size & mask) != 0) { @@ -457,9 +458,10 @@ static const char* _upb_Decoder_DecodeFixedPacked( } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarintPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { +const char* _upb_Decoder_DecodeVarintPacked(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTableField* field, + int lg2) { int scale = 1 << lg2; int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); char* out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr), @@ -765,9 +767,8 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* m) { +bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, const upb_MiniTable* m) { #if UPB_FASTTABLE if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); @@ -1005,9 +1006,8 @@ static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { } UPB_FORCEINLINE -static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field, - int* op) { +void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field, int* op) { // If sub-message is not linked, treat as unknown. if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; const upb_MiniTable* mt_sub = @@ -1033,9 +1033,8 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, } UPB_FORCEINLINE -static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, - const upb_MiniTableField* field, - int* op) { +void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, + const upb_MiniTableField* field, int* op) { if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) *op = kUpb_DecodeOp_String; @@ -1105,11 +1104,10 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, - const upb_MiniTable* mt, - const upb_MiniTableField* field, - int wire_type, wireval* val, - int* op) { +const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, + const upb_MiniTable* mt, + const upb_MiniTableField* field, + int wire_type, wireval* val, int* op) { static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Fixed32) | (1 << kUpb_FieldType_SFixed32); @@ -1159,10 +1157,11 @@ static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout, const upb_MiniTableField* field, int op, - wireval* val) { +const char* _upb_Decoder_DecodeKnownField(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout, + const upb_MiniTableField* field, + int op, wireval* val) { const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); uint8_t mode = field->UPB_PRIVATE(mode); diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 5a12a32071..f95d659679 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -113,7 +113,7 @@ static void encode_growbuffer(upb_encstate* e, size_t bytes) { /* Call to ensure that at least "bytes" bytes are available for writing at * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { +void encode_reserve(upb_encstate* e, size_t bytes) { if ((size_t)(e->ptr - e->buf) < bytes) { encode_growbuffer(e, bytes); return; @@ -152,7 +152,7 @@ static void encode_longvarint(upb_encstate* e, uint64_t val) { } UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { +void encode_varint(upb_encstate* e, uint64_t val) { if (val < 128 && e->ptr != e->buf) { --e->ptr; *e->ptr = val; diff --git a/upb/wire/eps_copy_input_stream.h b/upb/wire/eps_copy_input_stream.h index 3d04f1ed45..690ab49666 100644 --- a/upb/wire/eps_copy_input_stream.h +++ b/upb/wire/eps_copy_input_stream.h @@ -37,8 +37,8 @@ typedef struct { const char* end; // Can read up to SlopBytes bytes beyond this. const char* limit_ptr; // For bounds checks, = end + UPB_MIN(limit, 0) uintptr_t aliasing; - int limit; // Submessage limit relative to end - bool error; // To distinguish between EOF and error. + int limit; // Submessage limit relative to end + bool error; // To distinguish between EOF and error. char patch[kUpb_EpsCopyInputStream_SlopBytes * 2]; } upb_EpsCopyInputStream; @@ -375,7 +375,7 @@ typedef const char* upb_EpsCopyInputStream_ParseDelimitedFunc( // fits within this buffer, calls `func` with `ctx` as a parameter, where the // pushing and popping of limits is handled automatically and with lower cost // than the normal PushLimit()/PopLimit() sequence. -static UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( +UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( upb_EpsCopyInputStream* e, const char** ptr, int len, upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { if (!upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(e, *ptr, len)) { diff --git a/upb/wire/internal/decode_fast.c b/upb/wire/internal/decode_fast.c index 9203643ce3..67be4135c4 100644 --- a/upb/wire/internal/decode_fast.c +++ b/upb/wire/internal/decode_fast.c @@ -58,7 +58,7 @@ static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { } UPB_FORCEINLINE -static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { +const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { int overrun; switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { case kUpb_IsDoneStatus_Done: @@ -80,7 +80,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { } UPB_FORCEINLINE -static bool fastdecode_checktag(uint16_t data, int tagbytes) { +bool fastdecode_checktag(uint16_t data, int tagbytes) { if (tagbytes == 1) { return (data & 0xff) == 0; } else { @@ -89,7 +89,7 @@ static bool fastdecode_checktag(uint16_t data, int tagbytes) { } UPB_FORCEINLINE -static const char* fastdecode_longsize(const char* ptr, int* size) { +const char* fastdecode_longsize(const char* ptr, int* size) { int i; UPB_ASSERT(*size & 0x80); *size &= 0xff; @@ -109,7 +109,7 @@ static const char* fastdecode_longsize(const char* ptr, int* size) { } UPB_FORCEINLINE -static const char* fastdecode_delimited( +const char* fastdecode_delimited( upb_Decoder* d, const char* ptr, upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { ptr++; @@ -162,8 +162,8 @@ typedef struct { } fastdecode_nextret; UPB_FORCEINLINE -static void* fastdecode_resizearr(upb_Decoder* d, void* dst, - fastdecode_arr* farr, int valbytes) { +void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr, + int valbytes) { if (UPB_UNLIKELY(dst == farr->end)) { size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); size_t old_bytes = old_capacity * valbytes; @@ -181,7 +181,7 @@ static void* fastdecode_resizearr(upb_Decoder* d, void* dst, } UPB_FORCEINLINE -static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { +bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { if (tagbytes == 1) { return (uint8_t)tag == (uint8_t)data; } else { @@ -190,19 +190,17 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { } UPB_FORCEINLINE -static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, - int valbytes) { +void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { farr->arr->UPB_PRIVATE(size) = (size_t)((char*)dst - (char*)upb_Array_MutableDataPtr(farr->arr)) / valbytes; } UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, - const char** ptr, - fastdecode_arr* farr, - uint64_t data, int tagbytes, - int valbytes) { +fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, uint64_t data, + int tagbytes, int valbytes) { fastdecode_nextret ret; dst = (char*)dst + valbytes; @@ -224,16 +222,15 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, } UPB_FORCEINLINE -static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { +void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { size_t ofs = data >> 48; return (char*)msg + ofs; } UPB_FORCEINLINE -static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t* data, - uint64_t* hasbits, fastdecode_arr* farr, - int valbytes, upb_card card) { +void* fastdecode_getfield(upb_Decoder* d, const char* ptr, upb_Message* msg, + uint64_t* data, uint64_t* hasbits, + fastdecode_arr* farr, int valbytes, upb_card card) { switch (card) { case CARD_s: { uint8_t hasbit_index = *data >> 24; @@ -272,7 +269,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, } UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { +bool fastdecode_flippacked(uint64_t* data, int tagbytes) { *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. return fastdecode_checktag(*data, tagbytes); } @@ -288,7 +285,7 @@ static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { /* varint fields **************************************************************/ UPB_FORCEINLINE -static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { +uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { if (valbytes == 1) { return val != 0; } else if (zigzag) { @@ -304,7 +301,7 @@ static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { } UPB_FORCEINLINE -static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { +const char* fastdecode_varint64(const char* ptr, uint64_t* val) { ptr++; *val = (uint8_t)ptr[-1]; if (UPB_UNLIKELY(*val & 0x80)) { @@ -379,8 +376,8 @@ typedef struct { } fastdecode_varintdata; UPB_FORCEINLINE -static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { +const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { upb_Decoder* d = (upb_Decoder*)e; fastdecode_varintdata* data = ctx; void* dst = data->dst; @@ -659,9 +656,8 @@ static const char* fastdecode_longstring_noutf8( } UPB_FORCEINLINE -static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, - int copy, char* data, size_t data_offset, - upb_StringView* dst) { +void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy, + char* data, size_t data_offset, upb_StringView* dst) { d->arena.UPB_PRIVATE(ptr) += copy; dst->data = data + data_offset; UPB_UNPOISON_MEMORY_REGION(data, copy); @@ -892,8 +888,8 @@ typedef struct { } fastdecode_submsgdata; UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { +const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, const char* ptr, + void* ctx) { upb_Decoder* d = (upb_Decoder*)e; fastdecode_submsgdata* submsg = ctx; ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); diff --git a/upb/wire/internal/reader.h b/upb/wire/internal/reader.h index 2eff56bc86..dbe726149d 100644 --- a/upb/wire/internal/reader.h +++ b/upb/wire/internal/reader.h @@ -26,7 +26,7 @@ extern "C" { UPB_PRIVATE(_upb_WireReader_LongVarint) UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); -static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( +UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { diff --git a/upb/wire/reader.h b/upb/wire/reader.h index 9914837d73..37ff32ae09 100644 --- a/upb/wire/reader.h +++ b/upb/wire/reader.h @@ -32,8 +32,8 @@ extern "C" { // REQUIRES: there must be at least 10 bytes of data available at `ptr`. // Bounds checks must be performed before calling this function, preferably // by calling upb_EpsCopyInputStream_IsDone(). -static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, - uint32_t* tag) { +UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, + uint32_t* tag) { uint64_t val; ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); if (!ptr) return NULL;