From caec14afbf69a1785e106fb9ac6d044888dd8aaa Mon Sep 17 00:00:00 2001 From: Malek Date: Mon, 13 Sep 2021 11:44:09 +0200 Subject: [PATCH] version 1.5.1 --- mood/__init__.py | 2 +- setup.py | 88 +++++++++++++++++++------------------- src/msgpack.c | 30 ++++++++----- src/msgpack.h | 2 +- src/object.c | 102 ++++++++++++++++++++++++++++---------------- src/pack.c | 102 +++++++++++++++++++++++++++----------------- src/timestamp.c | 52 +++++++++++++++-------- src/unpack.c | 107 ++++++++++++++++++++++++++++++++++------------- 8 files changed, 309 insertions(+), 176 deletions(-) diff --git a/mood/__init__.py b/mood/__init__.py index 6a577ad..de3b521 100644 --- a/mood/__init__.py +++ b/mood/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. diff --git a/setup.py b/setup.py index 3ceab2d..43132b2 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -27,57 +27,59 @@ pkg_name = "mood.msgpack" -pkg_version = "1.5.0" +pkg_version = "1.5.1" pkg_desc = "Python MessagePack implementation" PKG_VERSION = ("PKG_VERSION", "\"{0}\"".format(pkg_version)) setup( - name=pkg_name, - version=pkg_version, - description=pkg_desc, - long_description=open(abspath("README.txt"), encoding="utf-8").read(), - long_description_content_type="text", + name=pkg_name, + version=pkg_version, + description=pkg_desc, + long_description=open(abspath("README.txt"), encoding="utf-8").read(), + long_description_content_type="text", - url="https://github.com/lekma/mood.msgpack", - download_url="https://github.com/lekma/mood.msgpack/releases", - project_urls={ - "Bug Tracker": "https://github.com/lekma/mood.msgpack/issues" - }, - author="Malek Hadj-Ali", - author_email="lekmalek@gmail.com", - license="GNU General Public License v3 (GPLv3)", - platforms=["POSIX"], - keywords="messagepack msgpack", + url="https://github.com/lekma/mood.msgpack", + download_url="https://github.com/lekma/mood.msgpack/releases", + project_urls={ + "Bug Tracker": "https://github.com/lekma/mood.msgpack/issues" + }, + author="Malek Hadj-Ali", + author_email="lekmalek@gmail.com", + license="GNU General Public License v3 (GPLv3)", + platforms=["POSIX"], + keywords="messagepack msgpack", - setup_requires = ["setuptools>=24.2.0"], - python_requires="~=3.8", - packages=find_packages(), - namespace_packages=["mood"], - zip_safe=False, + setup_requires = ["setuptools>=24.2.0"], + python_requires="~=3.8", + packages=find_packages(), + namespace_packages=["mood"], + zip_safe=False, - ext_package="mood", - ext_modules=[ - Extension("msgpack", - [ - "src/helpers/helpers.c", - "src/timestamp.c", - "src/pack.c", - "src/object.c", - "src/unpack.c", - "src/msgpack.c" - ], - define_macros=[PKG_VERSION]) - ], + ext_package="mood", + ext_modules=[ + Extension( + "msgpack", + [ + "src/helpers/helpers.c", + "src/timestamp.c", + "src/pack.c", + "src/object.c", + "src/unpack.c", + "src/msgpack.c" + ], + define_macros=[PKG_VERSION] + ) + ], - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: POSIX", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: Implementation :: CPython" - ] + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: POSIX", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython" + ] ) diff --git a/src/msgpack.c b/src/msgpack.c index 8672479..52e3061 100644 --- a/src/msgpack.c +++ b/src/msgpack.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -52,8 +52,10 @@ msgpack_register(PyObject *module, PyObject *obj) { module_state *state = NULL; - if (!(state = _PyModule_GetState(module)) || - RegisterObject(state->registry, obj)) { + if ( + !(state = _PyModule_GetState(module)) || + RegisterObject(state->registry, obj) + ) { return NULL; } Py_RETURN_NONE; @@ -81,12 +83,18 @@ msgpack_unpack(PyObject *module, PyObject *args) /* msgpack_def.m_methods */ static PyMethodDef msgpack_m_methods[] = { - {"pack", (PyCFunction)msgpack_pack, - METH_O, msgpack_pack_doc}, - {"register", (PyCFunction)msgpack_register, - METH_O, msgpack_register_doc}, - {"unpack", (PyCFunction)msgpack_unpack, - METH_VARARGS, msgpack_unpack_doc}, + { + "pack", (PyCFunction)msgpack_pack, + METH_O, msgpack_pack_doc + }, + { + "register", (PyCFunction)msgpack_register, + METH_O, msgpack_register_doc + }, + { + "unpack", (PyCFunction)msgpack_unpack, + METH_VARARGS, msgpack_unpack_doc + }, {NULL} /* Sentinel */ }; @@ -158,7 +166,7 @@ _module_state_init(PyObject *module) !(state->registry = PyDict_New()) || RegisterObject(state->registry, Py_NotImplemented) || RegisterObject(state->registry, Py_Ellipsis) - ) { + ) { return -1; } return 0; @@ -172,7 +180,7 @@ _module_init(PyObject *module) _module_state_init(module) || PyModule_AddStringConstant(module, "__version__", PKG_VERSION) || _PyModule_AddType(module, "Timestamp", &Timestamp_Type) - ) { + ) { return -1; } return 0; diff --git a/src/msgpack.h b/src/msgpack.h index 20412e9..c0609e4 100644 --- a/src/msgpack.h +++ b/src/msgpack.h @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. diff --git a/src/object.c b/src/object.c index af832ba..2837c69 100644 --- a/src/object.c +++ b/src/object.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -38,9 +38,11 @@ __PyObject_UpdateDict(PyObject *self, PyObject *arg) we should do that here. */ Py_INCREF(key); if (!PyUnicode_Check(key)) { - PyErr_Format(PyExc_TypeError, - "expected state key to be unicode, not '%.200s'", - Py_TYPE(key)->tp_name); + PyErr_Format( + PyExc_TypeError, + "expected state key to be unicode, not '%.200s'", + Py_TYPE(key)->tp_name + ); Py_DECREF(key); break; } @@ -64,10 +66,17 @@ __PyObject_SetState(PyObject *self, PyObject *arg) _Py_IDENTIFIER(__setstate__); PyObject *result = NULL; - if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId___setstate__, - arg, NULL))) { - if (PyErr_ExceptionMatches(PyExc_AttributeError) && - PyDict_Check(arg)) { + if ( + !( + result = _PyObject_CallMethodIdObjArgs( + self, &PyId___setstate__, arg, NULL + ) + ) + ) { + if ( + PyErr_ExceptionMatches(PyExc_AttributeError) && + PyDict_Check(arg) + ) { PyErr_Clear(); return __PyObject_UpdateDict(self, arg); } @@ -88,15 +97,17 @@ __PyObject_InPlaceConcatOrAdd(PyObject *self, PyObject *arg) PyObject *result = NULL; int res = -1; - if ((seq_methods = type->tp_as_sequence) && - seq_methods->sq_inplace_concat) { + if ( + (seq_methods = type->tp_as_sequence) && seq_methods->sq_inplace_concat + ) { if ((result = seq_methods->sq_inplace_concat(self, arg))) { res = 0; Py_DECREF(result); } } - else if ((num_methods = type->tp_as_number) && - num_methods->nb_inplace_add) { + else if ( + (num_methods = type->tp_as_number) && num_methods->nb_inplace_add + ) { if ((result = num_methods->nb_inplace_add(self, arg))) { if (result != Py_NotImplemented) { res = 0; @@ -105,8 +116,9 @@ __PyObject_InPlaceConcatOrAdd(PyObject *self, PyObject *arg) } } if (res && !PyErr_Occurred()) { - PyErr_Format(PyExc_TypeError, - "cannot extend '%.200s' objects", type->tp_name); + PyErr_Format( + PyExc_TypeError, "cannot extend '%.200s' objects", type->tp_name + ); } return res; } @@ -117,8 +129,13 @@ __PyObject_Extend(PyObject *self, PyObject *arg) _Py_IDENTIFIER(extend); PyObject *result = NULL; - if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId_extend, - arg, NULL))) { + if ( + !( + result = _PyObject_CallMethodIdObjArgs( + self, &PyId_extend, arg, NULL + ) + ) + ) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); return __PyObject_InPlaceConcatOrAdd(self, arg); @@ -136,10 +153,11 @@ __PySequence_Fast(PyObject *obj, Py_ssize_t len, const char *message) { PyObject *result = NULL; - if ((result = PySequence_Fast(obj, message)) && - (PySequence_Fast_GET_SIZE(result) != len)) { - PyErr_Format(PyExc_ValueError, - "expected a sequence of len %zd", len); + if ( + (result = PySequence_Fast(obj, message)) && + (PySequence_Fast_GET_SIZE(result) != len) + ) { + PyErr_Format(PyExc_ValueError, "expected a sequence of len %zd", len); Py_CLEAR(result); } return result; @@ -151,10 +169,14 @@ __PyObject_MergeFromIter(PyObject *self, PyObject *iter) PyObject *item = NULL, *fast = NULL; while ((item = PyIter_Next(iter))) { - if (!(fast = __PySequence_Fast(item, 2, "not a sequence")) || - PyObject_SetItem(self, - PySequence_Fast_GET_ITEM(fast, 0), - PySequence_Fast_GET_ITEM(fast, 1))) { + if ( + !(fast = __PySequence_Fast(item, 2, "not a sequence")) || + PyObject_SetItem( + self, + PySequence_Fast_GET_ITEM(fast, 0), + PySequence_Fast_GET_ITEM(fast, 1) + ) + ) { Py_XDECREF(fast); Py_DECREF(item); break; @@ -196,8 +218,13 @@ __PyObject_Update(PyObject *self, PyObject *arg) _Py_IDENTIFIER(update); PyObject *result = NULL; - if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId_update, - arg, NULL))) { + if ( + !( + result = _PyObject_CallMethodIdObjArgs( + self, &PyId_update, arg, NULL + ) + ) + ) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); return __PyObject_Merge(self, arg); @@ -217,9 +244,10 @@ __PyCallable_Check(PyObject *arg, void *addr) *(PyObject **)addr = arg; return 1; } - PyErr_Format(PyExc_TypeError, - "argument 1 must be a callable, not %.200s", - Py_TYPE(arg)->tp_name); + PyErr_Format( + PyExc_TypeError, "argument 1 must be a callable, not %.200s", + Py_TYPE(arg)->tp_name + ); return 0; } @@ -231,16 +259,18 @@ __PyObject_New(PyObject *reduce) PyObject *self = NULL; if ( - PyArg_ParseTuple(reduce, "O&O!|OOO", - __PyCallable_Check, &callable, &PyTuple_Type, &args, - &setstatearg, &extendarg, &updatearg) && + PyArg_ParseTuple( + reduce, "O&O!|OOO", + __PyCallable_Check, &callable, &PyTuple_Type, &args, + &setstatearg, &extendarg, &updatearg + ) && (self = PyObject_CallObject(callable, args)) && ( - (setstatearg != Py_None && __PyObject_SetState(self, setstatearg)) || - (extendarg != Py_None && __PyObject_Extend(self, extendarg)) || - (updatearg != Py_None && __PyObject_Update(self, updatearg)) + (setstatearg != Py_None && __PyObject_SetState(self, setstatearg)) || + (extendarg != Py_None && __PyObject_Extend(self, extendarg)) || + (updatearg != Py_None && __PyObject_Update(self, updatearg)) ) - ) { + ) { Py_CLEAR(self); } return self; diff --git a/src/pack.c b/src/pack.c index a0f3108..d79c6b4 100644 --- a/src/pack.c +++ b/src/pack.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -24,8 +24,10 @@ #define _PyErr_ObjTooBig_(n, ex) \ - PyErr_Format(PyExc_OverflowError, "%.200s%s too big to convert", \ - n, (ex) ? " extension data" : "") + PyErr_Format( \ + PyExc_OverflowError, "%.200s%s too big to convert", n, \ + (ex) ? " extension data" : "" \ + ) #define _Packing_(n) _While_(packing, n) @@ -121,8 +123,10 @@ __msgpack_type__(PyByteArrayObject *self, uint8_t type) static inline int -__msgpack_buffer__(PyByteArrayObject *self, uint8_t type, - const void *_buffer, size_t _size) +__msgpack_buffer__( + PyByteArrayObject *self, uint8_t type, + const void *_buffer, size_t _size +) { size_t size = 1 + _size; @@ -136,9 +140,11 @@ __msgpack_buffer__(PyByteArrayObject *self, uint8_t type, static inline int -__msgpack_buffers__(PyByteArrayObject *self, uint8_t type, - const void *_buffer1, size_t _size1, - const void *_buffer2, size_t _size2) +__msgpack_buffers__( + PyByteArrayObject *self, uint8_t type, + const void *_buffer1, size_t _size1, + const void *_buffer2, size_t _size2 +) { size_t size = 1 + _size1 + _size2; @@ -170,22 +176,30 @@ __msgpack_type(PyObject *msg, uint8_t type) static int -__msgpack_buffer(PyObject *msg, uint8_t type, - const void *_buffer, size_t _size) +__msgpack_buffer( + PyObject *msg, uint8_t type, + const void *_buffer, size_t _size +) { - return __msgpack_buffer__((PyByteArrayObject *)msg, type, - _buffer, _size); + return __msgpack_buffer__( + (PyByteArrayObject *)msg, type, + _buffer, _size + ); } static int -__msgpack_buffers(PyObject *msg, uint8_t type, - const void *_buffer1, size_t _size1, - const void *_buffer2, size_t _size2) +__msgpack_buffers( + PyObject *msg, uint8_t type, + const void *_buffer1, size_t _size1, + const void *_buffer2, size_t _size2 +) { - return __msgpack_buffers__((PyByteArrayObject *)msg, type, - _buffer1, _size1, - _buffer2, _size2); + return __msgpack_buffers__( + (PyByteArrayObject *)msg, type, + _buffer1, _size1, + _buffer2, _size2 + ); } @@ -702,16 +716,21 @@ __pack_class(PyObject *obj) _Py_IDENTIFIER(__qualname__); PyObject *data = NULL, *module = NULL, *qualname = NULL; - if ((module = _PyObject_GetAttrId(obj, &PyId___module__)) && - (qualname = _PyObject_GetAttrId(obj, &PyId___qualname__))) { + if ( + (module = _PyObject_GetAttrId(obj, &PyId___module__)) && + (qualname = _PyObject_GetAttrId(obj, &PyId___qualname__)) + ) { if (!PyUnicode_CheckExact(module) || !PyUnicode_CheckExact(qualname)) { - PyErr_Format(PyExc_TypeError, - "expected strings, got: __module__: %.200s, __qualname__: %.200s", - Py_TYPE(module)->tp_name, Py_TYPE(qualname)->tp_name); + PyErr_Format( + PyExc_TypeError, + "expected strings, got: __module__: %.200s, __qualname__: %.200s", + Py_TYPE(module)->tp_name, Py_TYPE(qualname)->tp_name + ); } - else if ((data = NewMessage()) && - (_PyUnicode_Pack(data, module) || - _PyUnicode_Pack(data, qualname))) { + else if ( + (data = NewMessage()) && + (_PyUnicode_Pack(data, module) || _PyUnicode_Pack(data, qualname)) + ) { Py_CLEAR(data); } } @@ -730,11 +749,12 @@ __pack_singleton(PyObject *obj) if ((reduce = _PyObject_CallMethodId(obj, &PyId___reduce__, NULL))) { if (!PyUnicode_CheckExact(reduce)) { - PyErr_SetString(PyExc_TypeError, - "__reduce__() must return a str"); + PyErr_SetString(PyExc_TypeError, "__reduce__() must return a str"); } - else if ((data = NewMessage()) && - _PyUnicode_Pack(data, reduce)) { + else if ( + (data = NewMessage()) && + _PyUnicode_Pack(data, reduce) + ) { Py_CLEAR(data); } Py_DECREF(reduce); @@ -751,9 +771,10 @@ __pack_complex(PyObject *obj) Py_complex complex = ((PyComplexObject *)obj)->cval; PyObject *data = NULL; - if ((data = NewMessage()) && - (__pack_float8(data, complex.real) || - __pack_float8(data, complex.imag))) { + if ( + (data = NewMessage()) && + (__pack_float8(data, complex.real) || __pack_float8(data, complex.imag)) + ) { Py_CLEAR(data); } return data; @@ -783,8 +804,10 @@ __pack_timestamp(PyObject *obj) Timestamp *timestamp = (Timestamp *)obj; PyObject *data = NULL; - if ((data = NewMessage()) && - __pack_timestamp__(data, timestamp->seconds, timestamp->nanoseconds)) { + if ( + (data = NewMessage()) && + __pack_timestamp__(data, timestamp->seconds, timestamp->nanoseconds) + ) { Py_CLEAR(data); } return data; @@ -952,8 +975,9 @@ _PyObject_Pack(PyObject *msg, PyObject *obj, const char *name) } } else { - PyErr_SetString(PyExc_TypeError, - "__reduce__() must return a str or a tuple"); + PyErr_SetString( + PyExc_TypeError, "__reduce__() must return a str or a tuple" + ); } if (type) { res = __pack_extension(msg, data, type, name); @@ -1022,7 +1046,9 @@ RegisterObject(PyObject *registry, PyObject *obj) PyObject *data = NULL, *key = NULL; int res = -1; - if ((data = (PyType_Check(obj) ? __pack_class(obj) : __pack_singleton(obj)))) { + if ( + (data = (PyType_Check(obj) ? __pack_class(obj) : __pack_singleton(obj))) + ) { if ((key = _PyBytes_FromPyByteArray(data))) { res = PyDict_SetItem(registry, key, obj); Py_DECREF(key); diff --git a/src/timestamp.c b/src/timestamp.c index 599ecb8..3fbcfc7 100644 --- a/src/timestamp.c +++ b/src/timestamp.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -63,8 +63,9 @@ _Timestamp_New(PyTypeObject *type, int64_t seconds, uint32_t nanoseconds) } } else { - PyErr_SetString(PyExc_OverflowError, - "argument 'nanoseconds' greater than maximum"); + PyErr_SetString( + PyExc_OverflowError, "argument 'nanoseconds' greater than maximum" + ); } return _PyObject_CAST(self); } @@ -156,8 +157,10 @@ Timestamp_tp_dealloc(Timestamp *self) static PyObject * Timestamp_tp_repr(Timestamp *self) { - return PyUnicode_FromFormat("%s(seconds=%lld, nanoseconds=%09u)", - Py_TYPE(self)->tp_name, self->seconds, self->nanoseconds); + return PyUnicode_FromFormat( + "%s(seconds=%lld, nanoseconds=%09u)", + Py_TYPE(self)->tp_name, self->seconds, self->nanoseconds + ); } @@ -189,9 +192,10 @@ Timestamp_fromtimestamp(PyObject *cls, PyObject *timestamp) result = _Timestamp_FromPyLong(timestamp); } else { - PyErr_Format(PyExc_TypeError, - "expected a 'float' or an 'int', got: '%.200s'", - Py_TYPE(timestamp)->tp_name); + PyErr_Format( + PyExc_TypeError, "expected a 'float' or an 'int', got: '%.200s'", + Py_TYPE(timestamp)->tp_name + ); } return result; } @@ -205,24 +209,35 @@ static PyObject * Timestamp_timestamp(Timestamp *self) { return PyFloat_FromDouble( - self->seconds + (self->nanoseconds / MSGPACK_NSECS_MAX)); + self->seconds + (self->nanoseconds / MSGPACK_NSECS_MAX) + ); } /* TimestampType.tp_methods */ static PyMethodDef Timestamp_tp_methods[] = { - {"fromtimestamp", (PyCFunction)Timestamp_fromtimestamp, - METH_O | METH_CLASS, Timestamp_fromtimestamp_doc}, - {"timestamp", (PyCFunction)Timestamp_timestamp, - METH_NOARGS, Timestamp_timestamp_doc}, + { + "fromtimestamp", (PyCFunction)Timestamp_fromtimestamp, + METH_O | METH_CLASS, Timestamp_fromtimestamp_doc + }, + { + "timestamp", (PyCFunction)Timestamp_timestamp, + METH_NOARGS, Timestamp_timestamp_doc + }, {NULL} /* Sentinel */ }; /* Timestamp_Type.tp_members */ static PyMemberDef Timestamp_tp_members[] = { - {"seconds", T_LONGLONG, offsetof(Timestamp, seconds), READONLY, NULL}, - {"nanoseconds", T_UINT, offsetof(Timestamp, nanoseconds), READONLY, NULL}, + { + "seconds", T_LONGLONG, offsetof(Timestamp, seconds), + READONLY, NULL + }, + { + "nanoseconds", T_UINT, offsetof(Timestamp, nanoseconds), + READONLY, NULL + }, {NULL} /* Sentinel */ }; @@ -235,8 +250,11 @@ Timestamp_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) int64_t seconds; uint32_t nanoseconds = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "L|I:__new__", kwlist, - &seconds, &nanoseconds)) { + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "L|I:__new__", kwlist, &seconds, &nanoseconds + ) + ) { return NULL; } return _Timestamp_New(type, seconds, nanoseconds); diff --git a/src/unpack.c b/src/unpack.c index bb07d9c..ee5a934 100644 --- a/src/unpack.c +++ b/src/unpack.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -144,7 +144,15 @@ __unpack_sequence(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size, PyObject **i int res = 0; for (i = 0; i < size; ++i) { - if ((res = ((item = UnpackMessage(msg, off)) ? 0 : -1))) { + if ( + ( + res = ( + ( + item = UnpackMessage(msg, off) + ) ? 0 : -1 + ) + ) + ) { break; } items[i] = item; // steals ref @@ -161,9 +169,16 @@ __unpack_dict(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size, PyObject *items) int res = 0; for (i = 0; i < size; ++i) { - if ((res = (((key = UnpackMessage(msg, off)) && - (val = UnpackMessage(msg, off))) ? - PyDict_SetItem(items, key, val) : -1))) { + if ( + ( + res = ( + ( + (key = UnpackMessage(msg, off)) && + (val = UnpackMessage(msg, off)) + ) ? PyDict_SetItem(items, key, val) : -1 + ) + ) + ) { Py_XDECREF(key); Py_XDECREF(val); break; @@ -178,11 +193,19 @@ __unpack_dict(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size, PyObject *items) /* -------------------------------------------------------------------------- */ #define __unpack_object(t, m, o, s) \ - ((buffer = __unpack_buffer(m, o, s)) ? t##_FromStringAndSize(buffer, s) : NULL) + ( \ + ( \ + buffer = __unpack_buffer(m, o, s) \ + ) ? t##_FromStringAndSize(buffer, s) : NULL \ + ) #define __unpack_size__(m, o, s) \ - ((buffer = __unpack_buffer(m, o, s)) ? (Py_ssize_t)__unpack_uint##s(buffer) : -1) + ( \ + ( \ + buffer = __unpack_buffer(m, o, s) \ + ) ? (Py_ssize_t)__unpack_uint##s(buffer) : -1 \ + ) #define __unpack_size(t, m, o, s) \ @@ -233,8 +256,10 @@ _PyTuple_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) PyObject *result = NULL; if (!Py_EnterRecursiveCall(_Unpacking_("tuple"))) { - if ((result = PyTuple_New(size)) && - __unpack_sequence(msg, off, size, _PyTuple_ITEMS(result))) { + if ( + (result = PyTuple_New(size)) && + __unpack_sequence(msg, off, size, _PyTuple_ITEMS(result)) + ) { Py_CLEAR(result); } Py_LeaveRecursiveCall(); @@ -254,8 +279,10 @@ _PyDict_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) PyObject *result = NULL; if (!Py_EnterRecursiveCall(_Unpacking_("dict"))) { - if ((result = PyDict_New()) && - __unpack_dict(msg, off, size, result)) { + if ( + (result = PyDict_New()) && + __unpack_dict(msg, off, size, result) + ) { Py_CLEAR(result); } Py_LeaveRecursiveCall(); @@ -272,14 +299,24 @@ _PyDict_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) -------------------------------------------------------------------------- */ static inline int -__unpack_anyset(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size, PyObject *items) +__unpack_anyset( + Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size, PyObject *items +) { PyObject *item = NULL; Py_ssize_t i; int res = 0; for (i = 0; i < size; ++i) { - if ((res = ((item = UnpackMessage(msg, off)) ? PySet_Add(items, item) : -1))) { + if ( + ( + res = ( + ( + item = UnpackMessage(msg, off) + ) ? PySet_Add(items, item) : -1 + ) + ) + ) { Py_XDECREF(item); break; } @@ -296,9 +333,11 @@ __unpack_registered(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) module_state *state = NULL; PyObject *result = NULL, *key = NULL; - if ((buffer = __unpack_buffer(msg, off, size)) && + if ( + (buffer = __unpack_buffer(msg, off, size)) && (state = module_get_state()) && - (key = PyBytes_FromStringAndSize(buffer, size))) { + (key = PyBytes_FromStringAndSize(buffer, size)) + ) { if ((result = PyDict_GetItem(state->registry, key))) { // borrowed Py_INCREF(result); } @@ -405,8 +444,10 @@ _PyList_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) PyObject *result = NULL; if (!Py_EnterRecursiveCall(_Unpacking_("list"))) { - if ((result = PyList_New(size)) && - __unpack_sequence(msg, off, size, _PyList_ITEMS(result))) { + if ( + (result = PyList_New(size)) && + __unpack_sequence(msg, off, size, _PyList_ITEMS(result)) + ) { Py_CLEAR(result); } Py_LeaveRecursiveCall(); @@ -426,8 +467,10 @@ _PySet_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) PyObject *result = NULL; if (!Py_EnterRecursiveCall(_Unpacking_("set"))) { - if ((result = PySet_New(NULL)) && - __unpack_anyset(msg, off, size, result)) { + if ( + (result = PySet_New(NULL)) && + __unpack_anyset(msg, off, size, result) + ) { Py_CLEAR(result); } Py_LeaveRecursiveCall(); @@ -447,8 +490,10 @@ _PyFrozenSet_Unpack(Py_buffer *msg, Py_ssize_t *off, Py_ssize_t size) PyObject *result = NULL; if (!Py_EnterRecursiveCall(_Unpacking_("frozenset"))) { - if ((result = PyFrozenSet_New(NULL)) && - __unpack_anyset(msg, off, size, result)) { + if ( + (result = PyFrozenSet_New(NULL)) && + __unpack_anyset(msg, off, size, result) + ) { Py_CLEAR(result); } Py_LeaveRecursiveCall(); @@ -468,15 +513,20 @@ __unpack_class_error(Py_buffer *msg, Py_ssize_t *off) _Py_IDENTIFIER(builtins); PyObject *module = NULL, *qualname = NULL; - if ((module = UnpackMessage(msg, off)) && - (qualname = UnpackMessage(msg, off))) { + if ( + (module = UnpackMessage(msg, off)) && + (qualname = UnpackMessage(msg, off)) + ) { if (!_PyUnicode_EqualToASCIIId(module, &PyId_builtins)) { - PyErr_Format(PyExc_TypeError, - "cannot unpack ", module, qualname); + PyErr_Format( + PyExc_TypeError, "cannot unpack ", + module, qualname + ); } else { - PyErr_Format(PyExc_TypeError, - "cannot unpack ", qualname); + PyErr_Format( + PyExc_TypeError, "cannot unpack ", qualname + ); } } Py_XDECREF(qualname); @@ -504,8 +554,7 @@ __unpack_singleton_error(Py_buffer *msg, Py_ssize_t *off) PyObject *name = NULL; if ((name = UnpackMessage(msg, off))) { - PyErr_Format(PyExc_TypeError, - "cannot unpack '%U'", name); + PyErr_Format(PyExc_TypeError, "cannot unpack '%U'", name); Py_DECREF(name); } }