We may modify PyXXX_GET_SIZE() to add assert(PyXXX_Check()) to help to detect bugs and misuses of these macros in debug mode.
The problem is that I expect a compilation error on PyXXX_GET_SIZE()=size. The new PyDict_GET_SIZE() macro has the assertion. Use Py_SIZE() to set the size. Victor Le 20 mars 2017 12:28, "Serhiy Storchaka" <storch...@gmail.com> a écrit : > What is the preferable way of getting the size of tuple, list, bytes, > bytearray: Py_SIZE or PyTuple_GET_SIZE, PyList_GET_SIZE, PyBytes_GET_SIZE, > PyByteArray_GET_SIZE? Are macros for concrete types more preferable or they > are outdated? > > On one hand concrete type macros are longer than Py_SIZE, and since > concrete type macros are defined not for all PyVarObject types we need to > use Py_SIZE for them in any case (for example for PyLongObject and > PyTypeObject). > > On other hand we can add asserts for checking that concrete type macros > are used with correct types. When I wrote a patch that replaces Py_SIZE > with concrete type macros I found two cases of misusing Py_SIZE with dict > object: one in _json.c (already fixed in > 3023ebb43f7607584c3e123aff56e867cb04a418) > and other in dictobject.c (still not fixed). If prefer using concrete type > macros this would unlikely happen. > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor. > stinner%40gmail.com >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com