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

The range for xrange() is too narrow on Windows 64-bit #70615

Closed
serhiy-storchaka opened this issue Feb 24, 2016 · 7 comments
Closed

The range for xrange() is too narrow on Windows 64-bit #70615

serhiy-storchaka opened this issue Feb 24, 2016 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 26428
Nosy @brettcannon, @mdickinson, @vstinner, @benjaminp, @serhiy-storchaka, @eryksun
Files
  • xrange_py_ssize_t.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 = None
    closed_at = <Date 2016-02-24.20:00:26.659>
    created_at = <Date 2016-02-24.16:40:45.039>
    labels = ['interpreter-core', 'type-bug']
    title = 'The range for xrange() is too narrow on Windows 64-bit'
    updated_at = <Date 2016-02-24.21:29:50.128>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2016-02-24.21:29:50.128>
    actor = 'eryksun'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-02-24.20:00:26.659>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-02-24.16:40:45.039>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['42022']
    hgrepos = []
    issue_num = 26428
    keywords = ['patch']
    message_count = 7.0
    messages = ['260816', '260820', '260822', '260829', '260831', '260833', '260834']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'mark.dickinson', 'vstinner', 'benjamin.peterson', 'serhiy.storchaka', 'eryksun']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26428'
    versions = ['Python 2.7']

    @serhiy-storchaka
    Copy link
    Member Author

    The xrange() object works with integers in the range of C long, not Py_ssize_t. Thus the idiomatic expression xrange(len(seq)) can fail for real sequences if sys.maxint < sys.maxsize (e.g on 64-bit Windows).

    Proposed patch changes the xrange() implementation to use Py_ssize_t instead of C long.

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 24, 2016
    @vstinner
    Copy link
    Member

    (e.g on 64-bit Windows)

    Platforms with sizeof(long) < sizeof(size_t), I only know one platform: Windows 64-bit.

    Since this change only impacts Windows 64-bit, we must compile (to check for compilation warnings) and run tests with this patch on Windows 64-bit.

    Many other similar issues has been fixed in Python 3. I'm not sure that it's worth to spend too much time on supporting the full 64-bit range on Python 2, it's almost a new feature no?

    Examples:

    • issue bpo-9611: FileIO not 64-bit safe under Windows (Python 2 fixed)
    • issue bpo-9566: Compilation warnings under x64 Windows (not fixed in Python 2)
    • issue bpo-16367: io.FileIO.readall() is not 64-bit safe on Windows (Python 2 fixed)
    • issue bpo-17931: PyLong_FromPid() is not correctly defined on Windows 64-bit (not fixed in Python 2?)
    • issue bpo-15792: Fix compiler options for x64 builds on Windows (not fixed in Python 2)
    • etc.

    @vstinner vstinner changed the title The range for xrange() is too narrow The range for xrange() is too narrow on Windows 64-bit Feb 24, 2016
    @mdickinson
    Copy link
    Member

    I hate to say it, but I think this would count as an enhancement rather than a bugfix: there's nothing documented about the range of xrange.

    @brettcannon
    Copy link
    Member

    I agree that it's a new feature since xrange() still functions if you give it a value larger than long (right?) and there's nothing saying it has to support the full size of an index.

    @eryksun
    Copy link
    Contributor

    eryksun commented Feb 24, 2016

    xrange() still functions if you give it a value larger than long

    What do you mean? Did you mean to write range() instead of xrange()? Both range and xrange in Python 2 use a C long for the start, stop, step, and length values. With how they get used this generally isn't a problem, which is why no one previously created an issue for this.

    @brettcannon
    Copy link
    Member

    No, I meant to write xrange(). My point is there is no crasher if this change didn't occur.

    @eryksun
    Copy link
    Contributor

    eryksun commented Feb 24, 2016

    No, I meant to write xrange(). My point is there is no crasher
    if this change didn't occur.

    Oh, by 'still functions' you meant that it doesn't cause an access violation that crashes the process, as opposed to raising an OverflowError that can be handled.

    @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) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants