From e17e95a82892b31c8063f2ace1b21c79e82e6f6d Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Wed, 5 Nov 2003 16:20:57 +0000
Subject: [PATCH] * Print a shared textual ATerm if the term if very large. 
 Due to   substitutions, Fix terms are very large when printed as trees (in  
 memory, they are quite compact due to sharing).

---
 src/libnix/expr.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libnix/expr.cc b/src/libnix/expr.cc
index cead80342..9bbe80ab4 100644
--- a/src/libnix/expr.cc
+++ b/src/libnix/expr.cc
@@ -6,13 +6,21 @@
 string printTerm(ATerm t)
 {
     char * s = ATwriteToString(t);
+    if (!s) throw Error("cannot print term");
     return s;
 }
 
 
 Error badTerm(const format & f, ATerm t)
 {
-    return Error(format("%1%, in `%2%'") % f.str() % printTerm(t));
+    char * s = ATwriteToString(t);
+    if (!s) throw Error("cannot print term");
+    if (strlen(s) > 1000) {
+        int len;
+        s = ATwriteToSharedString(t, &len);
+        if (!s) throw Error("cannot print term");
+    }
+    return Error(format("%1%, in `%2%'") % f.str() % (string) s);
 }
 
 
-- 
GitLab