Skip to content

PyLong_As* methods should not call nb_int. #51799

Closed

Description

@mdickinson
BPO 7550
Nosy @mdickinson

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 2009-12-21.14:45:18.005>
created_at = <Date 2009-12-20.10:31:12.790>
labels = ['interpreter-core']
title = 'PyLong_As* methods should not call nb_int.'
updated_at = <Date 2009-12-21.14:45:18.003>
user = 'https://github.com/mdickinson'

bugs.python.org fields:

activity = <Date 2009-12-21.14:45:18.003>
actor = 'mark.dickinson'
assignee = 'none'
closed = True
closed_date = <Date 2009-12-21.14:45:18.005>
closer = 'mark.dickinson'
components = ['Interpreter Core']
creation = <Date 2009-12-20.10:31:12.790>
creator = 'mark.dickinson'
dependencies = []
files = []
hgrepos = []
issue_num = 7550
keywords = []
message_count = 4.0
messages = ['96670', '96672', '96678', '96753']
nosy_count = 1.0
nosy_names = ['mark.dickinson']
pr_nums = []
priority = 'normal'
resolution = 'later'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue7550'
versions = ['Python 3.2']

Activity

  1. mdickinson commented on Dec 20, 2009

    @mdickinson
    MemberAuthor

    The following C-API functions:

    PyLong_AsLongAndOverflow
    PyLong_AsUnsignedLongMask
    PyLong_AsLongLong
    PyLong_AsUnsignedLongLongMask

    call nb_int for inputs that don't satisfy PyLong_Check. They thus accept
    floats, Decimal instances, etc. They should probably call nb_index
    instead (or perhaps accept only instances of int).

    The uses of these functions within the Python source should be checked, to
    see what consequences (if any) this change would have for Python
    semantics; it's possible that some of these consequences would fall under
    the moratorium (PEP-3003). In any case, this change probably requires a
    1-release deprecation period.

  2. mdickinson commented on Dec 20, 2009

    @mdickinson
    MemberAuthor

    Since PyLong_AsLong goes through PyLong_AsLongAndOverflow, this change
    would also affect calls to PyLong_AsLong.

  3. mdickinson commented on Dec 20, 2009

    @mdickinson
    MemberAuthor

    Just as an experiment, I removed the calls to nb_int and ran the test-
    suite. The only test failures were in test_ctypes, test_getargs2, and
    test_math.

    The test_math failure was from math.factorial depending on PyLong_AsLong
    to convert floats; I've fixed this in r76916 (trunk) and r76917 (py3k).

    One consequence of not having PyLong_AsLong automatically call nb_int
    would be that math.factorial(decimal.Decimal('-0.53')) is no longer valid.

  4. mdickinson commented on Dec 21, 2009

    @mdickinson
    MemberAuthor

    It turns out this is intimately bound up with the behaviour of
    PyArg_ParseTuple* for integer format codes. Since this behaviour can't
    change until Python 3.3 (because of the moratorium), I'm closing this for
    now.

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions