8000 Fix get_lv_struct_size · diskman88/lv_binding_micropython@53232d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53232d3

Browse files
committed
Fix get_lv_struct_size
When struct size is unknown, assume 0 This allows creating structs with undefined size, as null structs (instead of __cast__(None) ) __cast__(None) no longer creates a null struct, but returns None instead
1 parent 5595733 commit 53232d3

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

driver/esp32/xpt2046.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, miso=-1, mosi=-1, clk=-1, cs=25,
2525
if not lv.is_initialized():
2626
lv.init()
2727

28-
disp = lv.disp_t.__cast__(None)
28+
disp = lv.disp_t()
2929
self.screen_width = disp.get_hor_res()
3030
self.screen_height = disp.get_ver_res()
3131
self.miso = miso

gen/gen_mpy.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,13 @@ def register_int_ptr_type(convertor, *types):
10791079
10801080
STATIC inline size_t get_lv_struct_size(const mp_obj_type_t *type)
10811081
{
1082-
mp_obj_t size_obj = mp_obj_dict_get(MP_OBJ_TYPE_GET_SLOT(type, locals_dict), MP_OBJ_NEW_QSTR(MP_QSTR___SIZE__));
1083-
return (size_t)mp_obj_get_int(size_obj);
1082+
mp_obj_dict_t *self = MP_OBJ_TO_PTR(MP_OBJ_TYPE_GET_SLOT(type, locals_dict));
1083+
mp_map_elem_t *elem = mp_map_lookup(&self->map, MP_OBJ_NEW_QSTR(MP_QSTR___SIZE__), MP_MAP_LOOKUP);
1084+
if (elem == NULL) {
1085+
return 0;
1086+
} else {
1087+
return (size_t)mp_obj_get_int(elem->value);
1088+
}
10841089
}
10851090
10861091
STATIC mp_obj_t make_new_lv_struct(
@@ -1100,7 +1105,7 @@ def register_int_ptr_type(convertor, *types):
11001105
size_t count = (n_args > 0) && (mp_obj_is_int(args[0]))? mp_obj_get_int(args[0]): 1;
11011106
*self = (mp_lv_struct_t){
11021107
.base = {type},
1103-
.data = (other && other->data == NULL)? NULL: m_malloc(size * count)
1108+
.data = (size == 0 || (other && other->data == NULL))? NULL: m_malloc(size * count)
11041109
};
11051110
if (self->data) {
11061111
if (other) {
@@ -1141,6 +1146,7 @@ def register_int_ptr_type(convertor, *types):
11411146
11421147
const mp_obj_type_t *type = mp_obj_get_type(self_in);
11431148
size_t element_size = get_lv_struct_size(type);
1149+
if (element_size == 0) return mp_const_none;
11441150
size_t element_index = mp_obj_get_int(index);
11451151
void *element_addr = (byte*)self->data + element_size*element_index;
11461152
@@ -1378,6 +1384,7 @@ def register_int_ptr_type(convertor, *types):
13781384
} else {
13791385
size = (size_t)mp_obj_get_int(size_in);
13801386
}
1387+
if (size == 0) return mp_const_none;
13811388
mp_obj_array_t *view = MP_OBJ_TO_PTR(mp_obj_new_memoryview(BYTEARRAY_TYPECODE,
13821389
size, self->data));
13831390
view->typecode |= 0x80; // used to indicate writable buffer

lvgl

0 commit comments

Comments
 (0)
0