Only make objects long lived if they are on the GC heap #2317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using frozen bytecode compiled into the "firmware" (obviously not quite true in the Unix port), and said frozen bytecode has mp_type_bytes object(s) defined, and said object(s) are used as default arguments to functions generated SIGSEGV. After researching, I found this is due to the behavior of making certain things "long_lived". My specific failure occurred in make_str_long_lived, specifically trying to assign str->data, but in my case, "str" is a "ROM" pointer. In other words it is not a heap address, so the concept of making that long lived doesn't seem to apply.
This fix uses VERIFY_PTR (moved from gc.c to gc.h) to check the argument passed to make_obj_long_lived and do nothing if the pointer is not verified as a GC heap block pointer.
I don't have a debugging capability on my actual microcontrollers, but in concept this patch seems safe since the concept of a "long live" GC pointer doesn't seem to apply if the pointer can't be verified to begin with.