diff --git a/src/print.c b/src/print.c index ac7f164ff1b..6d0033c21f1 100644 --- a/src/print.c +++ b/src/print.c @@ -1325,17 +1325,28 @@ print (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) print_object (obj, printcharfun, escapeflag); } -#define PRINT_CIRCLE_CANDIDATE_P(obj) \ - (STRINGP (obj) \ - || CONSP (obj) \ - || (VECTORLIKEP (obj) \ - && (VECTORP (obj) || CLOSUREP (obj) \ - || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) \ - || HASH_TABLE_P (obj) || FONTP (obj) \ - || RECORDP (obj))) \ - || (! NILP (Vprint_gensym) \ - && SYMBOLP (obj) \ - && !SYMBOL_INTERNED_P (obj))) +static inline bool +print_circle_candidate_p (Lisp_Object obj) +{ + if (CONSP (obj)) + return true; + else if (STRINGP (obj)) + return SCHARS (obj) > 0; + else if (SYMBOLP (obj)) + return !NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj); + else if (VECTORLIKEP (obj)) + { + if (VECTORP (obj)) + return ASIZE (obj) > 0; + else + return (CLOSUREP (obj) + || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) + || HASH_TABLE_P (obj) || FONTP (obj) + || RECORDP (obj)); + } + else + return false; +} /* The print preprocess stack, used to traverse data structures. */ @@ -1423,12 +1434,12 @@ print_preprocess (Lisp_Object obj) eassert (!NILP (Vprint_circle)); /* The ppstack may contain HASH_UNUSED_ENTRY_KEY which is an invalid Lisp value. Make sure that our filter stops us from traversing it. */ - eassert (!PRINT_CIRCLE_CANDIDATE_P (HASH_UNUSED_ENTRY_KEY)); + eassert (!print_circle_candidate_p (HASH_UNUSED_ENTRY_KEY)); ptrdiff_t base_sp = ppstack.sp; for (;;) { - if (PRINT_CIRCLE_CANDIDATE_P (obj)) + if (print_circle_candidate_p (obj)) { if (!HASH_TABLE_P (Vprint_number_table)) Vprint_number_table = CALLN (Fmake_hash_table, QCtest, Qeq); @@ -2286,7 +2297,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) } being_printed[print_depth] = obj; } - else if (PRINT_CIRCLE_CANDIDATE_P (obj)) + else if (print_circle_candidate_p (obj)) { /* With the print-circle feature. */ Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); diff --git a/test/src/print-tests.el b/test/src/print-tests.el index c870427a0a9..0ef47a1d9d8 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el @@ -342,7 +342,10 @@ otherwise, use a different charset." (should (string-match "\\`((a . #[0-9]+) (a . #[0-9]+))\\'" (print-tests--prin1-to-string x)))) (let ((print-circle t)) - (should (equal "(#1=(a . #1#) #1#)" (print-tests--prin1-to-string x)))))) + (should (equal "(#1=(a . #1#) #1#)" (print-tests--prin1-to-string x))))) + (let ((print-circle t)) + (should (equal (print-tests--prin1-to-string '([] "" [] "")) + "([] \"\" [] \"\")")))) (print-tests--deftest print-circle-2 () ;; Bug#31146.