# HG changeset patch # User Richard M. Stallman # Date 681855243 0 # Node ID 34ec8957c6c030584bfb619bd8660157e8b452a4 # Parent 2e8bb7220c751dbf8d4fd9f2daf16a1a5353ec77 *** empty log message *** diff -r 2e8bb7220c75 -r 34ec8957c6c0 src/print.c --- a/src/print.c Fri Aug 09 00:38:03 1991 +0000 +++ b/src/print.c Sat Aug 10 20:14:03 1991 +0000 @@ -41,6 +41,10 @@ /* Avoid actual stack overflow in print. */ int print_depth; +/* Detect most circularities to print finite output. */ +#define PRINT_CIRCLE 200 +Lisp_Object being_printed[PRINT_CIRCLE]; + /* Maximum length of list to print in full; noninteger means effectively infinity */ @@ -651,9 +655,27 @@ QUIT; +#if 1 /* I'm not sure this is really worth doing. */ + /* Detect circularities and truncate them. + No need to offer any alternative--this is better than an error. */ + if (XTYPE (obj) == Lisp_Cons || XTYPE (obj) == Lisp_Vector + || XTYPE (obj) == Lisp_Compiled) + { + int i; + for (i = 0; i < print_depth; i++) + if (EQ (obj, being_printed[i])) + { + sprintf (buf, "#%d", i); + strout (buf, -1, printcharfun); + return; + } + } +#endif + + being_printed[print_depth] = obj; print_depth++; - if (print_depth > 200) + if (print_depth > PRINT_CIRCLE) error ("Apparently circular structure being printed"); #ifdef MAX_PRINT_CHARS if (max_print && print_chars > max_print) @@ -783,6 +805,9 @@ if (XTYPE (Vprint_length) == Lisp_Int) max = XINT (Vprint_length); + /* Could recognize circularities in cdrs here, + but that would make printing of long lists quadratic. + It's not worth doing. */ while (CONSP (obj)) { if (i++)