From 03d63424f3034c34d61fe0f654e05d20c9eded89 Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Wed, 27 Apr 2005 09:48:34 +0000
Subject: [PATCH] [project @ 2005-04-27 09:48:34 by simonmar] Remove uses of
 stderr from .cmm code.

We can't reliably refer to stdin/stdout/stderr from .cmm, because the
C standard doesn't specify whether stderr is a variable or a macro.
---
 ghc/rts/Apply.cmm          | 2 +-
 ghc/rts/Exception.cmm      | 2 +-
 ghc/rts/HeapStackCheck.cmm | 2 +-
 ghc/rts/PrimOps.cmm        | 2 +-
 ghc/rts/Profiling.c        | 7 +++++++
 ghc/rts/Profiling.h        | 1 +
 6 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ghc/rts/Apply.cmm b/ghc/rts/Apply.cmm
index 1fe444e3f9c..e4197ecb49b 100644
--- a/ghc/rts/Apply.cmm
+++ b/ghc/rts/Apply.cmm
@@ -41,7 +41,7 @@ INFO_TABLE_RET( stg_ap_0,
     // fn is in R1, no args on the stack
 
     IF_DEBUG(apply,
-	foreign "C" fprintf(W_[stderr] "ptr", stg_ap_0_ret_str);
+	foreign "C" debugBelch(stg_ap_0_ret_str);
 	foreign "C" printClosure(R1 "ptr"));
 
     IF_DEBUG(sanity,
diff --git a/ghc/rts/Exception.cmm b/ghc/rts/Exception.cmm
index f8d305efd81..6192f6d7763 100644
--- a/ghc/rts/Exception.cmm
+++ b/ghc/rts/Exception.cmm
@@ -330,7 +330,7 @@ raisezh_fast
      * the info was only displayed for an *uncaught* exception.
      */
     if (RtsFlags_ProfFlags_showCCSOnException(RtsFlags)) {
-      foreign "C" fprintCCS(W_[stderr] "ptr",W_[CCCS] "ptr");
+      foreign "C" fprintCCS_stderr(W_[CCCS] "ptr");
     }
 #endif
 
diff --git a/ghc/rts/HeapStackCheck.cmm b/ghc/rts/HeapStackCheck.cmm
index 90b11589036..db4af25db8d 100644
--- a/ghc/rts/HeapStackCheck.cmm
+++ b/ghc/rts/HeapStackCheck.cmm
@@ -611,7 +611,7 @@ __stg_gc_fun
         Sp(2) = R1;
         Sp(1) = size;
         Sp(0) = stg_gc_fun_info;
-        // DEBUG_ONLY(foreign "C" fprintf(stderr, "stg_fun_gc_gen(ARG_GEN)"););
+        // DEBUG_ONLY(foreign "C" debugBelch("stg_fun_gc_gen(ARG_GEN)"););
         GC_GENERIC
     } else { 
 	jump W_[stg_stack_save_entries + WDS(type)];
diff --git a/ghc/rts/PrimOps.cmm b/ghc/rts/PrimOps.cmm
index 7cb1aaf9c09..cfdaca604cf 100644
--- a/ghc/rts/PrimOps.cmm
+++ b/ghc/rts/PrimOps.cmm
@@ -289,7 +289,7 @@ mkWeakzh_fast
   StgWeak_link(w)	= W_[weak_ptr_list];
   W_[weak_ptr_list] 	= w;
 
-  IF_DEBUG(weak, foreign "C" fprintf(W_[stderr] "ptr",stg_weak_msg,w));
+  IF_DEBUG(weak, foreign "C" debugBelch(stg_weak_msg,w));
 
   RET_P(w);
 }
diff --git a/ghc/rts/Profiling.c b/ghc/rts/Profiling.c
index b9900f51c02..028dc5a5091 100644
--- a/ghc/rts/Profiling.c
+++ b/ghc/rts/Profiling.c
@@ -916,6 +916,13 @@ fprintCCS( FILE *f, CostCentreStack *ccs )
   fprintf(f,">");
 }
 
+/* For calling from .cmm code, where we can't reliably refer to stderr */
+void
+fprintCCS_stderr( CostCentreStack *ccs )
+{
+    fprintCCS(stderr, ccs);
+}
+
 #ifdef DEBUG
 void
 debugCCS( CostCentreStack *ccs )
diff --git a/ghc/rts/Profiling.h b/ghc/rts/Profiling.h
index 7ed7bdc6a06..4b669893088 100644
--- a/ghc/rts/Profiling.h
+++ b/ghc/rts/Profiling.h
@@ -27,6 +27,7 @@ void PrintNewStackDecls ( void );
 extern lnat RTS_VAR(total_prof_ticks);
 
 extern void fprintCCS( FILE *f, CostCentreStack *ccs );
+extern void fprintCCS_stderr( CostCentreStack *ccs );
 
 #ifdef DEBUG
 extern void debugCCS( CostCentreStack *ccs );
-- 
GitLab