[SOLVED]const void * parent (_mp_obj_type_t)
[SOLVED]const void * parent (_mp_obj_type_t)
What is this supposed to be used for?
Last edited by jickster on Mon Mar 26, 2018 9:38 pm, edited 1 time in total.
Re: const void * parent (_mp_obj_type_t)
I guess that depends on the context. Where are you seeing this?
It looks like a C declaration for a function called parent that returns a const void pointer and takes an _mp_obj_type_t as an argument.
It looks like a C declaration for a function called parent that returns a const void pointer and takes an _mp_obj_type_t as an argument.
Re: const void * parent (_mp_obj_type_t)
It's defined in _mp_obj_type_t
Code: Select all
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
const void *protocol;
// A pointer to the parents of this type:
// - 0 parents: pointer is NULL (object is implicitly the single parent)
// - 1 parent: a pointer to the type of that parent
// - 2 or more parents: pointer to a tuple object containing the parent types
const void *parent;
// A dict mapping qstrs to objects local methods/constants/etc.
struct _mp_obj_dict_t *locals_dict;
};
Code: Select all
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
const mp_obj_type_t mp_type_ordereddict = {
{ &mp_type_type },
.name = MP_QSTR_OrderedDict,
.print = dict_print,
.make_new = dict_make_new,
.unary_op = dict_unary_op,
.binary_op = dict_binary_op,
.subscr = dict_subscr,
.getiter = dict_getiter,
.parent = &mp_type_dict,
.locals_dict = (mp_obj_dict_t*)&dict_locals_dict,
};
#endif
Re: const void * parent (_mp_obj_type_t)
When you use inheritance, parent will point to the parent object.
So if you were to declare:then the Employee class parent would point to the Person class.
If you're using multiple inheritance: then parent will point to a tuple containing BaseClass1 and BaseClass2.
Your example shows that OrderedDict is a subclass of dict.
So if you were to declare:
Code: Select all
class Employee(Person):
If you're using multiple inheritance:
Code: Select all
class SubClass(BaseClass1, BaseClass2):
Your example shows that OrderedDict is a subclass of dict.
Re: const void * parent (_mp_obj_type_t)
Thanks. That's what I thought it was but good to make sure.dhylands wrote: ↑Mon Mar 26, 2018 9:35 pmWhen you use inheritance, parent will point to the parent object.
So if you were to declare:then the Employee class parent would point to the Person class.Code: Select all
class Employee(Person):
If you're using multiple inheritance:then parent will point to a tuple containing BaseClass1 and BaseClass2.Code: Select all
class SubClass(BaseClass1, BaseClass2):
Your example shows that OrderedDict is a subclass of dict.
Re: [SOLVED]const void * parent (_mp_obj_type_t)
@dhylands can we use `parent` to extend a base class with a sub class (with additional members) when extending Micropython?
The other option would be to add all the base's members in each of the child's local-dicts, which is a duplication and bloats the childs.
(related: https://github.com/micropython/micropython/issues/1159)
The other option would be to add all the base's members in each of the child's local-dicts, which is a duplication and bloats the childs.
(related: https://github.com/micropython/micropython/issues/1159)
Re: [SOLVED]const void * parent (_mp_obj_type_t)
I'm not sure - I typically look at other code for examples. I know that extending C declared classes in python has some issues. Doing everything in python seems to be ok. I haven't personally played with extending C declared classes using C.