make nogfx compile on mac

This commit is contained in:
silverweed 2024-08-21 13:56:30 +02:00
parent df2c4c2a89
commit 7f300d0ded
6 changed files with 79 additions and 56 deletions

View file

@ -12,7 +12,7 @@ CFLAGS = -Wall -Wextra -pedantic
INC = -Ithird_party -Ithird_party/imgui INC = -Ithird_party -Ithird_party/imgui
LIBS = -lglfw LIBS = -lglfw
ROOTFLAGS = -std=c++17 -m64 -I$(ROOTINCDIR) ROOTFLAGS = -std=c++17 -m64 -I$(ROOTINCDIR) -I/Users/sftnight/root/builtins/xxhash
ROOTLIBS = -L$(ROOTLIBDIR) -lCore -lRIO -lROOTNTuple -lxxhash -pthread -Wl,-rpath,$(ROOTLIBDIR) ROOTLIBS = -L$(ROOTLIBDIR) -lCore -lRIO -lROOTNTuple -lxxhash -pthread -Wl,-rpath,$(ROOTLIBDIR)
IMGUI_FLAGS = -Ithird_party -Ithird_party/imgui IMGUI_FLAGS = -Ithird_party -Ithird_party/imgui

View file

@ -1,8 +1,10 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/inotify.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h> // for NAME_MAX #include <limits.h> // for NAME_MAX
#if defined(R__LINUX)
#include <sys/inotify.h>
#endif
internal internal
i32 os_page_size() i32 os_page_size()
@ -21,7 +23,7 @@ bool os_open_and_map_file(String8 fname, App_State &app)
int fd = fileno(file); int fd = fileno(file);
size_t fsize = file_size(file); size_t fsize = file_size(file);
void *fmem = mmap(0, fsize, PROT_READ, MAP_SHARED_VALIDATE, fd, 0); void *fmem = mmap(0, fsize, PROT_READ, MAP_SHARED, fd, 0);
if (!fmem) { if (!fmem) {
fprintf(stderr, "Failed to open file %s\n", fname.c()); fprintf(stderr, "Failed to open file %s\n", fname.c());
return false; return false;
@ -42,25 +44,6 @@ void os_unmap_file(u8 *&mem, u64 size)
mem = nullptr; mem = nullptr;
} }
internal
void os_start_file_watch(String8 fname, App_State &app)
{
int inot = inotify_init1(IN_NONBLOCK);
if (inot == -1)
fprintf(stderr, "Failed to init inotify: %s (%d)\n", strerror(errno), errno);
if (inotify_add_watch(inot, fname.c(), IN_MODIFY) == -1)
fprintf(stderr, "Failed to add inotify watch: %s (%d)\n", strerror(errno), errno);
app.inspected_file.inot = inot;
}
internal
void os_stop_file_watch(App_State &app)
{
if (app.inspected_file.inot != -1) close(app.inspected_file.inot);
app.inspected_file.inot = -1;
}
internal internal
void *os_reserve(u64 size) void *os_reserve(u64 size)
{ {
@ -87,3 +70,33 @@ b32x os_commit(void *addr, u64 size)
return err == 0; return err == 0;
} }
#if defined(R__LINUX)
internal
void os_start_file_watch(String8 fname, App_State &app)
{
int inot = inotify_init1(IN_NONBLOCK);
if (inot == -1)
fprintf(stderr, "Failed to init inotify: %s (%d)\n", strerror(errno), errno);
if (inotify_add_watch(inot, fname.c(), IN_MODIFY) == -1)
fprintf(stderr, "Failed to add inotify watch: %s (%d)\n", strerror(errno), errno);
app.inspected_file.inot = inot;
}
internal
void os_stop_file_watch(App_State &app)
{
if (app.inspected_file.inot != -1) close(app.inspected_file.inot);
app.inspected_file.inot = -1;
}
#else
internal
void os_start_file_watch(String8, App_State &)
{
fprintf(stderr, "Warning: file watch is not supported on this platform.\n");
}
internal
void os_stop_file_watch(App_State &)
{}
#endif

View file

