Help with understanding `` and impl RustPython GC

Hi I am trying to write a GC for RustPython, after implemented the GC, I found almost all CI tests passed, except this one: is the full log doc&fix: explain gc&fix macro · discord9/RustPython@a98b40a (, tracing it down lead to this line, so my problem is what does this test do? I know it’s about testing setprofile but I can’t understand why would frame stack be related to GC or be influenced by gc, can anyone help explain it’s purpose and caevats in CPython, and what could go wrong in this test(RustPython try very hard to be like CPython so I guess asking here maybe useful)?:

it seems self.frame is already empty here, but I can’t get it, why would a GC impled influenced this code, and why is self.frame not checked before pop() for whether it’s empty? My GC algorithm is just ref count + cycle removal, and everyother tests seems to pass fine.

If you get IndexError: pop from empty list here, it means that the call profiling event wasn’t called before the return event. Or that there was an extra return.
The test registers callback with sys.setprofile, and the callback calls trace_call, trace_return etc. based on the event type. Then trace_call pushes its argument to a list (self.stack), and trace_return pops it.

Using a debugger might be tricky in this case, but try changing trace_call & trace_return to print out their arguments and self.stack – that might give a clue.

1 Like

Thanks! As it turns out, RustPython didn’t have a proper setprofile impl, so errors flow everywhere in this test, I had to added a TODO and if is _empty to supress it now, thanks!

1 Like