uctypes: Make PtrType(0) cast the int to pointer
.. the previous interpretation made the data at address 0 be a pointer. Additionally, `PtrType(buffer)` is not permitted anymore. You can use `ctypes.struct(buffer, PtrType)` if you really want to treat the content of the buffer as a pointer.
This commit is contained in:
parent
d325558b56
commit
6b69bb4030
1 changed files with 4 additions and 9 deletions
|
|
@ -125,17 +125,12 @@ mp_obj_t uctypes_struct_type_make_new(const mp_obj_type_t *type_in, size_t n_arg
|
|||
|
||||
mp_buffer_info_t bufinfo;
|
||||
if (is_ptr(desc)) {
|
||||
bufinfo.len = size;
|
||||
if (n_args != 1) {
|
||||
bufinfo.buf = 0;
|
||||
if (n_args > 1) {
|
||||
mp_raise_TypeError(NULL);
|
||||
}
|
||||
if (mp_obj_is_int(args[0])) {
|
||||
void *ptr = (void *)(uintptr_t)mp_obj_get_int_truncated(args[0]);
|
||||
*(void **)bufinfo.buf = ptr;
|
||||
} else {
|
||||
mp_buffer_info_t pointee;
|
||||
mp_get_buffer_raise(args[0], &pointee, MP_BUFFER_WRITE);
|
||||
*(void **)bufinfo.buf = pointee.buf;
|
||||
if (n_args) {
|
||||
bufinfo.buf = (void *)mp_obj_get_int_truncated(args[0]);
|
||||
}
|
||||
} else {
|
||||
mp_obj_t bytearray = mp_obj_new_bytearray(size, NULL);
|
||||
|
|
|
|||
Loading…
Reference in a new issue