<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 8 Jun 2018, at 12:36, Serhiy Storchaka <<a href="mailto:storchaka@gmail.com" class="">storchaka@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">08.06.18 11:31, Victor Stinner пише:<br class=""><blockquote type="cite" class="">Do you suggest to trigger a fake "GC collection" which would just<br class="">visit all objects with a no-op visit callback? I like the idea!<br class=""><br class="">Yeah, that would help to detect objects in an inconsistent state and<br class="">reuse the existing implemented visit methods of all types.<br class=""><br class="">Would you be interested to try to implement this new debug feature?<br class=""></blockquote><br class="">It is simple:<br class=""><br class="">#ifdef Py_DEBUG<br class="">void<br class="">_PyGC_CheckConsistency(void)<br class="">{<br class="">    int i;<br class="">    if (_PyRuntime.gc.collecting) {<br class="">        return;<br class="">    }<br class="">    _PyRuntime.gc.collecting = 1;<br class="">    for (i = 0; i < NUM_GENERATIONS; ++i) {<br class="">        update_refs(GEN_HEAD(i));<br class="">    }<br class="">    for (i = 0; i < NUM_GENERATIONS; ++i) {<br class="">        subtract_refs(GEN_HEAD(i));<br class="">    }<br class="">    for (i = 0; i < NUM_GENERATIONS; ++i) {<br class="">        revive_garbage(GEN_HEAD(i));<br class="">    }<br class="">    _PyRuntime.gc.collecting = 0;<br class="">}<br class="">#endif<br class=""></div></div></blockquote><div><br class=""></div>Wouldn’t it be enough to visit just the the newly tracked object in <span style="background-color: rgb(255, 255, 255);" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">PyObject_GC_Track with a visitor function that does something minimal to verify that the object value is sane, for example by checking PyType_Ready(Py_TYPE(op)).</span></font></span></div><div><font face="Menlo" class=""><span style="font-size: 11px; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div><font face="Menlo" class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">That would find issues where objects are tracked before they are initialised far enough to be save to visit, without changing GC behavior. I have no idea what the performance impact of this is though.</span></span></font></div><div><font face="Menlo" class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class=""><br class=""></span></span></font></div><div><font face="Menlo" class=""><span style="background-color: rgb(255, 255, 255);" class=""><span style="font-size: 11px;" class="">Ronald</span></span></font></div><div><br class=""></div></body></html>