mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
Issue #14630: Merge fix from 3.2.
This commit is contained in:
commit
9a359bd97f
3 changed files with 18 additions and 3 deletions
|
@ -1228,6 +1228,20 @@ class LongTest(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, myint.from_bytes, 0, 'big')
|
self.assertRaises(TypeError, myint.from_bytes, 0, 'big')
|
||||||
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
|
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
|
||||||
|
|
||||||
|
def test_access_to_nonexistent_digit_0(self):
|
||||||
|
# http://bugs.python.org/issue14630: A bug in _PyLong_Copy meant that
|
||||||
|
# ob_digit[0] was being incorrectly accessed for instances of a
|
||||||
|
# subclass of int, with value 0.
|
||||||
|
class Integer(int):
|
||||||
|
def __new__(cls, value=0):
|
||||||
|
self = int.__new__(cls, value)
|
||||||
|
self.foo = 'foo'
|
||||||
|
return self
|
||||||
|
|
||||||
|
integers = [Integer(0) for i in range(1000)]
|
||||||
|
for n in map(int, integers):
|
||||||
|
self.assertEqual(n, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(LongTest)
|
support.run_unittest(LongTest)
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3.0 Alpha 3?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #14630: Fix a memory access bug for instances of a subclass of int
|
||||||
|
with value 0.
|
||||||
|
|
||||||
- Issue #14339: Speed improvements to bin, oct and hex functions. Patch by
|
- Issue #14339: Speed improvements to bin, oct and hex functions. Patch by
|
||||||
Serhiy Storchaka.
|
Serhiy Storchaka.
|
||||||
|
|
||||||
|
|
|
@ -156,9 +156,7 @@ _PyLong_Copy(PyLongObject *src)
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
i = -(i);
|
i = -(i);
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
sdigit ival = src->ob_digit[0];
|
sdigit ival = MEDIUM_VALUE(src);
|
||||||
if (Py_SIZE(src) < 0)
|
|
||||||
ival = -ival;
|
|
||||||
CHECK_SMALL_INT(ival);
|
CHECK_SMALL_INT(ival);
|
||||||
}
|
}
|
||||||
result = _PyLong_New(i);
|
result = _PyLong_New(i);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue