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" <storchaka at 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 at python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor. > stinner%40gmail.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20170321/b73cdc86/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4