[Gambas-user] Issue 95 in gambas: FOR-optimization not correct

gambas at ...2524... gambas at ...2524...
Wed Aug 31 21:11:36 CEST 2011


Status: New
Owner: ----
Labels: Version Type-Bug Priority-Medium OpSys-Any Dist-Any Arch-Any  
Desktop-Any GUI-Any

New issue 95 by emil.len... at ...626...: FOR-optimization not correct
http://code.google.com/p/gambas/issues/detail?id=95

1) Describe the problem.
Every time a FOR begins, the code is modified depending on the sign of the  
Step-variable, so it doesn't have to check in every iteration whether a <=  
b or a >= b should be tested.
The problem appears if something between For and Next calls the same  
function recursively, so the sign of the Step-variable differs.
When that happens, the interpreter overwrites the old step-sign, and does  
not restore the old one. That will introduce an error when the function  
returns and the next for-iteration runs.
A possible fix would be that the sign is stored on some stack, maybe as a  
control-value like the "With".

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK
Revision: r4067
Operating system: Linux
Architecture: x86_64

3) Provide a little project that reproduces the bug or the crash.
Public Sub TheLoop(n As Integer)
   Dim i As Integer
   For i = Choose(n, 10, 1) To Choose(n, 1, 10) Step Choose(n, -1, 1)
     Print i
     If i = 1 And n = 1 Then TheLoop(2)
   Next
   Print i
End

Start the function with TheLoop(1), which will print:
10
9
8
7
6
5
4
3
2
1
1
2
3
4
5
6
7
8
9
10
11
0
-1
-2
-3
-4
-5
-6
-7
... until it wraps and i becomes >= 1.

4) If your project needs a database, try to provide it, or part of it.

5) Explain clearly how to reproduce the bug or the crash.
Run the example

6) By doing that carefully, you have done 50% of the bug fix job!





More information about the User mailing list