GNOME Bugzilla – Bug 92131
Recalculating in the wrong order can produce very deep stacks
Last modified: 2013-01-26 17:16:13 UTC
If you drag a cell downwards and the cell contains a formula, Gnumeric quits with a `Illegal instruction' error.
Please supply careful and precise instruction for this. (Of the kind "type XYZ into cell A14", ...) Also, what version?
This error happens with any formula in any cell. For instance, typing `=E2' in E3 and dragging to E30000.
This is somewhat OS specific. This will not occur in all cases only in the case where you create a very deep nested expression. The recalc can then overload the stack on some systems. By filling from E3 -> E30000 we end up recalculating E30000 first which requests E29999 .... 30000 is alot of stack frames I have an idea that might ameliorate the problem in the majority of the cases. In the longer term we probably need to manage the stack manually, but that is tricky in the presence of iterative expressions.
This is the current call pattern:
+ Trace 32406
It can get more ugly in cases with range depends. The collect functions are then going be the start of the nesting. That would make for a significantly deeper stack. However, I doubt that is as common a layout as the cellref case.
A1=1 B1=1 A2=sum(a1:b1)*1 B2=a1 drag A2:B2 down and get a stack like this one...
+ Trace 32444
Leave as a placeholder to get this fixed.
Created attachment 18250 [details] [review] Patch to try.
That patch is untested and needs some configure.in work. But the basics should be right. However, the requested stack size in there is a guess. The patch expands the stack; a real fix would eliminate the very deep recursion.
As mentioned in irc, the patch and various variants do not play nicely with pthreads. Anything linking with gnome-vfs has threading enabled. We'll need to bite the bullet and do a sort of some form.
Created attachment 18492 [details] [review] Entirely new patch
The above patch handles everything but circular dependencies. The only suspect areas are * Handling of names. * Handling of cell ranges. This patch will almost want the range looking for things that need evaluation. Even in the presense of such problems, the patch is safe.
*** Bug 120787 has been marked as a duplicate of this bug. ***
Created attachment 19552 [details] [review] append deps
the proposed patch is dead simple, and does not solve the problem in all cases. It only solves it for the case of f(n) = g(f(n-1)) which seems more common than the converse. We'll need a better solution during 1.3
*** Bug 127202 has been marked as a duplicate of this bug. ***
Comment on attachment 18492 [details] [review] Entirely new patch One of the big speed wins in 1.2 was the removal of double iterating over ranges.
Created attachment 36318 [details] Sample gnumeric file This problem is entirely too easy to trigger. For sample workbook, simply insert a row before A.
*** Bug 161335 has been marked as a duplicate of this bug. ***
Upping priority.
*** Bug 332479 has been marked as a duplicate of this bug. ***
*** Bug 332698 has been marked as a duplicate of this bug. ***
*** Bug 347341 has been marked as a duplicate of this bug. ***
*** Bug 348903 has been marked as a duplicate of this bug. ***
1.7.2 contains code to increase the stack size available for this. That's not a fix, but it should be good enough to handle the most common cases of this problem.
*** Bug 341675 has been marked as a duplicate of this bug. ***
Created attachment 129492 [details] [review] Back-and-forth traversal of dependency list Storing this patch here so it won't get lost. In practical terms, this solves the problem except when someone creates a deep cyclic dependency.
We need a Win32 solution for this. Something like the code in gnm_pre_parse_init to increase the stack size.
This might be relevant: http://sourceforge.net/tracker/index.php?func=detail&aid=1916101&group_id=200665&atid=974439
...or maybe http://makesweet.com/bozo/2008/01/16/compiling-ode-with-mingw-on-linux/
*** Bug 599799 has been marked as a duplicate of this bug. ***
For the record, this was fixed on win32 a while back by asking for a larger stack during linking.
Effectively fixed years ago.