diff src/print.c @ 802:19dfb459d51a

[xemacs-hg @ 2002-04-03 10:47:37 by ben] fix tty problem et al internals/internals.texi: Add section on correctly merging a branch back into the trunk. console-tty.c, eval.c, event-unixoid.c, file-coding.c, file-coding.h, lisp.h, print.c, sysdep.c: Fix data corruption error in print.c from print_depth becoming negative. Borrow primitives internal_bind_int, internal_bind_lisp_object from my stderr-proc ws, soon to be integrated; use them to properly bind print_depth et al. First fix for TTY problem. The basic problem is I switched things so that the TTY I/O is filtered through a coding system, for the support of kterm and such, that speak JIS or similar encodings. (#### I ***swear*** I had this working way back in 19.12.) Anyway, this introduced buffering issues, in which instead of one char being read, it tried to read 1024 chars. I tried setting the stdin descriptor non-blocking, but it doesn't appear to work on Cygwin. (#### Andy, do you know anything about this?) So I fixed it elsewhere. If you get weirdness on the TTY, look in console-tty.c and see how it gets the coding system; maybe there's a way to change it (and if not, there should be!). Also fix warning in sysdep.c.
author ben
date Wed, 03 Apr 2002 10:47:52 +0000
parents a5954632b187
children 6728e641994e
line wrap: on
line diff
--- a/src/print.c	Mon Apr 01 03:59:04 2002 +0000
+++ b/src/print.c	Wed Apr 03 10:47:52 2002 +0000
@@ -762,7 +762,6 @@
   struct gcpro gcpro1, gcpro2;
   GCPRO2 (object, stream);
 
-  print_depth = 0;
   stream = print_prepare (stream, &frame);
   print_internal (object, stream, 1);
   print_finish (stream, frame);
@@ -787,7 +786,6 @@
   struct gcpro gcpro1, gcpro2, gcpro3;
   GCPRO3 (object, stream, result);
 
-  print_depth = 0;
   RESET_PRINT_GENSYM;
   print_internal (object, stream, NILP (noescape));
   RESET_PRINT_GENSYM;
@@ -813,7 +811,6 @@
 
   GCPRO2 (object, stream);
   stream = print_prepare (stream, &frame);
-  print_depth = 0;
   print_internal (object, stream, 0);
   print_finish (stream, frame);
   UNGCPRO;
@@ -834,7 +831,6 @@
 
   GCPRO2 (object, stream);
   stream = print_prepare (stream, &frame);
-  print_depth = 0;
   write_char_internal ("\n", stream);
   print_internal (object, stream, 1);
   write_char_internal ("\n", stream);
@@ -1388,6 +1384,7 @@
 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
   /* This function can GC */
+  int specdepth;
 
   QUIT;
 
@@ -1481,7 +1478,7 @@
     }
 
   being_printed[print_depth] = obj;
-  print_depth++;
+  specdepth = internal_bind_int (&print_depth, print_depth + 1);
 
   if (print_depth > PRINT_CIRCLE)
     signal_error (Qstack_overflow, "Apparently circular structure being printed", Qunbound);
@@ -1610,7 +1607,7 @@
       }
     }
 
-  print_depth--;
+  unbind_to (specdepth);
 }
 
 
@@ -1890,23 +1887,17 @@
 debug_print_no_newline (Lisp_Object debug_print_obj)
 {
   /* This function can GC */
-  int save_print_readably = print_readably;
-  int save_print_depth    = print_depth;
-  Lisp_Object save_Vprint_length = Vprint_length;
-  Lisp_Object save_Vprint_level  = Vprint_level;
-  Lisp_Object save_Vinhibit_quit = Vinhibit_quit;
-  struct gcpro gcpro1, gcpro2, gcpro3;
-  GCPRO3 (save_Vprint_level, save_Vprint_length, save_Vinhibit_quit);
-
-  print_depth = 0;
-  print_readably = debug_print_readably != -1 ? debug_print_readably : 0;
-  print_unbuffered++;
-  /* Could use unwind-protect, but why bother? */
+  int specdepth = internal_bind_int (&print_depth, 0);
+  internal_bind_int (&print_readably,
+		     debug_print_readably != -1 ? debug_print_readably : 0);
+  internal_bind_int (&print_unbuffered, print_unbuffered + 1);
   if (debug_print_length > 0)
-    Vprint_length = make_int (debug_print_length);
+    internal_bind_lisp_object (&Vprint_length, make_int (debug_print_length));
   if (debug_print_level > 0)
-    Vprint_level = make_int (debug_print_level);
-
+    internal_bind_lisp_object (&Vprint_level, make_int (debug_print_level));
+  /* #### Do we need this?  It was in the old code. */
+  internal_bind_lisp_object (&Vinhibit_quit, Vinhibit_quit);
+  
   print_internal (debug_print_obj, Qexternal_debugging_output, 1);
   alternate_do_pointer = 0;
   print_internal (debug_print_obj, Qalternate_debugging_output, 1);
@@ -1915,13 +1906,7 @@
   print_internal (debug_print_obj, Qmswindows_debugging_output, 1);
 #endif
 
-  Vinhibit_quit  = save_Vinhibit_quit;
-  Vprint_level   = save_Vprint_level;
-  Vprint_length  = save_Vprint_length;
-  print_depth    = save_print_depth;
-  print_readably = save_print_readably;
-  print_unbuffered--;
-  UNGCPRO;
+  unbind_to (specdepth);
 }
 
 void
@@ -1937,35 +1922,20 @@
 debug_backtrace (void)
 {
   /* This function can GC */
-  int         old_print_readably = print_readably;
-  int         old_print_depth    = print_depth;
-  Lisp_Object old_print_length   = Vprint_length;
-  Lisp_Object old_print_level    = Vprint_level;
-  Lisp_Object old_inhibit_quit   = Vinhibit_quit;
-
-  struct gcpro gcpro1, gcpro2, gcpro3;
-  GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
-
-  print_depth = 0;
-  print_readably = 0;
-  print_unbuffered++;
-  /* Could use unwind-protect, but why bother? */
+  int specdepth = internal_bind_int (&print_depth, 0);
+  internal_bind_int (&print_readably, 0);
+  internal_bind_int (&print_unbuffered, print_unbuffered + 1);
   if (debug_print_length > 0)
-    Vprint_length = make_int (debug_print_length);
+    internal_bind_lisp_object (&Vprint_length, make_int (debug_print_length));
   if (debug_print_level > 0)
-    Vprint_level = make_int (debug_print_level);
+    internal_bind_lisp_object (&Vprint_level, make_int (debug_print_level));
+  /* #### Do we need this?  It was in the old code. */
+  internal_bind_lisp_object (&Vinhibit_quit, Vinhibit_quit);
 
   Fbacktrace (Qexternal_debugging_output, Qt);
   stderr_out ("\n");
 
-  Vinhibit_quit  = old_inhibit_quit;
-  Vprint_level   = old_print_level;
-  Vprint_length  = old_print_length;
-  print_depth    = old_print_depth;
-  print_readably = old_print_readably;
-  print_unbuffered--;
-
-  UNGCPRO;
+  unbind_to (specdepth);
 }
 
 void