| Ilya Zakharevich on Sun, 8 Sep 2002 14:41:07 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: gp: series bug |
On Sat, Sep 07, 2002 at 10:56:32PM +0200, Karim BELABAS wrote:
> 6) as a funny side effect, the value of precdl = seriesprecision is not
> restored by the error recovery code (polcoeff would have restored it,
> but now the old value is lost for good). Hence
This is a long-standing defect in the error-recovery system.
0) It is not documented how to do error-recovery;
1) The code which makes global-visible changes is not informing the
error-recovery system about these changes.
I propose a two-level system; for most-important fixed-width info one
does not need to inform anybody about any change:
Error-recovery looks like this
PARI_STATE st = PARI_STATE_cur();
switch (setjmp()) ...
PARI_STATE_restore(st);
In addition to storing several important integers (prec etc.),
PARI_STATE stores also a pointer to a linked list of "undo
commands". PARI_STATE_restore() (among other stuff) also "executes"
these commands. One possible flavor of a command is "call the
user-specified function with the user-specified argument"; one can
also have more specialized commands.
The linked list of "undo commands" is anchored at some global
variable; what goes into PARI_STATE is just the "current tail" of this
list.
Now the code which needs to temporary change the global state would do
*the same wrapping*:
PARI_STATE st = PARI_STATE_cur();
prec = ...;
INSTALL_UNDO(set_series_precision, series_precision);
series_precision = ...;
Do something...
PARI_STATE_restore(st);
A similar scheme is used in Perl; it does not slow down things
noticably, and is checked to be scalable.
Yours,
Ilya