uctypes enhancements: any interest in upstreaming from m68k-micropython? #17778
Unanswered
jepler
asked this question in
Core Development
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For m68k-micropython I want to wrap a large set of Macintosh APIs. Many of these APIs operate via structures, such as
struct { INTEGER top, left, right, bottom; } Rect;
.In Python code I'd like to be able to "construct a Rect object" and then pass it to a function which can type check that it actually received a
Rect
Python object. The object would of course have an internal buffer with the layout of aRect
struct.To do this, I've made some enhancements to the uctypes module:
uctypes.struct
can take a buffer as the first argument in addition to an addressRect()
allocates storage and returns aRect
instance that points to it. This object has a repr like<Rect STRUCT address>
.uctypes.struct(address, Rect)
returns aRect
instance pointing at the given address. (also works for buffers)uctypes.sizeof
and other stuff that looks at sub-structures can accept a type object as a descriptor, in addition to dict or tuplelhs[:] = rhs
rhs[:]
mp_get_buffer
: there's a new fieldvoid *base
in mp_buffer_info_t which is populated by memoryview & ctypes and whichmp_get_buffer
ensures is populated (withbuf
) if it was not otherwise set to non-NULL.ctypes.desc()
to get the actual descriptor of a type or objectNeedless to say this probably all grows the struct module by a fair amount (I haven't measured). And worse, it contains an incompatible ABI change. (hmm I wonder if the ABI change could be avoided by doing crimes to the field called
int typecode
...)I'm not sure, but ulab might benefit from the
mp_get_buffer
change or something that makes it possible for more types than memoryview to correctly track gc base pointers; at least at one point it had a similar GC problem to memoryview with slicing views.Is there any interest in seeing uctypes in micropython improved along these lines? The module does not seem to see a lot of development activity and so new features are likely to be little used. In short, I'm guessing not. But I wanted to make the offer and give a brief description of what I've done and what I have in mind.
Beta Was this translation helpful? Give feedback.
All reactions