Compile fix.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4660 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-12-06 00:52:47 +00:00
parent e677b0ac3c
commit eb3c9cd6f3

View File

@ -16,9 +16,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#if !defined(_countof) #define tf_countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
#define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
#endif
enum enum
{ {
@ -139,7 +137,7 @@ void tf_trace_counter(tf_trace_t* trace, const char* name, int argc, const char*
{ {
p += snprintf(line + p, sizeof(line) - p, "\"%s\": %" PRId64 "%s", arg_names[i], arg_values[i], i == argc - 1 ? "}}," : ", "); p += snprintf(line + p, sizeof(line) - p, "\"%s\": %" PRId64 "%s", arg_names[i], arg_values[i], i == argc - 1 ? "}}," : ", ");
} }
p = tf_min(p, _countof(line)); p = tf_min(p, tf_countof(line));
trace->callback(trace, line, p, trace->user_data); trace->callback(trace, line, p, trace->user_data);
} }
@ -229,7 +227,7 @@ static tf_trace_thread_t* _tf_trace_get_thread(tf_trace_t* trace, pthread_t self
static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name, void* tag) static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name, void* tag)
{ {
tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self); tf_trace_thread_t* thread = _tf_trace_get_thread(trace, self);
if (!thread->stack || thread->stack->count + 1 > (int)_countof(thread->stack->names)) if (!thread->stack || thread->stack->count + 1 > tf_countof(thread->stack->names))
{ {
tf_trace_stack_t* stack = tf_malloc(sizeof(tf_trace_stack_t)); tf_trace_stack_t* stack = tf_malloc(sizeof(tf_trace_stack_t));
memset(stack, 0, sizeof(*stack)); memset(stack, 0, sizeof(*stack));
@ -237,7 +235,7 @@ static void _tf_push_stack(tf_trace_t* trace, pthread_t self, const char* name,
thread->stack = stack; thread->stack = stack;
} }
tf_trace_stack_t* stack = thread->stack; tf_trace_stack_t* stack = thread->stack;
while (stack->count == 0 && stack->next && stack->next->count + 1 <= (int)_countof(thread->stack->names)) while (stack->count == 0 && stack->next && stack->next->count + 1 <= tf_countof(thread->stack->names))
{ {
stack = stack->next; stack = stack->next;
} }
@ -280,7 +278,7 @@ static void _tf_trace_begin_tagged(tf_trace_t* trace, const char* name, void* ta
int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)self, _trace_ts()); int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)self, _trace_ts());
p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name);
p += snprintf(line + p, sizeof(line) - p, "\"},"); p += snprintf(line + p, sizeof(line) - p, "\"},");
p = tf_min(p, _countof(line)); p = tf_min(p, tf_countof(line));
trace->callback(trace, line, p, trace->user_data); trace->callback(trace, line, p, trace->user_data);
} }
@ -307,7 +305,7 @@ static void _tf_trace_end_tagged(tf_trace_t* trace, void* tag)
int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts()); int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts());
p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name);
p += snprintf(line + p, sizeof(line) - p, "\"},"); p += snprintf(line + p, sizeof(line) - p, "\"},");
p = tf_min(p, _countof(line)); p = tf_min(p, tf_countof(line));
trace->callback(trace, line, p, trace->user_data); trace->callback(trace, line, p, trace->user_data);
} }