Skip to content
Open
File renamed without changes.
20 changes: 10 additions & 10 deletions ds4.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ static const char DS4_REASONING_EFFORT_MAX_PREFIX[] =
* asks for a reasoning budget the allocated context is not meant to hold. */
#define DS4_THINK_MAX_MIN_CONTEXT 393216u

static bool ds4_backend_uses_graph(ds4_backend backend) {
static inline bool ds4_backend_uses_graph(ds4_backend backend) {
return backend == DS4_BACKEND_METAL || backend == DS4_BACKEND_CUDA;
}

static bool ds4_backend_supports_ssd_streaming(ds4_backend backend) {
static inline bool ds4_backend_supports_ssd_streaming(ds4_backend backend) {
if (backend == DS4_BACKEND_METAL) return true;
if (backend == DS4_BACKEND_CUDA) {
#if defined(DS4_ROCM_BUILD) || (!defined(DS4_NO_GPU) && !defined(__APPLE__))
Expand All @@ -88,7 +88,7 @@ static bool ds4_backend_supports_ssd_streaming(ds4_backend backend) {
return false;
}

static bool ds4_backend_supports_streaming_auto_cache(ds4_backend backend) {
static inline bool ds4_backend_supports_streaming_auto_cache(ds4_backend backend) {
if (backend == DS4_BACKEND_METAL) return true;
#ifdef DS4_ROCM_BUILD
if (backend == DS4_BACKEND_CUDA) return true;
Expand Down Expand Up @@ -615,7 +615,7 @@ typedef struct {
char error[256];
} ds4_cursor;

static void ds4_die(const char *msg) {
static inline void ds4_die(const char *msg) {
fprintf(stderr, "ds4: %s\n", msg);
exit(1);
}
Expand Down Expand Up @@ -643,17 +643,17 @@ static uint32_t ds4_expected_layer_compress_ratio(uint32_t il) {
return 0;
}

static void ds4_die_errno(const char *what, const char *path) {
static inline void ds4_die_errno(const char *what, const char *path) {
fprintf(stderr, "ds4: %s '%s': %s\n", what, path, strerror(errno));
exit(1);
}

static bool ds4_streq(ds4_str s, const char *z) {
static inline bool ds4_streq(ds4_str s, const char *z) {
size_t n = strlen(z);
return s.len == n && memcmp(s.ptr, z, n) == 0;
}

static bool ds4_str_eq(ds4_str a, ds4_str b) {
static inline bool ds4_str_eq(ds4_str a, ds4_str b) {
return a.len == b.len && memcmp(a.ptr, b.ptr, a.len) == 0;
}

Expand All @@ -670,17 +670,17 @@ static uint64_t hash_bytes(const void *ptr, uint64_t len) {
static bool g_alloc_guard_enabled;
static const char *g_alloc_guard_phase;

static void ds4_alloc_guard_begin(const char *phase) {
static inline void ds4_alloc_guard_begin(const char *phase) {
g_alloc_guard_phase = phase;
g_alloc_guard_enabled = true;
}

static void ds4_alloc_guard_end(void) {
static inline void ds4_alloc_guard_end(void) {
g_alloc_guard_enabled = false;
g_alloc_guard_phase = NULL;
}

static void ds4_alloc_guard_check(const char *op, size_t size) {
static inline void ds4_alloc_guard_check(const char *op, size_t size) {
if (!g_alloc_guard_enabled) return;
fprintf(stderr,
"ds4: internal allocation during %s: %s(%zu). "
Expand Down
30 changes: 15 additions & 15 deletions ds4_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,26 @@ typedef struct {
size_t cap;
} buf;

static void die(const char *msg) {
static inline void die(const char *msg) {
fprintf(stderr, "ds4-server: %s\n", msg);
exit(1);
}

static void *xmalloc(size_t n) {
static inline void *xmalloc(size_t n) {
void *p = malloc(n ? n : 1);
if (!p) die("out of memory");
return p;
}

static void *xrealloc(void *p, size_t n) {
static inline void *xrealloc(void *p, size_t n) {
p = realloc(p, n ? n : 1);
if (!p) die("out of memory");
return p;
}

static char *xstrdup(const char *s) {
static inline char *xstrdup(const char *s) {
size_t n = strlen(s);
char *p = xmalloc(n + 1);
char* p = xmalloc(n + 1);
memcpy(p, s, n + 1);
return p;
}
Expand All @@ -104,7 +104,7 @@ static bool random_bytes(void *dst, size_t len) {
return true;
}

static char *xstrndup(const char *s, size_t n) {
static inline char *xstrndup(const char *s, size_t n) {
char *p = xmalloc(n + 1);
memcpy(p, s, n);
p[n] = '\0';
Expand Down Expand Up @@ -432,20 +432,20 @@ static bool json_content(const char **p, char **out) {
(*p)++;
buf b = {0};
json_ws(p);
while (**p && **p != ']') {
if (**p == '"') {
while (**p && **p != "]") {
if (**p == "\"") {
char *s = NULL;
if (!json_string(p, &s)) goto fail;
buf_puts(&b, s);
free(s);
} else if (**p == '{') {
} else if (**p == "{") {
(*p)++;
json_ws(p);
while (**p && **p != '}') {
while (**p && **p != "}") {
char *key = NULL;
if (!json_string(p, &key)) goto fail;
json_ws(p);
if (**p != ':') {
if (**p != ":") {
free(key);
goto fail;
}
Expand All @@ -464,19 +464,19 @@ static bool json_content(const char **p, char **out) {
}
free(key);
json_ws(p);
if (**p == ',') (*p)++;
if (**p == ",") (*p)++;
json_ws(p);
}
if (**p != '}') goto fail;
if (**p != "}") goto fail;
(*p)++;
} else if (!json_skip_value(p)) {
goto fail;
}
json_ws(p);
if (**p == ',') (*p)++;
if (**p == ",") (*p)++;
json_ws(p);
}
if (**p != ']') goto fail;
if (**p != "]") goto fail;
(*p)++;
*out = buf_take(&b);
return true;
Expand Down