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

3.0/3.1: Bad bug in range() computation (or possible Integer problem) #50583

Closed
mfxmfx mannequin opened this issue Jun 24, 2009 · 8 comments
Closed

3.0/3.1: Bad bug in range() computation (or possible Integer problem) #50583

mfxmfx mannequin opened this issue Jun 24, 2009 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@mfxmfx
Copy link
Mannequin

mfxmfx mannequin commented Jun 24, 2009

BPO 6334
Nosy @rhettinger, @mdickinson, @benjaminp, @ezio-melotti
Files
  • issue6334.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/mdickinson'
    closed_at = <Date 2009-06-24.19:24:52.866>
    created_at = <Date 2009-06-24.10:51:41.833>
    labels = ['interpreter-core', 'type-bug', 'release-blocker']
    title = '3.0/3.1: Bad bug in range() computation (or possible Integer problem)'
    updated_at = <Date 2009-06-25.11:31:15.735>
    user = 'https://bugs.python.org/mfxmfx'

    bugs.python.org fields:

    activity = <Date 2009-06-25.11:31:15.735>
    actor = 'mfxmfx'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2009-06-24.19:24:52.866>
    closer = 'mark.dickinson'
    components = ['Interpreter Core']
    creation = <Date 2009-06-24.10:51:41.833>
    creator = 'mfxmfx'
    dependencies = []
    files = ['14355']
    hgrepos = []
    issue_num = 6334
    keywords = ['patch']
    message_count = 8.0
    messages = ['89660', '89661', '89665', '89667', '89669', '89670', '89674', '89702']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'mark.dickinson', 'benjamin.peterson', 'ezio.melotti', 'mfxmfx']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6334'
    versions = ['Python 3.0']

    @mfxmfx
    Copy link
    Mannequin Author

    mfxmfx mannequin commented Jun 24, 2009

    Please note that the correct answer is 25, and the last element is missing !

    This bug does not show on 64-bit versions (but 46337**2 is near 2**31).

    ~Markus

    C:\Python31>python
    Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> len(list(range(46337**2, 46349**2, 46337)))
    24
    
    C:\Python30>python.exe
    Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> len(list(range(46337**2, 46349**2, 46337)))
    24

    @mfxmfx mfxmfx mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jun 24, 2009
    @ezio-melotti
    Copy link
    Member

    Simpler test case:
    Py2.6:
    >>> n = 46349**2
    >>> n
    2148229801L
    >>> range(n-10, n, 3)
    [2148229791L, 2148229794L, 2148229797L, 2148229800L]
    
    Py3.0:
    >>> n = 46349**2
    >>> n
    2148229801
    >>> list(range(n-10, n, 3))
    [2148229791, 2148229794, 2148229797]

    @mdickinson
    Copy link
    Member

    The length calculation in range_iter in Objects/rangeobject.c is
    incorrect, when using a longrangeiterobject. The length is computed
    as: (stop - start)//step. It should be ceiling((stop-start)/step), or
    1 + (stop - start - 1)//step, provided that start <= stop and step > 0.
    It's not clear to me right now whether there may also be problems with
    negative steps, and with cases where start < stop, etc.

    I think this is serious enough to be considered a release blocker for 3.1;
    I'm working on a patch, and will post it later today.

    @mdickinson
    Copy link
    Member

    Here's a patch for py3k.

    There are also a whole bunch of tests that are commented
    out in BuiltinTest.test_range in Lib/test/test_builtin.py.
    Some of those tests fail with the current py3k; with this
    patch applied, they all pass except the one involving 'badzero'.

    @benjaminp
    Copy link
    Contributor

    The patch looks good. Please apply.

    @mdickinson
    Copy link
    Member

    Applied to py3k in r73547. Will backport to 3.0.

    @mdickinson
    Copy link
    Member

    Backported to release30-maint branch in r73549.

    Thanks for catching this, Markus!

    @mfxmfx
    Copy link
    Mannequin Author

    mfxmfx mannequin commented Jun 25, 2009

    Many thanks for your quick fix! ~Markus

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants