~ chicken-core (master) a90a1d408614d5d39013488b50df7d2d4ddcd1a2
commit a90a1d408614d5d39013488b50df7d2d4ddcd1a2
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Mon Jul 13 15:38:22 2026 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Mon Jul 13 15:38:22 2026 +0200
flush files in cleanup routine before normal exit.
Removing C_fflush(NULL) previously resulted in unwritten output being
dropped (reported by Kon). But since we need a non-flushing exit for
"emergency-exit", we move the flushing to the default cleanup procedure.
diff --git a/dbg-stub.c b/dbg-stub.c
index 10290f0f..63e8c91a 100644
--- a/dbg-stub.c
+++ b/dbg-stub.c
@@ -210,6 +210,7 @@ terminate(char *msg)
{
fprintf(stderr, "%s\n", msg);
socket_close();
+ C_fflush(NULL);
C_exit_runtime(C_fix(1));
}
diff --git a/library.scm b/library.scm
index 7ab5c509..01e57d4d 100644
--- a/library.scm
+++ b/library.scm
@@ -69,6 +69,8 @@
#define C_a_get_current_seconds(ptr, c, dummy) C_int64_to_num(ptr, time(NULL))
#define C_peek_c_string_at(ptr, i) ((C_char *)(((C_char **)ptr)[ i ]))
+#define C_flush_all_files(dummy) (C_fflush(NULL), C_SCHEME_UNDEFINED)
+
static C_word
fast_read_line_from_file(C_word str, C_word port, C_word size) {
int n = C_unfix(size);
@@ -6001,6 +6003,7 @@ EOF
(define (cleanup-before-exit)
(set! exit-in-progress #t)
+ (##core#inline "C_flush_all_files" #f)
(when (##core#inline "C_i_dump_heap_on_exitp")
(##sys#print "\n" #f ##sys#standard-error)
(##sys#dump-heap-state))
diff --git a/runtime.c b/runtime.c
index 004fa449..1a2d6715 100644
--- a/runtime.c
+++ b/runtime.c
@@ -1629,6 +1629,7 @@ void C_ccall termination_continuation(C_word c, C_word *av)
C_dbg(C_text("debug"), C_text("application terminated normally\n"));
}
+ C_fflush(NULL);
C_exit_runtime(C_fix(0));
}
@@ -2759,8 +2760,9 @@ void C_div_by_zero_error(C_char *loc)
void C_unimplemented(C_char *msg)
{
- C_fprintf(C_stderr, C_text("Error: unimplemented feature: %s\n"), msg);
- C_exit_runtime(C_fix(EX_SOFTWARE));
+ C_fprintf(C_stderr, C_text("Error: unimplemented feature: %s\n"), msg);
+ C_fflush(NULL);
+ C_exit_runtime(C_fix(EX_SOFTWARE));
}
void C_not_an_integer_error(C_char *loc, C_word x)
@@ -4625,6 +4627,7 @@ C_word C_halt(C_word msg)
if(dmp != NULL)
C_dbg("", C_text("\n%s"), dmp);
+ C_fflush(NULL);
C_exit_runtime(C_fix(EX_SOFTWARE));
return 0;
}
Trap