[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread STINNER Victor


STINNER Victor  added the comment:

Thanks Antti Haapala for the bug report and thanks Zackery Spytz for the fix!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 2bfc2dc214445550521074f428245b502d215eac by Victor Stinner 
(Zackery Spytz) in branch '2.7':
[2.7] bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() 
(GH-13860) (GH-13898)
https://github.com/python/cpython/commit/2bfc2dc214445550521074f428245b502d215eac


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread Zackery Spytz


Change by Zackery Spytz :


--
pull_requests: +13773
pull_request: https://github.com/python/cpython/pull/13898

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset e36ed475ea429f7cc80a4d65f80b44686a74b246 by Victor Stinner 
(Zackery Spytz) in branch '3.7':
[3.7] bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() 
(GH-13860) (GH-13896)
https://github.com/python/cpython/commit/e36ed475ea429f7cc80a4d65f80b44686a74b246


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread Zackery Spytz


Change by Zackery Spytz :


--
pull_requests: +13771
pull_request: https://github.com/python/cpython/pull/13896

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset dd492d9c352eb0fa2bc48ea9acc47e47a7fab8a0 by Victor Stinner 
(Zackery Spytz) in branch '3.8':
[3.8] bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() 
(GH-13860) (GH-13891)
https://github.com/python/cpython/commit/dd492d9c352eb0fa2bc48ea9acc47e47a7fab8a0


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-07 Thread Zackery Spytz


Change by Zackery Spytz :


--
keywords: +patch
pull_requests: +13765
pull_request: https://github.com/python/cpython/pull/13891

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset dc2476500d91082f0c907772c83a044bf49af279 by Victor Stinner 
(Zackery Spytz) in branch 'master':
bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() (GH-13860)
https://github.com/python/cpython/commit/dc2476500d91082f0c907772c83a044bf49af279


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Zackery Spytz


Change by Zackery Spytz :


--
nosy: +ZackerySpytz
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread STINNER Victor


STINNER Victor  added the comment:

Python 2.7 - 3.9 are affected. Python 3.6 no longer accept bugfixes.

--
versions:  -Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Mark Dickinson


Change by Mark Dickinson :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Antti Haapala


Antti Haapala  added the comment:

Unsigned long long needs to be at least 64 bits wide, so it is probably all 
32-bit platforms and 64-bit window at least. These functions are not used only 
in a few places within the CPython code and when they are they're guarded with 
`PyLong_Check`s or similar, as they probably should, but the other is part of 
public API

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread STINNER Victor


STINNER Victor  added the comment:

> Victor, as a friendly reminder, (unsigned long)-1 is not necessarily the same 
> number as (unsigned long long)-1. The documentation means the latter.

Aaaah, I didn't notice that the function returns unsigned *long long*, sorry :-)

Which platform is impacted? Windows 64-bit? Does it mean that we have zero unit 
test on this function? Or does it mean that (unsigned long)-1 is compiled 
correctly as (unsigned long long)-1 on Windows 64-bit? Is "long long" 8 bytes 
long and "long" 4 bytes long on Windows 64-bit?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Eric V. Smith


Eric V. Smith  added the comment:

As ztane says, the issue isn't the -1, it's the type of the cast. This looks 
like a legitimate issue to me.

--
nosy: +eric.smith
resolution: not a bug -> 
stage: resolved -> patch review
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Zackery Spytz


Change by Zackery Spytz :


--
pull_requests: +13734
pull_request: https://github.com/python/cpython/pull/13860

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Antti Haapala


Antti Haapala  added the comment:

Victor, as a friendly reminder, (unsigned long)-1 is not necessarily the same 
number as (unsigned long long)-1. The documentation means the latter.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread STINNER Victor


STINNER Victor  added the comment:

-1 is documented: 
https://docs.python.org/dev/c-api/long.html#c.PyLong_AsUnsignedLongLongMask

It's not a bug but a deliberate behavior. See also the general behavior 
described at:
https://docs.python.org/dev/c-api/long.html#integer-objects

--
nosy: +vstinner
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37170] Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall

2019-06-06 Thread Antti Haapala


New submission from Antti Haapala :

Hi, while checking the longobject implementation for a Stack Overflow answer, I 
noticed that the functions `_PyLong_AsUnsignedLongLongMask` and 
`PyLong_AsUnsignedLongLongMask` erroneously return `(unsigned long)-1` on error 
when bad internal call is thrown.

First case: 
https://github.com/python/cpython/blob/cb65202520e7959196a2df8215692de155bf0cc8/Objects/longobject.c#L1379

static unsigned long long
_PyLong_AsUnsignedLongLongMask(PyObject *vv)
{
PyLongObject *v;
unsigned long long x;
Py_ssize_t i;
int sign;

if (vv == NULL || !PyLong_Check(vv)) {
PyErr_BadInternalCall();
return (unsigned long) -1; 
}

Second case: 
https://github.com/python/cpython/blob/cb65202520e7959196a2df8215692de155bf0cc8/Objects/longobject.c#L1407

They seem to have been incorrect for quite some time, the other one blames back 
to the SVN era. The bug seems to be in 2.7 alike: 
https://github.com/python/cpython/blob/20093b3adf6b06930fe994527670dfb3aee40cc7/Objects/longobject.c#L1025

The correct return value should of course be `(unsigned long long)-1`

--
components: Interpreter Core
messages: 344789
nosy: ztane
priority: normal
severity: normal
status: open
title: Wrong return value from PyLong_AsUnsignedLongLongMask on 
PyErr_BadInternalCall
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com