Mercurial > cpython-lru_cache-weakref
diff Objects/longobject.c @ 41827:eb45f85c4c79
Make test_base64 pass.
Change binascii.Error to derive from ValueError
and raise binascii.Error everywhere where values are bad
(why on earth did the old code use TypeError?!?).
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 22 May 2007 21:56:47 +0000 |
| parents | b29d71d43c80 |
| children | 229c28cb9afb |
line wrap: on
line diff
--- a/Objects/longobject.c Tue May 22 20:24:57 2007 +0000 +++ b/Objects/longobject.c Tue May 22 21:56:47 2007 +0000 @@ -3519,11 +3519,20 @@ return PyLong_FromLong(0L); if (base == -909) return PyNumber_Long(x); - else if (PyString_Check(x)) { + else if (PyString_Check(x) || PyBytes_Check(x)) { /* Since PyLong_FromString doesn't have a length parameter, * check here for possible NULs in the string. */ - char *string = PyString_AS_STRING(x); - if (strlen(string) != PyString_Size(x)) { + char *string; + int size; + if (PyBytes_Check(x)) { + string = PyBytes_AS_STRING(x); + size = PyBytes_GET_SIZE(x); + } + else { + string = PyString_AS_STRING(x); + size = PyString_GET_SIZE(x); + } + if (strlen(string) != size) { /* create a repr() of the input string, * just like PyLong_FromString does. */ PyObject *srepr; @@ -3536,7 +3545,7 @@ Py_DECREF(srepr); return NULL; } - return PyLong_FromString(PyString_AS_STRING(x), NULL, base); + return PyLong_FromString(string, NULL, base); } else if (PyUnicode_Check(x)) return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
