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

longobject.c: minor fixes, cleanups and optimizations #49510

Closed
mdickinson opened this issue Feb 14, 2009 · 4 comments
Closed

longobject.c: minor fixes, cleanups and optimizations #49510

mdickinson opened this issue Feb 14, 2009 · 4 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@mdickinson
Copy link
Member

BPO 5260
Nosy @gpshead, @mdickinson, @pitrou
Files
  • trunk_long_cleanup.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-02-15.11:06:53.327>
    created_at = <Date 2009-02-14.17:44:49.219>
    labels = ['interpreter-core', 'type-bug']
    title = 'longobject.c: minor fixes, cleanups and optimizations'
    updated_at = <Date 2009-02-15.11:06:53.316>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2009-02-15.11:06:53.316>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2009-02-15.11:06:53.327>
    closer = 'mark.dickinson'
    components = ['Interpreter Core']
    creation = <Date 2009-02-14.17:44:49.219>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['13086']
    hgrepos = []
    issue_num = 5260
    keywords = ['patch']
    message_count = 4.0
    messages = ['82095', '82103', '82113', '82149']
    nosy_count = 3.0
    nosy_names = ['gregory.p.smith', 'mark.dickinson', 'pitrou']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5260'
    versions = ['Python 3.1', 'Python 2.7']

    @mdickinson
    Copy link
    Member Author

    Here are various minor portability and standards-compliance fixes,
    optimizations and cleanups for the trunk version of
    Objects/longobject.c. Most of these also apply to py3k.

    I'll admit to an ulterior motive here: the aim is to extract all
    the trivial, non-behaviour-changing pieces of the 30-bit longdigit
    patch (bpo-4258), in order to make that patch easier to review.
    A good few of the changes here are designed to weaken the assumptions
    about the relative sizes of digit, int and long.

    Detailed contents of this patch:

    • make longs smaller by being more careful about tp_basicsize: it's
      defined as offsetof(PyLongObject, ob_digit) instead of the previous
      sizeof(PyLongObject) - sizeof(digit). On average, this saves 2
      bytes per long on 32-bit platforms and 6 bytes per
      long on 64-bit platforms. This is similar to the fix that's already
      in py3k, but more portable since it doesn't make assumptions about
      the amount of padding between the PyVarObject head and the long
      digits.

    • add overflow check in _PyLong_New

    • replace double cast (double -> long -> digit) in PyLong_FromDouble
      with a single double -> digit cast.

    • int -> Py_ssize_t fixes in _PyLong_FromByteArray.

    • fix bogus overflow check in _PyLong_FromByteArray.

    • inline muladd1 into mul1

    • simplify long_hash (without changing its semantics in any way):
      there's no need for the masking when rotating x; everything in
      sight is unsigned and unambiguous.

    • make PyLong_MASK unsigned (of type digit); this is safer, since
      it's used in many bitwise operations.

    • remove wdigit from Include/longintrepr.h; it's no longer used

    • remove some unnecessary forward declarations

    • add a few extra casts to silence compiler warnings from gcc -Wextra

    @mdickinson mdickinson self-assigned this Feb 14, 2009
    @mdickinson mdickinson added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 14, 2009
    @pitrou
    Copy link
    Member

    pitrou commented Feb 14, 2009

    The patch looks good.

    @gpshead
    Copy link
    Member

    gpshead commented Feb 14, 2009

    agreed, looks good. (and thats a good motive)

    @mdickinson
    Copy link
    Member Author

    Thanks, Antoine and Gregory!

    Committed, r69634 and r69635.

    @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

    3 participants