vstr_t line avoiding a sweep from GC in pyexec

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
envirocoder
Posts: 4
Joined: Tue Nov 30, 2021 5:49 pm

vstr_t line avoiding a sweep from GC in pyexec

Post by envirocoder » Mon Feb 07, 2022 5:45 pm

Forgive my potential ignorance, I'm trying to understand why

Code: Select all

vstr_t line
doesn't get swept from the garbage collector? I'm making changes elsewhere in the function and I want to make sure I don't break something.

With the non MICROPY_REPL_EVENT_DRIVEN version of

Code: Select all

pyexec_friendly_repl
I can't see

Code: Select all

vstr_t line
being referenced from a root pointers. As such, why doesn't it get cleaned by the garbage collector?

In the event_driven version it is referenced:

Code: Select all

MP_STATE_VM(repl_line) = vstr_new(32);
Thanks -- I wanted to check before I introduced a bug!

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: vstr_t line avoiding a sweep from GC in pyexec

Post by stijn » Mon Feb 07, 2022 7:45 pm

Didn't check in detail, but the non-eventdriven version is one big loop hence line is on the stack as long as the program runs and as such doesn't get garbage collected because the mark phase will see it being on the stack?

Post Reply