Karim BELABAS on Wed, 11 Sep 2002 23:50:43 +0200 (MEST)

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

Re: gp: forbidden division t_INT / t_STR

On Wed, 11 Sep 2002, Bill Allombert wrote:
> On Mon, Aug 26, 2002 at 07:52:16PM -0400, Michael Somos wrote:
> > pari-dev,
> >
> > This is a puzzling bug because the two definitions of 'calc()' are
> > exactly the same and it is never even used. Note that if it is only
> > defined once, the error does not happen. Very strange indeed.
> > ============================================================================
> Yes. This looks very strange and very serious:
> It is sufficient to do the following to see the bug:
> ? f(x="")=;
> ? f(x="")=;
> ? x
> %1 = ""
> Note that
> ? f(x="")=;
> ? g(x="")=;
> ? x
> %1 = x
> So it looks like a bug in the function redefinition code.
[ sorry for not answering that message sooner, I manage my mailbox in "last
in, first out" mode... ]

Actually, it is a "known bug" that I fixed badly a long time ago (around
1996, I think).

Unfortunately, I also re-introduced the bug (relatively) recently, while
fixing another problem. This entry in anal.c specifically:

  revision 1.49
  date: 2001/02/06 18:33:00;  author: karim;  state: Exp;  lines: +4 -2
  initialize redefine_fun in lis*

Explanation of the problem:

The code is first checked for syntax errors (skip*), then GP reparses
everything (no comment), _executing code as it reads it_. So, here we go:


So, the first time:
f : unknown symbol
( : OK, we're parsing a function. f is unknown. So go to function definition
mode, parse prototype, etc. No problemo.

The second time:
f(   : we're evaluating a known function, read args
x="" : argument is "" (side effect set x to "")
)    : presumably, we're done evaluating. Just to be sure, look ahead:
=    : Ooops (look ahead: '=' not '=='). So we are redefining f after all. Go to
       function redefinition code, etc.

Net side effect x is "".

The old "solution" was to set a global flag in the 'skip' phase, so that the
'run' phase would be aware of the problem.

This was a very bad fix for plenty of reasons (it was even documented, but I
forgot about it).

Better solutions:
1) Re-skip argument block of user functions to make sure we're not redefining

2) junk the parser and use gp2c's.

I vote for (2). But just implemented (1) as a short term solution.

Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathematiques, Bat. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
PARI/GP Home Page: http://www.parigp-home.de/