<div dir="auto">We may modify PyXXX_GET_SIZE() to add assert(PyXXX_Check()) to help to detect bugs and misuses of these macros in debug mode.<div dir="auto"><br></div><div dir="auto">The problem is that I expect a compilation error on PyXXX_GET_SIZE()=size.</div><div dir="auto"><br></div><div dir="auto">The new PyDict_GET_SIZE() macro has the assertion. Use Py_SIZE() to set the size.</div><div dir="auto"><br></div><div dir="auto">Victor</div></div><div class="gmail_extra"><br><div class="gmail_quote">Le 20 mars 2017 12:28, "Serhiy Storchaka" <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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?<br>
<br>
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).<br>
<br>
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 3023ebb43f7607584c3e123aff56e8<wbr>67cb04a418) and other in dictobject.c (still not fixed). If prefer using concrete type macros this would unlikely happen.<br>
<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/victor.<wbr>stinner%40gmail.com</a><br>
</blockquote></div></div>