Use Py_SIZE() when it is safe (#369)

This commit is contained in:
Inada Naoki 2019-09-19 13:20:57 +09:00 committed by GitHub
parent b98b8cab99
commit 3146ebd330
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,7 +200,7 @@ cdef class Packer(object):
dval = o
ret = msgpack_pack_double(&self.pk, dval)
elif PyBytesLike_CheckExact(o) if strict_types else PyBytesLike_Check(o):
L = len(o)
L = Py_SIZE(o)
if L > ITEM_LIMIT:
PyErr_Format(ValueError, b"%.200s object is too large", Py_TYPE(o).tp_name)
rawval = o
@ -214,7 +214,7 @@ cdef class Packer(object):
raise ValueError("unicode string is too large")
else:
o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors)
L = len(o)
L = Py_SIZE(o)
if L > ITEM_LIMIT:
raise ValueError("unicode string is too large")
ret = msgpack_pack_raw(&self.pk, L)
@ -254,7 +254,7 @@ cdef class Packer(object):
ret = msgpack_pack_ext(&self.pk, longval, L)
ret = msgpack_pack_raw_body(&self.pk, rawval, L)
elif PyList_CheckExact(o) if strict_types else (PyTuple_Check(o) or PyList_Check(o)):
L = len(o)
L = Py_SIZE(o)
if L > ITEM_LIMIT:
raise ValueError("list is too large")
ret = msgpack_pack_array(&self.pk, L)