Commit 80910267

80910267e8c4Merged

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

Description

Move the allocation-free File/IO handle ops to libspinel_rt.a

Following the sp_gc.c / sp_fiber.c / sp_system.c slimming pattern, move the libc-only File/IO handle ops out of sp_runtime.h into lib/sp_io.c (+ lib/sp_io.h for the sp_File struct and prototypes): File.open, the new IO.pipe support (sp_io_make_pipe / sp_io_fdopen), write, close, closed?, puts, print, flush, eof?, and the fin/scan GC callbacks. They only touch libc plus the external sp_gc_alloc / sp_raise_cls and sp_gc.h's inline sp_mark_string, so they move cleanly and stay perf-neutral (none were inline-hot).

The string-returning readers (gets / read / read_n / path) stay inline in sp_runtime.h: they allocate via the hot static sp_str_alloc, whose per-TU sp_str_heap can't be shared across translation units without externalizing the string heap (a separate, more delicate change). The compiler itself only uses File.read(path) (sp_file_read, also unmoved), so moving the handle ops is bootstrap-safe.

sp_io.c uses _pipe / _O_BINARY (<io.h>/<fcntl.h>) on _WIN32 and pipe / <unistd.h> elsewhere. Wired into libspinel_rt.a + the install set. Gate green (test 861 / bench 57 / optcarrot / self-host fixpoint); IO.pipe + File still work.

Refs #1282.

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

Details

Commit
80910267e8c4
Parent
4f3009ebeb75

MakefilemodifiedView file

@@ -343,9 +343,13 @@
343343 @mkdir -p build
344344 $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib lib/sp_net.c -o build/sp_net.o
345345
346+build/sp_io.o: lib/sp_io.c lib/sp_io.h lib/sp_gc.h lib/sp_types.h
347+ @mkdir -p build
348+ $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib lib/sp_io.c -o build/sp_io.o
349+
346350 SP_RT_LIB = lib/libspinel_rt.a
347351
348-$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o build/sp_time.o build/sp_core.o build/sp_net.o build/sp_system.o build/sp_gc.o build/sp_fiber.o
352+$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o build/sp_time.o build/sp_core.o build/sp_net.o build/sp_system.o build/sp_gc.o build/sp_fiber.o build/sp_io.o
349353 ar rcs $@ $^
350354
351355 regexp: $(SP_RT_LIB)
@@ -821,6 +825,7 @@
821825 install -m 644 lib/sp_system.h $(SPNLDIR)/lib/
822826 install -m 644 lib/sp_gc.h $(SPNLDIR)/lib/
823827 install -m 644 lib/sp_fiber.h $(SPNLDIR)/lib/
828+ install -m 644 lib/sp_io.h $(SPNLDIR)/lib/
824829 install -m 644 lib/sp_time.h $(SPNLDIR)/lib/
825830 install -m 644 lib/sp_net.h $(SPNLDIR)/lib/
826831 install -m 644 lib/*.rb $(SPNLDIR)/lib/