mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 13:10:21 +01:00
py/obj: Add "full" and "empty" non-variable-length mp_obj_type_t.
This will always have the maximum/minimum size of a mp_obj_type_t representation and can be used as a member in other structs. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
5ddf671944
commit
e8355eb163
@@ -67,7 +67,7 @@ void __dbpanic(DB *db) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_btree_t *btree_new(DB *db, mp_obj_t stream) {
|
||||
mp_obj_btree_t *o = mp_obj_malloc(mp_obj_btree_t, &btree_type);
|
||||
mp_obj_btree_t *o = mp_obj_malloc(mp_obj_btree_t, (mp_obj_type_t *)&btree_type);
|
||||
o->stream = stream;
|
||||
o->db = db;
|
||||
o->start_key = mp_const_none;
|
||||
|
||||
@@ -841,7 +841,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
|
||||
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
|
||||
STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args_in) {
|
||||
mp_obj_framebuf_t *o = mp_obj_malloc(mp_obj_framebuf_t, &mp_type_framebuf);
|
||||
mp_obj_framebuf_t *o = mp_obj_malloc(mp_obj_framebuf_t, (mp_obj_type_t *)&mp_type_framebuf);
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args_in[0], &bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
@@ -62,7 +62,8 @@ mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_o
|
||||
struct _mod_network_socket_obj_t;
|
||||
|
||||
typedef struct _mod_network_nic_type_t {
|
||||
mp_obj_type_t base;
|
||||
// Ensure that this struct is big enough to hold any type size.
|
||||
mp_obj_full_type_t base;
|
||||
|
||||
// API for non-socket operations
|
||||
int (*gethostbyname)(mp_obj_t nic, const char *name, mp_uint_t len, uint8_t *ip_out);
|
||||
|
||||
@@ -198,7 +198,7 @@ STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
||||
STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_re_t *self;
|
||||
if (mp_obj_is_type(args[0], &re_type)) {
|
||||
if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) {
|
||||
self = MP_OBJ_TO_PTR(args[0]);
|
||||
} else {
|
||||
self = MP_OBJ_TO_PTR(mod_re_compile(1, args));
|
||||
@@ -217,7 +217,7 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
match->base.type = &match_type;
|
||||
match->base.type = (mp_obj_type_t *)&match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = args[1];
|
||||
return MP_OBJ_FROM_PTR(match);
|
||||
@@ -282,7 +282,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_split_obj, 2, 3, re_split);
|
||||
|
||||
STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_re_t *self;
|
||||
if (mp_obj_is_type(args[0], &re_type)) {
|
||||
if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) {
|
||||
self = MP_OBJ_TO_PTR(args[0]);
|
||||
} else {
|
||||
self = MP_OBJ_TO_PTR(mod_re_compile(1, args));
|
||||
@@ -305,7 +305,7 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
||||
vstr_t vstr_return;
|
||||
vstr_return.buf = NULL; // We'll init the vstr after the first match
|
||||
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char *));
|
||||
match->base.type = &match_type;
|
||||
match->base.type = (mp_obj_type_t *)&match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = where;
|
||||
|
||||
@@ -430,7 +430,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
||||
if (size == -1) {
|
||||
goto error;
|
||||
}
|
||||
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, &re_type);
|
||||
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, (mp_obj_type_t *)&re_type);
|
||||
#if MICROPY_PY_URE_DEBUG
|
||||
int flags = 0;
|
||||
if (n_args > 1) {
|
||||
|
||||
@@ -774,7 +774,7 @@ static const mp_rom_map_elem_t nina_locals_dict_table[] = {
|
||||
|
||||
static MP_DEFINE_CONST_DICT(nina_locals_dict, nina_locals_dict_table);
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
STATIC MP_DEFINE_CONST_OBJ_FULL_TYPE(
|
||||
mod_network_nic_type_nina_base,
|
||||
MP_QSTR_nina,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
|
||||
@@ -1024,7 +1024,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
||||
locals_dict, &wiznet5k_locals_dict
|
||||
);
|
||||
#else // WIZNET5K_PROVIDED_STACK
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
STATIC MP_DEFINE_CONST_OBJ_FULL_TYPE(
|
||||
mod_network_nic_type_wiznet5k_base,
|
||||
MP_QSTR_WIZNET5K,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
|
||||
Reference in New Issue
Block a user