upb: clean up the UPB_TRACING_ENABLED code

PiperOrigin-RevId: 631023575
pull/16737/head
Eric Salo 7 months ago committed by Copybara-Service
parent b6e0a48b02
commit 18306666b9
  1. 20
      upb/message/internal/message.c
  2. 15
      upb/message/internal/message.h
  3. 16
      upb/message/message.h

@ -60,18 +60,16 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
}
#if UPB_TRACING_ENABLED
static void (*_new_message_trace_handler)(const upb_MiniTable*,
const upb_Arena*);
static void (*_message_trace_handler)(const upb_MiniTable*, const upb_Arena*);
void UPB_PRIVATE(upb_Message_SetNewMessageTraceHandler)(
void (*new_message_trace_handler)(const upb_MiniTable*, const upb_Arena*)) {
_new_message_trace_handler = new_message_trace_handler;
void upb_Message_LogNewMessage(const upb_MiniTable* m, const upb_Arena* arena) {
if (_message_trace_handler) {
_message_trace_handler(m, arena);
}
}
void UPB_PRIVATE(upb_Message_LogNewMessage)(const upb_MiniTable* mini_table,
const upb_Arena* arena) {
if (_new_message_trace_handler) {
_new_message_trace_handler(mini_table, arena);
}
void upb_Message_SetNewMessageTraceHandler(void (*handler)(const upb_MiniTable*,
const upb_Arena*)) {
_message_trace_handler = handler;
}
#endif
#endif // UPB_TRACING_ENABLED

@ -60,18 +60,19 @@ typedef struct upb_Message_Internal {
} upb_Message_Internal;
#ifdef UPB_TRACING_ENABLED
void UPB_PRIVATE(upb_Message_SetNewMessageTraceHandler)(
void (*newMessageTraceHandler)(const upb_MiniTable*, const upb_Arena*));
void UPB_PRIVATE(upb_Message_LogNewMessage)(const upb_MiniTable* mini_table,
const upb_Arena* arena);
#endif
UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
const upb_Arena* arena);
UPB_API void upb_Message_SetNewMessageTraceHandler(
void (*handler)(const upb_MiniTable*, const upb_Arena*));
#endif // UPB_TRACING_ENABLED
// Inline version upb_Message_New(), for internal use.
UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* m,
upb_Arena* a) {
#ifdef UPB_TRACING_ENABLED
UPB_PRIVATE(upb_Message_LogNewMessage)(m, a);
#endif
upb_Message_LogNewMessage(m, a);
#endif // UPB_TRACING_ENABLED
const int size = m->UPB_PRIVATE(size);
struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size);
if (UPB_UNLIKELY(!msg)) return NULL;

@ -47,16 +47,12 @@ UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m);
UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg);
#ifdef UPB_TRACING_ENABLED
UPB_INLINE void upb_Message_SetNewMessageTraceHandler(
void (*newMessageTraceHandler)(const upb_MiniTable* mini_table,
const upb_Arena* arena)) {
UPB_PRIVATE(upb_Message_SetNewMessageTraceHandler)(newMessageTraceHandler);
}
UPB_INLINE void upb_Message_LogNewMessage(const upb_MiniTable* mini_table,
const upb_Arena* arena) {
UPB_PRIVATE(upb_Message_LogNewMessage)(mini_table, arena);
}
#endif
UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
const upb_Arena* arena);
UPB_API void upb_Message_SetNewMessageTraceHandler(
void (*handler)(const upb_MiniTable* m, const upb_Arena* arena));
#endif // UPB_TRACING_ENABLED
#ifdef __cplusplus
} /* extern "C" */

Loading…
Cancel
Save