]> birchwood-abbey.net Git - mit-scheme.git/commitdiff
microcode: Fix bug in writing ucode stack traces to file.
authorTaylor R Campbell <campbell+mit-scheme@mumble.net>
Tue, 28 Dec 2021 12:04:58 +0000 (12:04 +0000)
committerTaylor R Campbell <campbell+mit-scheme@mumble.net>
Fri, 10 Jun 2022 15:08:24 +0000 (15:08 +0000)
In the v15 microcode merge, the type-abuse of casting a FILE * to
outf_channel was dropped, and thus so was the `C-c t' function's file
output at the console.

Do this is a slightly less abusive way that works with modern C and
modern platforms where enums are not necessarily wide enough, or
allowed by the semantics, to hold pointers.

(cherry picked from commit 350be6720bce76eec23b551c720adc3570c0a608)

src/microcode/outf.c
src/microcode/outf.h
src/microcode/uxsig.c

index a88b0839c571724adbcc4a9226d0cbd56680ac0c..af75a9a2dc2a18ed8521832ff7c1309dfcd745f8 100644 (file)
@@ -48,6 +48,16 @@ USA.
 #  include "ntscreen.h"
    extern HANDLE master_tty_window;
 #endif
+
+outf_channel CONSOLE_OUTPUT = { .type = OUTF_CONSOLE };
+outf_channel ERROR_OUTPUT = { .type = OUTF_ERROR };
+outf_channel FATAL_OUTPUT = { .type = OUTF_FATAL };
+
+outf_channel
+FILE_OUTPUT (FILE * fp)
+{
+  return ((outf_channel) { .type = OUTF_FILE, .cookie = fp });
+}
 \f
 void
 outf (outf_channel chan, const char * format, ...)
@@ -61,22 +71,24 @@ outf (outf_channel chan, const char * format, ...)
 void
 voutf (outf_channel chan, const char * format, va_list ap)
 {
-  switch (chan)
+  switch (chan.type)
     {
-    case CONSOLE_OUTPUT: voutf_console (format, ap); break;
-    case ERROR_OUTPUT: voutf_error (format, ap); break;
-    case FATAL_OUTPUT: voutf_fatal (format, ap); break;
+    case OUTF_CONSOLE: voutf_console (format, ap); break;
+    case OUTF_ERROR: voutf_error (format, ap); break;
+    case OUTF_FATAL: voutf_fatal (format, ap); break;
+    case OUTF_FILE: vfprintf ((chan.cookie), format, ap); break;
     }
 }
 
 void
 outf_flush (outf_channel chan)
 {
-  switch (chan)
+  switch (chan.type)
     {
-    case CONSOLE_OUTPUT: outf_flush_console (); break;
-    case ERROR_OUTPUT: outf_flush_error (); break;
-    case FATAL_OUTPUT: outf_flush_fatal (); break;
+    case OUTF_CONSOLE: outf_flush_console (); break;
+    case OUTF_ERROR: outf_flush_error (); break;
+    case OUTF_FATAL: outf_flush_fatal (); break;
+    case OUTF_FILE: fflush (chan.cookie); break;
     }
 }
 
index 3c35d12321e6e74ec571f5a57f59b23bbc451b41..e55c2ad73324dee2f541359f26b9e03c11789404 100644 (file)
@@ -29,7 +29,18 @@ USA.
 
 #include "config.h"
 
-typedef enum { CONSOLE_OUTPUT, ERROR_OUTPUT, FATAL_OUTPUT } outf_channel;
+#include <stdio.h>
+
+typedef struct
+{
+  enum { OUTF_CONSOLE, OUTF_ERROR, OUTF_FATAL, OUTF_FILE } type;
+  void * cookie;
+} outf_channel;
+
+extern outf_channel CONSOLE_OUTPUT;
+extern outf_channel ERROR_OUTPUT;
+extern outf_channel FATAL_OUTPUT;
+extern outf_channel FILE_OUTPUT (FILE *);
 
 extern void outf (outf_channel, const char *, ...)
   ATTRIBUTE ((__format__ (__printf__, 2, 3)));
index 75e5e9cf379b4555b564e0c4375c249510bd6d45..f8089ae79b68f4e4739d28acc9f49d6243d0fc45 100644 (file)
@@ -1194,7 +1194,7 @@ interactive_back_trace (void)
       outf_console ("Writing the stack trace to file \"%s\" -- ",
                     &input_string[0]);
       outf_flush_console ();
-      debug_back_trace ((outf_channel) to_dump);
+      debug_back_trace (FILE_OUTPUT (to_dump));
       outf_console ("Done.\n");
       outf_flush_console ();
     }