bpo-35983: improve and test old trashcan macros by jdemeyer · Pull Request #12607 · python/cpython

I see what you mean. Let me be very precise what this PR will fix and what it will break, hopefully clarifying things:

This will fix a crash in this case:

  1. class X uses Py_TRASHCAN_SAFE_BEGIN in its deallocator
  2. a class Y inherits from X
  3. a 50 levels deep nested instance of Y is deallocated

This will add a new crash in this case:

  1. class X uses Py_TRASHCAN_SAFE_BEGIN in its deallocator
  2. class X does not inherit directly from object, but from another base class
  3. a very deeply nested instance of X is deallocated, where this nesting does not involve any other trashcan-using class like tuple or list

I consider the first set of conditions more likely than the second, so this will fix more crashes than it introduces. But I cannot deny the possibility that it will break stuff.