Commit 3fcbfd64

3fcbfd648b3fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Make IO.pipe build on MinGW; add an io_pipe test

The IO.pipe lowering emitted a POSIX pipe(int[2]) call, which MinGW doesn't provide (it exposes _pipe(fds, size, mode) via <io.h>); a program using IO.pipe would fail to compile on the windows-mingw target. Route the syscall through a new sp_io_make_pipe helper that calls _pipe(fds, 65536, _O_BINARY) on WIN32 and pipe(fds) elsewhere, and include <io.h> / <fcntl.h> in the Windows block. fdopen (already used by sp_io_fdopen) and the sp_File* ops are available on MinGW.

Add test/io_pipe.rb so the windows-mingw CI actually exercises the path (class IO + a write/read round-trip through the pipe). Output matches CRuby on Linux; gate green (test/bench/optcarrot/self-host fixpoint).

Refs #1282.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
3fcbfd648b3f
Parent
7372c37f9b9f

lib/sp_runtime.hmodifiedView file

@@ -45,6 +45,8 @@
4545 #include <windows.h>
4646 #include <process.h>
4747 #include <direct.h>
48+#include <io.h> /* _pipe (POSIX pipe(2) is absent on MinGW) */
49+#include <fcntl.h> /* _O_BINARY */
4850 /* POSIX compat shims for MinGW */
4951 #define mmap(a,l,p,f,fd,off) VirtualAlloc(NULL,(l),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE)
5052 #define munmap(a,l) (VirtualFree((a),0,MEM_RELEASE)?0:-1)
@@ -1824,6 +1826,15 @@
18241826 f->mode = mode;
18251827 return f;
18261828 }
1829+/* pipe(2) portability: MinGW exposes _pipe(fds, size, mode) via <io.h>,
1830+ not the POSIX pipe(int[2]). Returns 0 on success, -1 on error. */
1831+static int sp_io_make_pipe(int fds[2]) {
1832+#ifdef _WIN32
1833+ return _pipe(fds, 65536, _O_BINARY);
1834+#else
1835+ return pipe(fds);
1836+#endif
1837+}
18271838 /* IO.pipe end: wrap a raw pipe fd in a GC-managed sp_File so the
18281839 sp_File_* I/O ops work on it. Same finalizer/scan as sp_File_open. */
18291840 static sp_File *sp_io_fdopen(int fd, const char *mode) {