diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-15 10:58:42 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-15 10:58:42 +0200 |
| commit | 2e754964b0570ff72c82aa012142adf504e01f0e (patch) | |
| tree | a6cf324f43fe5fd11a5651c6f8186a987a1da922 /python | |
| parent | 43d87e1b14719750585412ab1d15fc30e280b7d0 (diff) | |
| parent | 7bd938dd78ab27ec23ffd84811dbdfa5dd83593a (diff) | |
| download | python-apt-2e754964b0570ff72c82aa012142adf504e01f0e.tar.gz | |
merge from the debian-sid branch
Diffstat (limited to 'python')
| -rw-r--r-- | python/cache.cc | 2 | ||||
| -rw-r--r-- | python/progress.cc | 2 | ||||
| -rw-r--r-- | python/string.cc | 28 | ||||
| -rw-r--r-- | python/tag.cc | 4 |
4 files changed, 25 insertions, 11 deletions
diff --git a/python/cache.cc b/python/cache.cc index a1a865af..e527faba 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -286,7 +286,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { static PyObject *PkgCacheGetIsMultiArch(PyObject *Self, void*) { pkgCache *Cache = GetCpp<pkgCache *>(Self); - PyBool_FromLong(Cache->MultiArchCache()); + return PyBool_FromLong(Cache->MultiArchCache()); } static PyGetSetDef PkgCacheGetSet[] = { diff --git a/python/progress.cc b/python/progress.cc index a7fd7ae1..9e870875 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -28,6 +28,8 @@ inline bool setattr(PyObject *object, const char *attr, const char *fmt, T arg) if (!object) return false; PyObject *value = Py_BuildValue(fmt, arg); + if (value == NULL) + return false; int result = PyObject_SetAttrString(object, attr, value); Py_DECREF(value); 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/python/tag.cc b/python/tag.cc index 248d818d..6ae439f5 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -74,7 +74,7 @@ int TagFileClear(PyObject *self) { PyString_FromStringAndSize((v), (len)) #define TagSecString_FromString(self, v) PyString_FromString(v) #else -PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, +static PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, Py_ssize_t len) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) @@ -85,7 +85,7 @@ PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, return PyUnicode_FromStringAndSize(v, len); } -PyObject *TagSecString_FromString(PyObject *self, const char *v) { +static PyObject *TagSecString_FromString(PyObject *self, const char *v) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) return PyBytes_FromString(v); |
