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

Using size_t where appropriate #41714

Closed
loewis mannequin opened this issue Mar 18, 2005 · 4 comments
Closed

Using size_t where appropriate #41714

loewis mannequin opened this issue Mar 18, 2005 · 4 comments

Comments

@loewis
Copy link
Mannequin

loewis mannequin commented Mar 18, 2005

BPO 1166195
Nosy @loewis
Files
  • size_t.diff
  • ssize_t.diff.gz: Version 2 (PyCon)
  • 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 2006-04-15.07:15:32.000>
    created_at = <Date 2005-03-18.19:59:12.000>
    labels = []
    title = 'Using size_t where appropriate'
    updated_at = <Date 2006-04-15.07:15:32.000>
    user = 'https://github.com/loewis'

    bugs.python.org fields:

    activity = <Date 2006-04-15.07:15:32.000>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['None']
    creation = <Date 2005-03-18.19:59:12.000>
    creator = 'loewis'
    dependencies = []
    files = ['6550', '6551']
    hgrepos = []
    issue_num = 1166195
    keywords = ['patch']
    message_count = 4.0
    messages = ['47994', '47995', '47996', '47997']
    nosy_count = 1.0
    nosy_names = ['loewis']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1166195'
    versions = []

    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented Mar 18, 2005

    This patch is (a first draft of) an attempt to make
    Python properly use size_t where necessary. This work
    is triggered by compilation on Win64 (where the
    compiler warns about potential truncation errors a
    lot). The rationale for the patch is that size_t might
    be larger than int, in particular on 64-bit platforms,
    and that the size of a memory chunk cannot reliably be
    measured with an int.

    It turns out that using size_t is not enough, since
    values can sometimes also be negative. For these cases,
    a "signed" size_t is used, which is called Py_ssize_t
    and is a define for ssize_t if the compiler supports
    the latter.

    The guideline for converting int to size_t used in this
    patch is this:

    • if the variable is meant to store the number of
      bytes, and is always guaranteed to be positive, and
      could get arbitrarily large, use size_t
    • if the value could be negative also, use ssize_t
    • if the value is meant to store a number of "things",
      but this directly translates into size_t (e.g. number
      of pointers, number of characters), also use size_t/ssize_t
    • if the value is in a range limited to 32-bit int
      (e.g. the number of characters in a path name), convert
      the size_t to int, after asserting that the value
      really is in the range.

    This version is work in progress, and needs review. I
    hope to work on it during the sprints at PyConDC.

    @loewis loewis mannequin closed this as completed Mar 18, 2005
    @loewis loewis mannequin closed this as completed Mar 18, 2005
    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented May 6, 2005

    Logged In: YES
    user_id=21627

    Second version of the patch attached (PyCon version). It turns out that
    changing everything from signed to unsigned breaks too many things, so
    this version of the patch uses Py_ssize_t in nearly all places.

    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented Dec 17, 2005

    Logged In: YES
    user_id=21627

    This patch is now maintained in

    http://svn.python.org/projects/python/branches/ssize_t/

    @loewis
    Copy link
    Mannequin Author

    loewis mannequin commented Apr 15, 2006

    Logged In: YES
    user_id=21627

    And now it is part of the trunk.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants