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

PyLong_As* methods should not call nb_int. #51799

Closed
mdickinson opened this issue Dec 20, 2009 · 4 comments
Closed

PyLong_As* methods should not call nb_int. #51799

mdickinson opened this issue Dec 20, 2009 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@mdickinson
Copy link
Member

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']

@mdickinson
Copy link
Member Author

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.

@mdickinson mdickinson added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 20, 2009
@mdickinson
Copy link
Member Author

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

@mdickinson
Copy link
Member Author

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.

@mdickinson
Copy link
Member Author

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.

@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)
Projects
None yet
Development

No branches or pull requests

1 participant