Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
Merge pull request #352 from woolcoxm/fix/test-stops-windows
JustVuggd94c68149db2
diff --cc c/compat.hindex 2dc5bdad,c477170c..1b56f5fb--- a/c/compat.h+++ b/c/compat.h@@@ -313,39 -305,21 +314,52 @@@ static inline int compat_setenv(const c}#define setenv(name,value,overwrite) compat_setenv(name,value,overwrite)+/* --- getenv_utf8: read an env var as UTF-8, not through the ANSI codepage ---+ * Plain getenv()/_environ are populated by the CRT from the ANSI-codepage view+ * of the process environment block, not UTF-8. A parent that hands the child a+ * Unicode value via CreateProcessW's wide env block (e.g. Python's subprocess+ * module, which coli uses to pass the chat prompt) round-trips correctly only+ * through GetEnvironmentVariableW; going through narrow getenv() re-encodes it+ * via CP_ACP first, so any non-ASCII prompt text (Cyrillic, CJK, ...) comes out+ * corrupted before the byte-level tokenizer ever sees it. Read the wide value+ * directly and convert straight to UTF-8, bypassing the ANSI codepage entirely.+ * Returned buffer is intentionally leaked: called a handful of times at+ * startup, lives for the process. */+static inline const char *compat_getenv_utf8(const char *name){+ wchar_t wname[64];+ if(MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, 64) <= 0) return getenv(name);+ DWORD need = GetEnvironmentVariableW(wname, NULL, 0);+ if(!need) return NULL;+ wchar_t *wval = (wchar_t*)malloc(need * sizeof(wchar_t));+ if(!wval) return NULL;+ GetEnvironmentVariableW(wname, wval, need);+ int blen = WideCharToMultiByte(CP_UTF8, 0, wval, -1, NULL, 0, NULL, NULL);+ char *val = blen>0 ? (char*)malloc((size_t)blen) : NULL;+ if(val) WideCharToMultiByte(CP_UTF8, 0, wval, -1, val, blen, NULL, NULL);+ free(wval);+ return val;+}+#define getenv_utf8(name) compat_getenv_utf8(name)++ /* --- mkdtemp -> _mktemp + _mkdir (POSIX mkdtemp assente su Windows) ---+ * Test binaries (test_stops.c) create a scratch dir in the CWD via a+ * "name_XXXXXX" template; POSIX mkdtemp fills the X's and mkdirs 0700. The+ * Windows CRT has _mktemp (in-place, same XXXXXX contract) so we compose it.+ * Returns the template pointer on success, NULL on failure — matching POSIX. */+ static inline char *compat_mkdtemp(char *tmpl){+ if(!tmpl) return NULL;+ if(!_mktemp(tmpl)) return NULL; /* fills the trailing X's in place */+ if(_mkdir(tmpl) != 0) return NULL; /* EEXIST is impossible post-_mktemp */+ return tmpl;+ }+ #define mkdtemp(tmpl) compat_mkdtemp(tmpl)+#endif /* _WIN32 */+#ifndef getenv_utf8+#define getenv_utf8(name) getenv(name)+#endif+/* --- compat_aligned_free su piattaforme diverse da Windows ---* Su Linux/macOS, posix_memalign usa free() normale. */#ifndef compat_aligned_free