# HG changeset patch # User Richard M. Stallman # Date 896113682 0 # Node ID 35af9a27627255ea81d86fb538d018df68ba3e24 # Parent 32f2adf05397e598e7d76b5b61946c936bafa55d (print) : Detect circular list. diff -r 32f2adf05397 -r 35af9a276272 src/print.c --- a/src/print.c Mon May 25 16:03:58 1998 +0000 +++ b/src/print.c Mon May 25 16:28:02 1998 +0000 @@ -1418,14 +1418,20 @@ { register int i = 0; register int print_length = 0; + Lisp_Object halftail = obj; if (INTEGERP (Vprint_length)) print_length = 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)) { + /* Detect circular list. */ + if (i != 0 && EQ (obj, halftail)) + { + sprintf (buf, " . #%d", i / 2); + strout (buf, -1, -1, printcharfun, 0); + obj = Qnil; + break; + } if (i++) PRINTCHAR (' '); if (print_length && i > print_length) @@ -1435,6 +1441,8 @@ } print (XCAR (obj), printcharfun, escapeflag); obj = XCDR (obj); + if (!(i & 1)) + halftail = XCDR (halftail); } } if (!NILP (obj))