Code: Select all
// This mp_obj_type_t struct is a concrete MicroPython object which holds info
// about a type. See below for actual definition of the struct.
typedef struct _mp_obj_type_t mp_obj_type_t;
// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
// as its first member (small ints, qstr objs and inline floats are not concrete).
struct _mp_obj_base_t {
const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
};
typedef struct _mp_obj_base_t mp_obj_base_t;
// as its first member (small ints, qstr objs and inline floats are not concrete).
and everything has worked out.
So then why are there native types that do not follow this rule?
Code: Select all
#if MICROPY_PY_COLLECTIONS
typedef struct _mp_obj_namedtuple_type_t {
mp_obj_type_t base;
size_t n_fields;
qstr fields[];
} mp_obj_namedtuple_type_t;
Code: Select all
mp_obj_type_t
Code: Select all
mp_obj_base_t
Code: Select all
mp_obj_base_t
Code: Select all
mp_obj_type_t *
So why is it ok to use mp_obj_type_t directly?