@ -138,7 +138,7 @@ String8 render_range_bytes_to_string(Arena *arena, App_State &app, Term_Viewer &
*cur++ = '\n'; *cur++ = '\n';
// first line addr // first line addr
cur += sprintf(cur, line_addr_fmt.c(), start); cur += snprintf(cur, max_addr_len, line_addr_fmt.c(), start);
for (u32 i = 0; i < n_spaces_after_line_addr; ++i) for (u32 i = 0; i < n_spaces_after_line_addr; ++i)
*cur++ = ' '; *cur++ = ' ';
@ -154,14 +154,14 @@ String8 render_range_bytes_to_string(Arena *arena, App_State &app, Term_Viewer &
cur += acol_str.size; cur += acol_str.size;
/// Write the human-readable byte /// Write the human-readable byte
cur += sprintf(cur, "%02X ", data[off]); cur += snprintf(cur, 3, "%02X ", data[off]);
// new line // new line
if ((i + 1) % n_cols == 0) { if ((i + 1) % n_cols == 0) {
*cur++ = '\n'; *cur++ = '\n';
memcpy(cur, col_none.c(), col_none.size); memcpy(cur, col_none.c(), col_none.size);
cur += col_none.size; cur += col_none.size;
cur += sprintf(cur, line_addr_fmt.c(), off + 1); cur += snprintf(cur, max_addr_len, line_addr_fmt.c(), off + 1);
for (u32 i = 0; i < n_spaces_after_line_addr; ++i) for (u32 i = 0; i < n_spaces_after_line_addr; ++i)
*cur++ = ' '; *cur++ = ' ';
} }

View file

@ -221,7 +221,7 @@ void gather_ntuple_metadata(Arena *arena, RMicroFileReader &reader, const RNTupl
chr::time_point end_t = chr::high_resolution_clock::now(); chr::time_point end_t = chr::high_resolution_clock::now();
u64 time_spent_ms = chr::duration_cast<chr::milliseconds>(end_t - start_t).count(); u64 time_spent_ms = chr::duration_cast<chr::milliseconds>(end_t - start_t).count();
fprintf(stderr, "Loaded %lu pages in %lu ms (%lu duplicates).\nGenerating groups...\n", fprintf(stderr, "Loaded %" PRIu64 " pages in %" PRIu64 " ms (%" PRIu64 " duplicates).\nGenerating groups...\n",
n_pages, time_spent_ms, n_duplicate_page_ranges); n_pages, time_spent_ms, n_duplicate_page_ranges);
// Create page groups and chunks. // Create page groups and chunks.
@ -285,7 +285,7 @@ void gather_ntuple_metadata(Arena *arena, RMicroFileReader &reader, const RNTupl
Page_Info_Group &last_group = groups[n_groups - 1]; Page_Info_Group &last_group = groups[n_groups - 1];
last_group.range.len = pinfo_tail->range.end() - last_group.range.start; last_group.range.len = pinfo_tail->range.end() - last_group.range.start;
fprintf(stderr, "Generated %lu groups and %lu chunks.\n", n_groups, n_chunks); fprintf(stderr, "Generated %" PRIu64 " groups and %" PRIu64 " chunks.\n", n_groups, n_chunks);
assert(!chunks_tail->next); assert(!chunks_tail->next);
assert(!pinfo_tail->next); assert(!pinfo_tail->next);
@ -581,7 +581,7 @@ Section find_section(App_State &app, u64 off, i64 hilite_cluster = -1)
} }
} }
fprintf(stderr, "Offset 0x%lX is in chunk 0x%lX - 0x%lX, but found in no page_info range!\n", fprintf(stderr, "Offset 0x%" PRIX64 " is in chunk 0x%" PRIX64 " - 0x%" PRIX64 ", but found in no page_info range!\n",
off, chunk->range.start, chunk->range.end()); off, chunk->range.start, chunk->range.end());
assert(false); assert(false);
} }
@ -768,8 +768,8 @@ struct Try_Sec_Hover_Fn {
|| field<u32>("Datetime: ", hover_display_datetime_str) || field<u32>("Datetime: ", hover_display_datetime_str)
|| field<u16>("Key Len: %u") || field<u16>("Key Len: %u")
|| field<u16>("Cycle: %u") || field<u16>("Cycle: %u")
|| field<u64>("Seek Key: 0x%lX") || field<u64>("Seek Key: 0x%" PRIX64)
|| field<u64>("Seek Pdir: 0x%lX") || field<u64>("Seek Pdir: 0x%" PRIX64)
|| field<String8>("Class Name: %s") || field<String8>("Class Name: %s")
|| field<String8>("Obj Name: %s") || field<String8>("Obj Name: %s")
|| field<String8>("Obj Title: %s") || field<String8>("Obj Title: %s")
@ -784,8 +784,8 @@ struct Try_Sec_Hover_Fn {
|| field<u32>("Datetime: ", hover_display_datetime_str) || field<u32>("Datetime: ", hover_display_datetime_str)
|| field<u16>("Key Len: %u") || field<u16>("Key Len: %u")
|| field<u16>("Cycle: %u") || field<u16>("Cycle: %u")
|| field<u32>("Seek Key: 0x%lX") || field<u32>("Seek Key: 0x%" PRIX64)
|| field<u32>("Seek Pdir: 0x%lX") || field<u32>("Seek Pdir: 0x%" PRIX64)
|| field<String8>("Class Name: %s") || field<String8>("Class Name: %s")
|| field<String8>("Obj Name: %s") || field<String8>("Obj Name: %s")
|| field<String8>("Obj Title: %s") || field<String8>("Obj Title: %s")
@ -800,7 +800,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
{ {
Sec_Hover_Info info {}; Sec_Hover_Info info {};
// printf("off: 0x%lX, sec start - pre_size: (0x%lX - %lu) = 0x%lX\n", off, section.range.start, section.pre_size, section.range.start - section.pre_size); // printf("off: 0x%" PRIX64 ", sec start - pre_size: (0x%" PRIX64 " - %" PRIu64 ") = 0x%" PRIX64 "\n", off, section.range.start, section.pre_size, section.range.start - section.pre_size);
assert(off >= section.range.start - section.pre_size); assert(off >= section.range.start - section.pre_size);
// Hover info header // Hover info header
@ -830,14 +830,14 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
|| try_sec_hover.field<u16>("Version Major: %u") || try_sec_hover.field<u16>("Version Major: %u")
|| try_sec_hover.field<u16>("Version Minor: %u") || try_sec_hover.field<u16>("Version Minor: %u")
|| try_sec_hover.field<u16>("Version Patch: %u") || try_sec_hover.field<u16>("Version Patch: %u")
|| try_sec_hover.field<u64>("Seek Header: 0x%lX") || try_sec_hover.field<u64>("Seek Header: 0x%" PRIX64)
|| try_sec_hover.field<u64>("NBytes Header: %u") || try_sec_hover.field<u64>("NBytes Header: %u")
|| try_sec_hover.field<u64>("Len Header: %u") || try_sec_hover.field<u64>("Len Header: %u")
|| try_sec_hover.field<u64>("Seek Footer: 0x%lX") || try_sec_hover.field<u64>("Seek Footer: 0x%" PRIX64)
|| try_sec_hover.field<u64>("NBytes Footer: %u") || try_sec_hover.field<u64>("NBytes Footer: %u")
|| try_sec_hover.field<u64>("Len Footer: %u") || try_sec_hover.field<u64>("Len Footer: %u")
|| try_sec_hover.field<u64>("Max Key Size: %u") || try_sec_hover.field<u64>("Max Key Size: %u")
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le) || try_sec_hover.field<u64>("Checksum: 0x%" PRIX64, hover_display_val_le)
; ;
} break; } break;
@ -854,30 +854,30 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
x -= 1000000; x -= 1000000;
return push_str8_node_child(arena, prev, fmt, x); return push_str8_node_child(arena, prev, fmt, x);
}) })
|| try_sec_hover.field<u32>("fBEGIN: 0x%lX") || try_sec_hover.field<u32>("fBEGIN: 0x%" PRIX64)
|| try_sec_hover.field<u64>("fEND: 0x%lX") || try_sec_hover.field<u64>("fEND: 0x%" PRIX64)
|| try_sec_hover.field<u64>("Seek Free: 0x%lX") || try_sec_hover.field<u64>("Seek Free: 0x%" PRIX64)
|| try_sec_hover.field<u32>("NBytes Free: %u") || try_sec_hover.field<u32>("NBytes Free: %u")
|| try_sec_hover.field<u32>("N Free: %u") || try_sec_hover.field<u32>("N Free: %u")
|| try_sec_hover.field<u32>("NBytes Name: %u") || try_sec_hover.field<u32>("NBytes Name: %u")
|| try_sec_hover.field<u8>("Units: %u") || try_sec_hover.field<u8>("Units: %u")
|| try_sec_hover.field<u32>("Compression: %u") || try_sec_hover.field<u32>("Compression: %u")
|| try_sec_hover.field<u64>("Seek Info: 0x%lX") || try_sec_hover.field<u64>("Seek Info: 0x%" PRIX64)
|| try_sec_hover.field<u32>("NBytes Info: %u") || try_sec_hover.field<u32>("NBytes Info: %u")
|| try_sec_hover.range("Padding", section.post_size) || try_sec_hover.range("Padding", section.post_size)
; ;
} else { } else {
try_sec_hover.field<u32>("ROOT magic number") try_sec_hover.field<u32>("ROOT magic number")
|| try_sec_hover.field<u32>("ROOT version: %u") || try_sec_hover.field<u32>("ROOT version: %u")
|| try_sec_hover.field<u32>("fBEGIN: 0x%lX") || try_sec_hover.field<u32>("fBEGIN: 0x%" PRIX64)
|| try_sec_hover.field<u32>("fEND: 0x%lX") || try_sec_hover.field<u32>("fEND: 0x%" PRIX64)
|| try_sec_hover.field<u32>("Seek Free: 0x%lX") || try_sec_hover.field<u32>("Seek Free: 0x%" PRIX64)
|| try_sec_hover.field<u32>("NBytes Free: %u") || try_sec_hover.field<u32>("NBytes Free: %u")
|| try_sec_hover.field<u32>("N Free: %u") || try_sec_hover.field<u32>("N Free: %u")
|| try_sec_hover.field<u32>("NBytes Name: %u") || try_sec_hover.field<u32>("NBytes Name: %u")
|| try_sec_hover.field<u8>("Units: %u") || try_sec_hover.field<u8>("Units: %u")
|| try_sec_hover.field<u32>("Compression: %u") || try_sec_hover.field<u32>("Compression: %u")
|| try_sec_hover.field<u32>("Seek Info: 0x%lX") || try_sec_hover.field<u32>("Seek Info: 0x%" PRIX64)
|| try_sec_hover.field<u32>("NBytes Info: %u") || try_sec_hover.field<u32>("NBytes Info: %u")
|| try_sec_hover.range("Padding", section.post_size) || try_sec_hover.range("Padding", section.post_size)
; ;
@ -905,9 +905,9 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
|| try_sec_hover.field<u32>("Modified: ", hover_display_datetime_str) || try_sec_hover.field<u32>("Modified: ", hover_display_datetime_str)
|| try_sec_hover.field<u32>("NBytes Key: %u") || try_sec_hover.field<u32>("NBytes Key: %u")
|| try_sec_hover.field<u32>("NBytes Name: %u") || try_sec_hover.field<u32>("NBytes Name: %u")
|| try_sec_hover.field<u64>("Seek Dir: 0x%lX") || try_sec_hover.field<u64>("Seek Dir: 0x%" PRIX64)
|| try_sec_hover.field<u64>("Seek Parent: 0x%lX") || try_sec_hover.field<u64>("Seek Parent: 0x%" PRIX64)
|| try_sec_hover.field<u64>("Seek Keys: 0x%lX") || try_sec_hover.field<u64>("Seek Keys: 0x%" PRIX64)
|| try_sec_hover.field<u16>("UUID Vers.Class: %u") || try_sec_hover.field<u16>("UUID Vers.Class: %u")
|| try_sec_hover.field<u16>("UUID: %u", hover_display_val_le) || try_sec_hover.field<u16>("UUID: %u", hover_display_val_le)
; ;
@ -917,9 +917,9 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
|| try_sec_hover.field<u32>("Modified: ", hover_display_datetime_str) || try_sec_hover.field<u32>("Modified: ", hover_display_datetime_str)
|| try_sec_hover.field<u32>("NBytes Key: %u") || try_sec_hover.field<u32>("NBytes Key: %u")
|| try_sec_hover.field<u32>("NBytes Name: %u") || try_sec_hover.field<u32>("NBytes Name: %u")
|| try_sec_hover.field<u32>("Seek Dir: 0x%lX") || try_sec_hover.field<u32>("Seek Dir: 0x%" PRIX64)
|| try_sec_hover.field<u32>("Seek Parent: 0x%lX") || try_sec_hover.field<u32>("Seek Parent: 0x%" PRIX64)
|| try_sec_hover.field<u32>("Seek Keys: 0x%lX") || try_sec_hover.field<u32>("Seek Keys: 0x%" PRIX64)
|| try_sec_hover.field<u16>("UUID Vers.Class: %u") || try_sec_hover.field<u16>("UUID Vers.Class: %u")
|| try_sec_hover.field<u16>("UUID: %u", hover_display_val_le) || try_sec_hover.field<u16>("UUID: %u", hover_display_val_le)
|| try_sec_hover.range("Padding", 3 * sizeof(u32)) || try_sec_hover.range("Padding", 3 * sizeof(u32))
@ -935,7 +935,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
try_sec_hover.tkey() try_sec_hover.tkey()
|| try_sec_hover.maybe_rootzip(data, start) || try_sec_hover.maybe_rootzip(data, start)
|| try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve || try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le) || try_sec_hover.field<u64>("Checksum: 0x%" PRIX64, hover_display_val_le)
; ;
} break; } break;
@ -944,7 +944,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
b8 ok = section.pre_size && try_sec_hover.tkey(); b8 ok = section.pre_size && try_sec_hover.tkey();
ok = ok || try_sec_hover.maybe_rootzip(data, start) ok = ok || try_sec_hover.maybe_rootzip(data, start)
|| try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve || try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le) || try_sec_hover.field<u64>("Checksum: 0x%" PRIX64, hover_display_val_le)
; ;
} break; } break;
@ -977,8 +977,8 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
x -= 1000; x -= 1000;
return push_str8_node_child(arena, prev, fmt, x); return push_str8_node_child(arena, prev, fmt, x);
}) })
|| try_sec_hover.field<u64>("First: 0x%lX") || try_sec_hover.field<u64>("First: 0x%" PRIX64)
|| try_sec_hover.field<u64>("Last: 0x%lX") || try_sec_hover.field<u64>("Last: 0x%" PRIX64)
; ;
} else { } else {
try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) { try_sec_hover.field<u16>("Version: %u", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 x) {

View file

@ -26,7 +26,7 @@
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <cassert> #include <cassert>
#include <byteswap.h> #include <inttypes.h> // PRIu64
#include <chrono> #include <chrono>
@ -60,7 +60,7 @@
#include "render.h" #include "render.h"
#include "app_state.h" #include "app_state.h"
#if defined(R__LINUX) #if defined(R__LINUX) || defined(R__MACOSX)
#include "platform_linux.h" #include "platform_linux.h"
#else #else
#error "Unsupported platform" #error "Unsupported platform"

View file

@ -26,10 +26,20 @@ using i64 = int64_t;
#define LIKELY(x) __builtin_expect(!!(x), 1) #define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0) #define UNLIKELY(x) __builtin_expect(!!(x), 0)
#ifdef R__BYTESWAP #ifdef R__BYTESWAP
#if defined(R__MACOSX)
#include <libkern/OSByteOrder.h>
u16 bswap(u16 x) { return _OSSwapInt16(x); }
u32 bswap(u32 x) { return _OSSwapInt32(x); }
u64 bswap(u64 x) { return _OSSwapInt64(x); }
#else
#include <byteswap.h>
u16 bswap(u16 x) { return bswap_16(x); } u16 bswap(u16 x) { return bswap_16(x); }
u32 bswap(u32 x) { return bswap_32(x); } u32 bswap(u32 x) { return bswap_32(x); }
u64 bswap(u64 x) { return bswap_64(x); } u64 bswap(u64 x) { return bswap_64(x); }
#endif // defined(R__MACOSX)
#else #else
u16 bswap(u16 x) { return x; } u16 bswap(u16 x) { return x; }
u32 bswap(u32 x) { return x; } u32 bswap(u32 x) { return x; }