Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in optimization of range #763

Closed
robertwb opened this issue Jan 30, 2009 · 11 comments
Closed

Bug in optimization of range #763

robertwb opened this issue Jan 30, 2009 · 11 comments

Comments

@robertwb
Copy link
Contributor

This:

   cdef int i, n
    n = 10
    for i in range(n):
        if i == 5: n *= 2
    print i

prints out 20.

Migrated from http://trac.cython.org/ticket/203

@robertwb
Copy link
Contributor Author

@dagss commented

It should print 9, I think

@robertwb
Copy link
Contributor Author

@dagss commented

Note: This must be changed in the for in range-optimization, because "for 0 <= i < n" should have this semantics!

@robertwb
Copy link
Contributor Author

robertwb commented Feb 1, 2009

@dagss changed milestone from 0.11 to 0.11.1
commented

@robertwb
Copy link
Contributor Author

@dagss changed owner from somebody to Prajwal Suhas P
commented

@robertwb
Copy link
Contributor Author

@robertwb changed resolution to fixed
status from new to closed
commented

Works as expected. Committed http://hg.cython.org/cython-devel/rev/620326b14c3f

This is another reason to keep the for...from syntax though.

@robertwb
Copy link
Contributor Author

@robertwb changed component from Optimization to Python Semantics
commented

@robertwb
Copy link
Contributor Author

robertwb commented Mar 15, 2009

@robertwb commented

This is a dupe of http://trac.cython.org/ticket/196, the above commit was for http://trac.cython.org/ticket/208.

@robertwb
Copy link
Contributor Author

@dagss changed resolution from fixed to empty
status from closed to reopened
commented

No, this is a different bug. Reopening.

Also note that this ticket is assigned to Prajwal Suhas P; see http://thread.gmane.org/gmane.comp.python.cython.devel/4775

Magnus' patch was only for incrementing-one-to-far; this is about evaluating the endpoints to range once per loop.

Also consider this test case:

"""
 >>> f()
g called
0
1
2
2
"""

cdef int g():
     print "g called"
     return 3

def f():
     cdef int i
     for i in range(g()):
         print i
     print i

@robertwb
Copy link
Contributor Author

@dagss commented

That is; I get:

Failed example:
    f()
Expected:
    g called
    0
    1
    2
    2
Got:
    g called
    0
    g called
    1
    g called
    2
    g called
    2

@robertwb
Copy link
Contributor Author

@dagss changed priority from major to critical
commented

@robertwb
Copy link
Contributor Author

robertwb commented Mar 25, 2009

@robertwb changed resolution to fixed
status from reopened to closed
commented

Finally resolved by http://trac.cython.org/ticket/243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant