diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/longobject.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index d325b8e..1f497c4 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -3519,11 +3519,20 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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), |