This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Small patch


Hello,

  during "development" of guile-gettext package I created small patch (against
  guile 1.3.4) which a little bit simplified my work. It adds raw-strings option
  for read-options (and \x sequences are not interpreted) and few features to
  backtrace (display file & line).

  I am not sure whether both changes were done in the right and correct way (my
  experiences in guile internals are not so huge - as a answer to question `What
  means SCM_MEMOIZEDP' I would say `Huh?' :) or whether there is way how to do
  these changes in simpler/cleaner/... way.

  Could someone more enlightened review my changes and accept/reject them or
  tell me what to improve or rewrite?

Thanks,
Dan Skarda

--- guile-1.3.4/libguile/backtrace.c.old	Wed Feb  9 19:23:29 2000
+++ guile-1.3.4/libguile/backtrace.c	Thu Feb 10 01:46:39 2000
@@ -61,6 +61,7 @@
 #include "fluids.h"
 
 #include "backtrace.h"
+#include "filesys.h"
 
 /* {Error reporting and backtraces}
  * (A first approximation.)
@@ -457,6 +458,87 @@
     return SCM_BOOL_F;
 }
 
+static void
+display_backtrace_get_file_line (frame, file, line)
+     SCM frame;
+     SCM *file;
+     SCM *line;
+{
+  SCM source = SCM_FRAME_SOURCE (frame);
+  *file = (SCM_NIMP (source) && SCM_MEMOIZEDP (source))
+    ? scm_source_property (source, scm_sym_filename)
+    : SCM_BOOL_F;
+  *line = (SCM_NIMP (source) && SCM_MEMOIZEDP (source))
+    ? scm_source_property (source, scm_sym_line)
+    : SCM_BOOL_F;
+}
+
+static void
+display_backtrace_file (frame, last_file, port, pstate)
+     SCM frame;
+     SCM *last_file;
+     SCM port;
+     scm_print_state *pstate;
+{
+  SCM file, line;
+
+  display_backtrace_get_file_line (frame, &file, &line);
+
+  if (file == *last_file)
+    return;
+
+  *last_file = file;
+  if (file == SCM_BOOL_F)
+    if (line == SCM_BOOL_F)
+      scm_puts ("<unknown file>\n", port);
+    else
+      scm_puts ("<stdin>\n", port);
+  else
+    {
+      pstate->writingp = 0;
+      scm_iprin1 (file, port, pstate);
+      scm_puts (":\n", port);
+      pstate->writingp = 1;
+    }
+}
+
+static void
+display_backtrace_file_and_line (frame, port, pstate)
+     SCM frame;
+     SCM port;
+     scm_print_state *pstate;
+{
+  SCM file, line;
+
+  display_backtrace_get_file_line (frame, &file, &line);
+  scm_putc (' ', port);
+
+  if (SCM_BACKTRACE_BASE_NAME_P)
+    if (file == SCM_BOOL_F)
+      if (line == SCM_BOOL_F)
+	scm_putc ('?', port);
+      else
+	scm_puts ("<stdin>", port);
+    else
+      {
+	pstate -> writingp = 0;
+	scm_iprin1 ((SCM_NIMP (file) && SCM_STRINGP (file)) 
+		    ? scm_basename (file, SCM_UNDEFINED) 
+		    : file,
+		    port, pstate);
+	pstate -> writingp = 1;
+      }
+
+  if (SCM_BACKTRACE_BASE_NAME_P && SCM_BACKTRACE_LINE_P)
+    scm_putc (':', port);
+
+  if (SCM_BACKTRACE_LINE_P)
+    if (line == SCM_BOOL_F)
+      scm_putc ('?', port);
+    else
+      scm_intprint (SCM_INUM (line) + 1, 10, port);
+}
+
 static void display_frame SCM_P ((SCM frame, int nfield, int indentation, SCM sport, SCM port, scm_print_state *pstate));
 static void
 display_frame (frame, nfield, indentation, sport, port, pstate)
@@ -489,6 +571,10 @@
   /* Real frame marker */
   scm_putc (SCM_FRAME_REAL_P (frame) ? '*' : ' ', port);
 
+  /* display file name and line number */
+  if (SCM_BACKTRACE_LINE_P || SCM_BACKTRACE_BASE_NAME_P)
+    display_backtrace_file_and_line (frame, port, pstate);
+
   /* Indentation. */
   indent (indentation, port);
 
@@ -538,6 +624,7 @@
   int n_frames, beg, end, n, i, j;
   int nfield, indent_p, indentation;
   SCM frame, sport, print_state;
+  SCM last_file;
   scm_print_state *pstate;
 
   a->port = SCM_COERCE_OUTPORT (a->port);
@@ -624,13 +711,16 @@
   /* Print frames. */
   frame = scm_stack_ref (a->stack, SCM_MAKINUM (beg));
   indentation = 1;
-  display_frame (frame, nfield, indentation, sport, a->port, pstate);
-  for (i = 1; i < n; ++i)
+  last_file = SCM_UNDEFINED;
+  for (i = 0; i < n; ++i)
     {
+      if (SCM_BACKTRACE_FULL_NAME_P)
+	display_backtrace_file (frame, &last_file, a->port, pstate);
+
+      display_frame (frame, nfield, indentation, sport, a->port, pstate);
       if (indent_p && SCM_FRAME_EVAL_ARGS_P (frame))
 	++indentation;
       frame = SCM_BACKWARDS_P ? SCM_FRAME_PREV (frame) : SCM_FRAME_NEXT (frame);
-      display_frame (frame, nfield, indentation, sport, a->port, pstate);
     }
 
   return SCM_UNSPECIFIED;
--- guile-1.3.4/libguile/debug.h.old	Sun Sep 12 11:16:13 1999
+++ guile-1.3.4/libguile/debug.h	Wed Feb  9 22:19:48 2000
@@ -81,7 +81,10 @@
 #define SCM_BACKTRACE_P		scm_debug_opts[10].val
 #define SCM_DEVAL_P		scm_debug_opts[11].val
 #define SCM_STACK_LIMIT		scm_debug_opts[12].val
-#define SCM_N_DEBUG_OPTIONS 13
+#define SCM_BACKTRACE_LINE_P	scm_debug_opts[13].val
+#define SCM_BACKTRACE_FULL_NAME_P scm_debug_opts[14].val
+#define SCM_BACKTRACE_BASE_NAME_P scm_debug_opts[15].val
+#define SCM_N_DEBUG_OPTIONS 16
 
 extern SCM (*scm_ceval_ptr) SCM_P ((SCM exp, SCM env));
 
--- guile-1.3.4/libguile/eval.c.old	Sun Sep 12 02:24:10 1999
+++ guile-1.3.4/libguile/eval.c	Wed Feb  9 22:42:43 2000
@@ -1757,7 +1757,10 @@
   { SCM_OPTION_INTEGER, "depth", 20, "Maximal length of printed backtrace." },
   { SCM_OPTION_BOOLEAN, "backtrace", 0, "Show backtrace on error." },
   { SCM_OPTION_BOOLEAN, "debug", 0, "Use the debugging evaluator." },
-  { SCM_OPTION_INTEGER, "stack", 20000, "Stack size limit (measured in words; 0 = no check)." }
+  { SCM_OPTION_INTEGER, "stack", 20000, "Stack size limit (measured in words; 0 = no check)." },
+  { SCM_OPTION_BOOLEAN, "show-line-number", 0, "Show line numbers in backtrace."},
+  { SCM_OPTION_BOOLEAN, "show-full-file-name", 0, "Show full file names in backtrace."},
+  { SCM_OPTION_BOOLEAN, "show-base-file-name", 0, "Show base file names in backtrace."}
 };
 
 scm_option scm_evaluator_trap_table[] = {
--- guile-1.3.4/libguile/read.c.old	Mon Sep 20 23:34:57 1999
+++ guile-1.3.4/libguile/read.c	Wed Feb  9 15:39:37 2000
@@ -66,7 +66,9 @@
   { SCM_OPTION_BOOLEAN, "case-insensitive", 0,
     "Convert symbols to lower case."},
   { SCM_OPTION_SCM, "keywords", SCM_BOOL_F,
-    "Style of keyword recognition: #f or 'prefix"}
+    "Style of keyword recognition: #f or 'prefix"},
+  { SCM_OPTION_BOOLEAN, "raw-strings", 0,
+    "Do not interpret backslashes while reading strings"}
 };
 
 SCM_PROC (s_read_options, "read-options-interface", 0, 1, 0, scm_read_options);
