diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-09-19 13:20:57 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-19 13:20:57 +0900 |
commit | 3146ebd330cbd02d0d7b4f82a94472cb395804ef (patch) | |
tree | 115279d7b92292972a2d8504dc0a449e762e48ad | |
parent | b98b8cab99d7b2dbfe2b2211974564b7e22e9412 (diff) | |
download | msgpack-python-3146ebd330cbd02d0d7b4f82a94472cb395804ef.tar.gz |
Use Py_SIZE() when it is safe (#369)
-rw-r--r-- | msgpack/_packer.pyx | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx index e275ef2..2f4d120 100644 --- a/msgpack/_packer.pyx +++ b/msgpack/_packer.pyx @@ -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) |