cpython: 4fd48a807812 (original) (raw)

Mercurial > cpython

changeset 84996:4fd48a807812

Issue #16741: Fix an error reporting in int(). [#16741]

Serhiy Storchaka storchaka@gmail.com
date Sat, 03 Aug 2013 21:14:05 +0300
parents ab1859ba1a78(current diff)ecc8512b427d(diff)
children 673ef3f96919
files Include/longobject.h Lib/test/test_int.py Misc/NEWS Objects/abstract.c Objects/longobject.c
diffstat 5 files changed, 100 insertions(+), 70 deletions(-)[+] [-] Include/longobject.h 1 Lib/test/test_int.py 47 Misc/NEWS 2 Objects/abstract.c 29 Objects/longobject.c 91

line wrap: on

line diff

--- a/Include/longobject.h +++ b/Include/longobject.h @@ -97,6 +97,7 @@ PyAPI_FUNC(PyObject *) PyLong_FromString #ifndef Py_LIMITED_API PyAPI_FUNC(PyObject ) PyLong_FromUnicode(Py_UNICODE, Py_ssize_t, int); PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base); +PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int); #endif #ifndef Py_LIMITED_API

--- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -73,14 +73,6 @@ class IntTestCases(unittest.TestCase): x = -1-sys.maxsize self.assertEqual(x >> 1, x//2)

-

- x = int('1' * 600) self.assertIsInstance(x, int) @@ -401,14 +393,37 @@ class IntTestCases(unittest.TestCase): int(TruncReturnsBadInt()) def test_error_message(self):

+

+

def test_main(): support.run_unittest(IntTestCases)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #16741: Fix an error reporting in int(). +

--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1261,25 +1261,6 @@ convert_integral_to_int(PyObject integr } -/ Add a check for embedded NULL-bytes in the argument. */ -static PyObject * -long_from_string(const char *s, Py_ssize_t len) -{

-

-} - PyObject * PyNumber_Long(PyObject *o) { @@ -1327,16 +1308,16 @@ PyNumber_Long(PyObject o) if (PyBytes_Check(o)) / need to do extra error checking that PyLong_FromString()

return type_error("int() argument must be a string or a " "number, not '%.200s'", o);

--- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2000,6 +2000,14 @@ long_from_binary_base(char *str, int ba return long_normalize(z); } +/ Parses a long from a bytestring. Leading and trailing whitespace will be

onError:

+

+} + PyObject * PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) { @@ -2294,9 +2332,8 @@ PyLong_FromUnicode(Py_UNICODE *u, Py_ssi PyObject * PyLong_FromUnicodeObject(PyObject *u, int base) {

} /* forward */ @@ -4319,23 +4361,12 @@ long_new(PyTypeObject *type, PyObject *a if (PyUnicode_Check(x)) return PyLong_FromUnicodeObject(x, (int)base); else if (PyByteArray_Check(x) || PyBytes_Check(x)) {