@@ -440,32 +442,38 @@
 	    scm_grow_tok_buf (tok_buf);
 
 	  if (c == '\\')
-	    switch (c = scm_getc (port))
+	    if (SCM_RAW_STRINGS_P)
 	      {
-	      case '\n':
-		continue;
-	      case '0':
-		c = '\0';
-		break;
-	      case 'f':
-		c = '\f';
-		break;
-	      case 'n':
-		c = '\n';
-		break;
-	      case 'r':
-		c = '\r';
-		break;
-	      case 't':
-		c = '\t';
-		break;
-	      case 'a':
-		c = '\007';
-		break;
-	      case 'v':
-		c = '\v';
-		break;
+		SCM_CHARS (*tok_buf)[j++] = '\\';
+		c = scm_getc (port);
 	      }
+	    else
+	      switch (c = scm_getc (port))
+		{
+		case '\n':
+		  continue;
+		case '0':
+		  c = '\0';
+		  break;
+		case 'f':
+		  c = '\f';
+		  break;
+		case 'n':
+		  c = '\n';
+		  break;
+		case 'r':
+		  c = '\r';
+		  break;
+		case 't':
+		  c = '\t';
+		  break;
+		case 'a':
+		  c = '\007';
+		  break;
+		case 'v':
+		  c = '\v';
+		  break;
+		}
 	  SCM_CHARS (*tok_buf)[j] = c;
 	  ++j;
 	}
--- guile-1.3.4/libguile/read.h.old	Sat Feb  6 12:30:48 1999
+++ guile-1.3.4/libguile/read.h	Wed Feb  9 15:28:55 2000
@@ -73,7 +73,8 @@
 #define SCM_RECORD_POSITIONS_P scm_read_opts[1].val
 #define SCM_CASE_INSENSITIVE_P scm_read_opts[2].val
 #define SCM_KEYWORD_STYLE      scm_read_opts[3].val
-#define SCM_N_READ_OPTIONS 4
+#define SCM_RAW_STRINGS_P      scm_read_opts[4].val
+#define SCM_N_READ_OPTIONS 5
 
 
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]