[New-bugs-announce] [issue28272] a redundant check in maybe_small_long

Oren Milman report at bugs.python.org
Sun Sep 25 08:38:49 EDT 2016

New submission from Oren Milman:

------------ current state ------------
In Objects/longobject.c, the function maybe_small_long first checks whether v (the received PyLongObject pointer) is not NULL. 
However, currently in every call to maybe_small_long, it is already guaranteed that v is not NULL, which makes that check redundant.
(Currently, the following are the only functions that call maybe_small_long:
    * PyLong_FromString
    * long_divrem
    * long_rshift
    * long_lshift
    * long_bitwise)

With regard to relevant changes made in the past, maybe_small_long remained quite the same since it was added, in changeset 48567 (https://hg.python.org/cpython/rev/1ce7e5c5a761) - in particular, the check (whether v is not NULL) was always there.
When it was added, both long_rshift and long_lshift might have called maybe_small_long with v as NULL, which seems like the reason for adding the check back then.

------------ proposed changes ------------
In Objects/longobject.c in maybe_small_long, remove the check whether v is not NULL, and add an 'assert(v != NULL);'.

------------ diff ------------
The proposed patches diff file is attached.

------------ tests ------------
I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with and without the patches, and got quite the same output.
The outputs of both runs are attached.

components: Interpreter Core
files: CPythonTestOutput.txt
messages: 277371
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: a redundant check in maybe_small_long
type: enhancement
versions: Python 3.7
Added file: http://bugs.python.org/file44815/CPythonTestOutput.txt

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list