Skip to content

Commit 26a7814

Browse files
committed
Fix Windows/MinGW build: TLS, strndup, sys/wait.h
- CBM_TLS: use _Thread_local (C11 standard) instead of __declspec(thread) which only works on MSVC, not MinGW GCC - Replace bare strndup() with cbm_strndup() in 6 files (strndup is POSIX, not available on Windows) - Guard sys/wait.h with #ifndef _WIN32 in http_server.c
1 parent c8bdf92 commit 26a7814

8 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/foundation/compat.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
#include <stdio.h>
1313

1414
/* ── Thread-local storage ─────────────────────────────────────── */
15-
#ifdef _WIN32
16-
#define CBM_TLS __declspec(thread)
17-
#else
15+
/* _Thread_local is C11 standard — works on GCC, Clang, and MSVC (2019+).
16+
* __declspec(thread) is MSVC-only and doesn't work on MinGW GCC. */
1817
#define CBM_TLS _Thread_local
19-
#endif
2018

2119
/* ── Sleep ────────────────────────────────────────────────────── */
2220
#ifdef _WIN32

src/graph_buffer/graph_buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "store/store.h"
1313
#include "sqlite_writer.h"
1414
#include "foundation/hash_table.h"
15+
#include "foundation/compat.h"
1516
#include "foundation/log.h"
1617
#include "foundation/dyn_array.h"
1718

@@ -841,7 +842,7 @@ static char *extract_url_path(const char *props) {
841842
return NULL;
842843
}
843844
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
844-
return strndup(key, (size_t)(end - key));
845+
return cbm_strndup(key, (size_t)(end - key));
845846
}
846847

847848
int cbm_gbuf_dump_to_sqlite(cbm_gbuf_t *gb, const char *path) {

src/pipeline/pass_calls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int build_import_map(cbm_pipeline_ctx_t *ctx, const char *rel_path,
139139
const char *end = strchr(start, '"');
140140
if (end && end > start) {
141141
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
142-
char *key = strndup(start, end - start);
142+
char *key = cbm_strndup(start, end - start);
143143
keys[count] = key;
144144
vals[count] = target->qualified_name;
145145
count++;

src/pipeline/pass_enrichment.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "foundation/log.h"
1212
#include "foundation/hash_table.h"
1313
#include "foundation/platform.h"
14+
#include "foundation/compat.h"
1415
#include "yyjson/yyjson.h"
1516

1617
#include <ctype.h>
@@ -46,15 +47,15 @@ int cbm_split_camel_case(const char *s, char **out, int max_out) {
4647
if (s[i] >= 'A' && s[i] <= 'Z' && s[i - 1] >= 'a' && s[i - 1] <= 'z') {
4748
if (count < max_out) {
4849
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
49-
out[count] = strndup(s + start, i - start);
50+
out[count] = cbm_strndup(s + start, i - start);
5051
count++;
5152
}
5253
start = i;
5354
}
5455
}
5556
/* Emit remaining */
5657
if (count < max_out) {
57-
out[count] = strndup(s + start, len - start);
58+
out[count] = cbm_strndup(s + start, len - start);
5859
count++;
5960
}
6061
return count;

src/pipeline/pass_parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static int build_import_map(const cbm_gbuf_t *gbuf, const char *project_name, co
232232
const char *end = strchr(start, '"');
233233
if (end && end > start) {
234234
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
235-
keys[count] = strndup(start, end - start);
235+
keys[count] = cbm_strndup(start, end - start);
236236
vals[count] = target->qualified_name;
237237
count++;
238238
}

src/pipeline/pass_semantic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int build_import_map(cbm_pipeline_ctx_t *ctx, const char *rel_path,
131131
const char *end = strchr(start, '"');
132132
if (end && end > start) {
133133
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
134-
keys[count] = strndup(start, end - start);
134+
keys[count] = cbm_strndup(start, end - start);
135135
vals[count] = target->qualified_name;
136136
count++;
137137
}

src/pipeline/pass_usages.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int build_import_map(cbm_pipeline_ctx_t *ctx, const char *rel_path,
147147
const char *end = strchr(start, '"');
148148
if (end && end > start) {
149149
// NOLINTNEXTLINE(misc-include-cleaner) — strndup provided by standard header
150-
keys[count] = strndup(start, end - start);
150+
keys[count] = cbm_strndup(start, end - start);
151151
vals[count] = target->qualified_name;
152152
count++;
153153
}

src/ui/http_server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
#include <stdio.h>
2929
#include <stdlib.h>
3030
#include <string.h>
31+
#ifndef _WIN32
3132
#include <unistd.h>
3233
#include <sys/wait.h>
34+
#endif
3335
#ifdef __APPLE__
3436
#include <mach-o/dyld.h>
3537
#endif

0 commit comments

Comments
 (0)