Skip to content

Commit

Permalink
Update doc with new macro M_CHAIN_INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
P-p-H-d committed Sep 9, 2023
1 parent bf68340 commit 269636b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6804,7 +6804,7 @@ You can chain the M\_LET\_IF macro to create several different variables.
This macro registers the execution of 'clear\_code' when reaching
the further closing brace of the next block of instruction.
clear_code shall be a valid expression.
clear\_code shall be a valid expression.
There shall be at most one M\_DEFER macro per line of source code.
Expand All @@ -6823,6 +6823,39 @@ You can use the break instruction to quit the block
(the clear\_code will be executed) or you can use exception.
##### M\_CHAIN\_INIT(init\_code, clear\_code)
This macro executes 'init\_code' then
registers the execution of 'clear\_code' if an exception is triggered
until the further closing brace of the next block of instruction.
init\_code and clear\_code shall be a valid expression.
If exception are not enabled, it simply executes 'init\_code'.
There shall be at most one M\CHAIN\_INIT macro per line of source code.
It can be chained multiple times to register multiple registrations.
Therefore it enables support for chaining
initialization at the begining of a constructor for the fields of the constructed
object so that even if the constructor failed and throw an exception,
the fields of the constructed object are properly cleared.
This is equivalent to C++ construct:
void type() : field1(), field2() { rest of constructor }
M_CHAIN_INIT shall be the first instructions of the constructor function.
Example:
void struct_init_set(struct_t d, struct_t s)
{
M_CHAIN_INIT(string_init_set(d->s1, s->s1), string_clear(d->s1) )
M_CHAIN_INIT(string_init_set(d->s2, s->s2), string_clear(d->s2) ) {
d->num = s->num;
}
}
#### Memory / Error macros
All these macro can be overridden before including the header m-core.h
Expand Down Expand Up @@ -8065,6 +8098,11 @@ otherwise it will compile in degraded mode:
-fblocks -lBlocksRuntime
When writing your own constructor, you should consider M\_CHAIN\_INIT
to support partially constructed object
if there are more than two source of throwing in your object
(any memory allocation is a source of throwing).
#### struct m\_exception\_s
This is the exception type. It is composed of the following fields:
Expand Down
20 changes: 19 additions & 1 deletion doc/ISSUES.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
*Long term issues*
==========================================================

* TODO #33 : Handling of partially constructed object :ANOMALY:

** State

Support of partially constructed object needs special code to handle it
correctly (register a correct cleanup function in case of exception).

Current containers don't support such features.

** Actions

Add such support in M*LIB containers.

It can be difficult. For example, for array _init_set
function due to the copy of the object one per one. Each copied sub object
may throw an exception, so we always need to have the container in a correct
state so that it can be cleanup.

* TODO #32 : User specialization fields in the container :ENHANCEMENT:

** State
Expand Down Expand Up @@ -145,7 +163,7 @@ containers provides
static inline m_serial_return_code_t \
M_C(M_F(name, _out_serial),M_GET_NAME(serial_op) )(M_GET_TYPE(serial_op) f, const list_t list) \

* TODO #29 : Support of partial initialized object :ANOMALY:
* DONE #29 : Support of partial initialized object :ANOMALY:

** State

Expand Down

0 comments on commit 269636b

Please sign in to comment.