If I have an inheritance tree, with INIT methods in each class, in which order will they be invoked when a class is cloned?
In particular, when using multiple inheritance
class foo { inherit A; inherit M; }
can I count i on A's INIT method being executed before M's? For some context, M is a mixin, that works by initializing fields of A. Inheritance tree may look something like
M A N | | | | B | | |\ / | C E \ / D
where N and M are two different mixins modifying the behaviour of A.
You will probably have to verify that by browsing through precompile.pike. If you find that (or make sure that) the desired behaviour is guaranteed by the current implementation, it is probably a good idea to document this guarantee near the code in question.
/ Johan Sundström (folkskådare)
Previous text:
2003-03-13 13:25: Subject: INIT order
If I have an inheritance tree, with INIT methods in each class, in which order will they be invoked when a class is cloned?
In particular, when using multiple inheritance
class foo { inherit A; inherit M; }
can I count i on A's INIT method being executed before M's? For some context, M is a mixin, that works by initializing fields of A. Inheritance tree may look something like
M A N | | | | B | | |\ / | C E \ / D
where N and M are two different mixins modifying the behaviour of A.
/ Niels Möller ()
Some experimentation shows that if I write
PIKECLASS md5_state { INHERIT nettle_md5; INHERIT hash_instance; CVAR struct md5_ctx md5;
... }
then hash_instance is initialized before nettle_md5, which is what I want. I would have expected the opposite order.
The order of the low_inherit in the generated C code matches the order of the INHERITs in the cmod. So if the initialization order should be changed, I think that change belongs somewhere else than in precompile.pike.
Within an inheritance chain, init methods are called from the top down, inheriting classes after the classes they inherit, which makes sense.
/ Niels Möller ()
Previous text:
2003-03-13 15:14: Subject: INIT order
You will probably have to verify that by browsing through precompile.pike. If you find that (or make sure that) the desired behaviour is guaranteed by the current implementation, it is probably a good idea to document this guarantee near the code in question.
/ Johan Sundström (folkskådare)
pike-devel@lists.lysator.liu.se