emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Apparently circular structure being printed"


From: Seweryn
Subject: Re: "Apparently circular structure being printed"
Date: Tue, 9 Nov 2010 07:49:43 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Sam Steingold <sds <at> gnu.org> writes:

> 
> GNU Emacs 24.0.50.4 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
>  of 2010-11-07 on sysu76
>  '--with-x-toolkit=gtk'
> 
> In an nXML buffer:
> C-h v rng-compile-table RET
> 
> I get an error in the *Messages* buffer:
> 
> Entering debugger...
> debugger-setup-buffer: Apparently circular structure being printed
> 
> no *Backtrace* buffer is created.
> my print-circle is t.
> 

I get the same error with predictive package [1].

Here are steps to reproduce it:
1) Open an arbitrary text file.txt
2) M-x predictive-mode (my rpg-dictionary is loaded)
3) predictive-add-to-dict <- "Very longgggggg string"
(I want to add the expression in qutes, of course without quotes)
4) predictive-save-dict (OK)
5) predictive-add-to-dict <- "Very veryyyyyy longggggggggggggg stringgggggggg"
6) I get the message in echo area: "Entering debugger...
debugger-setup-buffer: Apparently circular structure being printed"
7) No *Backtrace*

The Author of predictive package wrote me as follows:

"This enabled me to reproduce the issue, and I
remember now what it is that causes this. It has nothing to do with
special characters (the predictive-mode dictionaries can store arbitrary
strings). It's to do with the *length* of the string you're trying to
store.

Unfortunately, Emacs has an undocumented, hard-coded limit on the depth
of a Lisp list structure, beyond which it considers the structure to be
circular and refuses to print it, throwing the "Apparently circular
structure" error. This limit only applies to printing such structures;
Emacs will happily work with deeply nested structures in all other
circumstances. But predictive-mode uses the Lisp printing functions to
write the dictionaries to file, hence the error when saving.

It's not unreasonable to impose a depth limit on printing, as it guards
against hanging in a tight loop if you inadvertently ask Emacs to
printing a circular list structure. However, it's unfortunate that this
limit is hard-coded. Other similar Emacs limits can be changed by
modifying a variable in Elisp, but not this one. The vast majority of
Elisp code only uses very simple data structures, and the Emacs devs
didn't have predictive-mode in mind when they arbitrarily chose the value
for this print-depth limit, so it's set rather conservatively.

The practical consequence is that standard Emacs will bork on saving
dictionaries containing strings longer than about 45 characters. There is
a patch included in the predictive package (print.c.diff) [2] which increases
this limit by a factor of 5. (If you envisage storing even longer
strings, you could increase this even further. The required modification
should be obvious from the patch file.) But obviously this requires
patching and compiling the Emacs source yourself, which is possible but
maybe not so easy under Windows."

Regards,
Seweryn


[1] http://www.emacswiki.org/emacs/PredictiveMode or
http://www.dr-qubit.org/emacs.php#predictive

[2]
<code>
--- print.c     2008-10-24 11:18:33.000000000 +0100
+++ print.c.new 2008-10-24 11:19:27.000000000 +0100
@@ -88,7 +88,7 @@
 int new_backquote_output;
 
 /* Detect most circularities to print finite output.  */
-#define PRINT_CIRCLE 200
+#define PRINT_CIRCLE 1000
 Lisp_Object being_printed[PRINT_CIRCLE];
 
 /* When printing into a buffer, first we put the text in this
</code>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]