diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-02 11:34:51 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-02 11:34:51 +0200 |
| commit | 957603e4d012d29e69fefa4737a7d640e514875b (patch) | |
| tree | b16b77d4720d98f918d868811d75f51a4a188317 | |
| parent | 176e587073b3e529e1494175dc0b250fd2fb79b1 (diff) | |
| parent | 8d1fae9e2bb03225c81ac1f0719408618d86eb52 (diff) | |
| download | python-apt-957603e4d012d29e69fefa4737a7d640e514875b.tar.gz | |
merge upload from Barry
| -rw-r--r-- | debian/changelog | 21 | ||||
| -rw-r--r-- | python/string.cc | 28 | ||||
| -rw-r--r-- | tests/test_lp1030278.py | 22 |
3 files changed, 62 insertions, 9 deletions
diff --git a/debian/changelog b/debian/changelog index 56742716..8c391cad 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.8.7ubuntu2) UNRELEASEDquantal; urgency=low +python-apt (0.8.7ubuntu3) quantal; urgency=low * lp:~mvo/python-apt/recv-key-lp1016643: - Only support long (v4) keyids when downloading keys and @@ -9,6 +9,17 @@ python-apt (0.8.7ubuntu2) UNRELEASEDquantal; urgency=low -- Michael Vogt <michael.vogt@ubuntu.com> Tue, 02 Oct 2012 11:24:21 +0200 +python-apt (0.8.7ubuntu2) quantal; urgency=low + + * python/string.cc, tests/test_lp1030278.py: Fix StrSizeToStr() so that + 1) it first checks for PyLong-ness so that in Python 3 on i386, it + will be able to convert larger numbers (via doubles rather than ints); + 2) before doing the conversions through the apt API, check to see if a + Python exception occurred, e.g. OverflowError, and return an error + condition in that case instead of masking it. (LP: #1030278) + + -- Barry Warsaw <barry@ubuntu.com> Mon, 01 Oct 2012 18:04:35 -0400 + python-apt (0.8.7ubuntu1) quantal; urgency=low [ James Hunt ] @@ -30,6 +41,14 @@ python-apt (0.8.8) UNRELEASED; urgency=low disabled sources.list entries instead of duplicating them. Thanks to "sampo555", LP: #1042916 + [ Barry Warsaw ] + * python/string.cc, tests/test_lp1030278.py: Fix StrSizeToStr() so that + 1) it first checks for PyLong-ness so that in Python 3 on i386, it + will be able to convert larger numbers (via doubles rather than ints); + 2) before doing the conversions through the apt API, check to see if a + Python exception occurred, e.g. OverflowError, and return an error + condition in that case instead of masking it. (LP: #1030278) + [ James Hunt ] * python/cache.cc: PkgCacheGetIsMultiArch(): Return calculated value rather than a random one. diff --git a/python/string.cc b/python/string.cc index 7abe2d17..62aa34e7 100644 --- a/python/string.cc +++ b/python/string.cc @@ -64,17 +64,29 @@ MkInt(StrTimeRFC1123,TimeRFC1123, long long, "L"); PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) { PyObject *Obj; + double value; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) return 0; - if (PyInt_Check(Obj)) - return CppPyString(SizeToStr(PyInt_AsLong(Obj))); + // In Python 3, PyInt_Check is aliased to PyLong_Check and PyInt_AsLong is + // aliased to PyLong_AsLong. Therefore we do the actual long checks first + // so that if it is a long in Python 3, the value will be converted to a + // double rather than a long. This avoids OverflowError regressions in + // Python 3. LP: #1030278 if (PyLong_Check(Obj)) - return CppPyString(SizeToStr(PyLong_AsDouble(Obj))); - if (PyFloat_Check(Obj)) - return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); - - PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); - return 0; + value = PyLong_AsDouble(Obj); + else if (PyInt_Check(Obj)) + value = PyInt_AsLong(Obj); + else if (PyFloat_Check(Obj)) + value = PyFloat_AsDouble(Obj); + else { + PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); + return 0; + } + // Check for OverflowErrors or other exceptions during conversion. + if (PyErr_Occurred()) + return 0; + return CppPyString(SizeToStr(value)); } PyObject *StrQuoteString(PyObject *Self,PyObject *Args) diff --git a/tests/test_lp1030278.py b/tests/test_lp1030278.py new file mode 100644 index 00000000..1cbc2c18 --- /dev/null +++ b/tests/test_lp1030278.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Regression test for LP: #1030278""" + +__author__ = "Barry Warsaw <barry@ubuntu.com>" + +import unittest +import apt_pkg + + +class RegressionTestCase(unittest.TestCase): + + def test_no_overflow_error(self): + # LP: #1030278 produces an overflow error in size_to_str() with a big + # value under Python 3. + self.assertEqual(apt_pkg.size_to_str(2147483648000000000000), '2147 E') + + +if __name__ == "__main__": + unittest.main() + +# vim: ts=4 et sts=4 |
