fix: set stdout to O_BINARY on Windows to prevent READY sentinel corruption
Both sentinels in c/coli (READY and END) end with \n. Under CRT text mode on Windows, printf() translates \n to \r\n, so the engine emits \x01\x01READY\x01\x01\r\n. The Python coli wrapper checks endswith(SENTINEL) which expects bare \n — the match never fires and chat hangs forever. _setmode(fileno(stdout), O_BINARY) at engine startup switches stdout to binary mode so \n passes through unchanged. This matches the belt-and-braces reasoning already in compat.h:88 (O_BINARY for file I/O). The fix is defense-in-depth: on the documented w64devkit/MinGW build path, CRT text mode may or may not apply depending on how the terminal is attached, so this ensures correctness regardless. Note: I was unable to compile-test this on the full codebase because glm.c uses POSIX-only symbols (mmap, madvise, select, fd_set, struct stat/fstat) that are unavailable on Windows without platform guards. The codebase compiles on Linux (Ubuntu 24.04, GCC 13) and macOS (Apple clang). Windows compilation requires wrapping those POSIX calls in #if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__) guards — I opened this as a separate concern for the maintainer.
This commit is contained in:
@@ -5749,6 +5749,9 @@ int main(int argc, char **argv){
|
||||
perror("[OMP] execv self-reexec failed, running untuned");
|
||||
#endif
|
||||
}
|
||||
#ifdef _WIN32
|
||||
_setmode(fileno(stdout), O_BINARY);
|
||||
#endif
|
||||
#if defined(__AVX512F__) && defined(__AVX512BW__)
|
||||
if(getenv("I4_ACC512")) g_i4_acc512=atoi(getenv("I4_ACC512"))!=0;
|
||||
if(getenv("I4_ACC512_TEST")){
|
||||
|
||||
Reference in New Issue
Block a user