Skip to content

Conversation

@jepler
Copy link

@jepler jepler commented Jul 20, 2025

MicroPython's GC requires that a pointer to the beginning of an allocated chunk has to be kept somewhere in another reachable object, or the chunk can be freed when GC happens.

However, with uctypes nested structures, this was not necessarily the case. For example, before this PR, you could lose the contents of a pnSize object:

MicroPython 20250717-9.g4a46582605.dirty on 2025-07-20; macplus with m68000
Type "help()" for more information.
>>> import qd, gc
>>> sz = qd.PenState().pnSize # Sub-field of PenState not at start
>>> sz.h = 8
>>> sz.v = 12
>>> import gc
>>> gc.collect()
>>> for _ in range(100): l = [] # Make a bunch of objects
>>> (sz.h, sz.v)
(4, 0)   # Because the storage for PenState was used for other objects

After this PR, the correct value of (8, 12) is printed.

jepler added 4 commits July 20, 2025 13:30
This flag requests that the filled bufinfo give the associated
GC base address, for classes like memoryview & uctypes that need
it in order to ensure liveness of the data they refer to.

I had initially hoped that this would be a forward compatible
change, but the practice of checking `flags == MP_BUFFER_READ`
means it's not, so I might as well make it unconditional. But,
here, it's an intermediate step that passed the tests.
For instance, don't cancel a push run for a given ref when a
tag/release run for the same ref is running.
@jepler jepler merged commit 8b36bf9 into m68k-micropython:main Jul 20, 2025
6 checks passed
@jepler jepler deleted the uctypes-enhancements branch July 20, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant