Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document ucl_object_iter_chk_excpn() and add it into test scenario. #206

Merged
merged 8 commits into from
Apr 3, 2019
Next Next commit
Document usage of ucl_object_iter_chk_excpn().
  • Loading branch information
sobomax committed Apr 2, 2019
commit 0b1a4075b84f2c9dd47356778a63e61bea41ae60
26 changes: 22 additions & 4 deletions doc/libucl.3
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,23 @@ Iteration\ without\ expansion:
.PP
UCL defines the following functions to manage safe iterators:
.IP \[bu] 2
\f[C]ucl_object_iterate_new\f[] \- creates new safe iterator
\f[C]ucl_object_iterate_new\f[] \- creates new safe iterator.
.IP \[bu] 2
\f[C]ucl_object_iterate_reset\f[] \- resets iterator to a new object
\f[C]ucl_object_iterate_reset\f[] \- resets iterator to a new object.
.IP \[bu] 2
\f[C]ucl_object_iterate_safe\f[] \- safely iterate the object inside
iterator
iterator.
Note: function may allocate and fees memory during its operation.
Therefore it returns \f[C]NULL\f[] either while trying to access item
after the last one or when exception (sucn as memory allocation
failure) happens.
.IP \[bu] 2
\f[C]ucl_object_iter_chk_excpn\f[] \- check if last call to
\f[C]ucl_object_iterate_safe\f[] ended up in unrecoverable exception
(e.g. \f[C]ENOMEM\f) .
.IP \[bu] 2
\f[C]ucl_object_iterate_free\f[] \- free memory associated with the safe
iterator
iterator.
.PP
Please note that unlike unsafe iterators, safe iterators \f[I]must\f[]
be explicitly initialized and freed.
Expand All @@ -637,13 +645,23 @@ it\ =\ ucl_object_iterate_new\ (obj);
while\ ((cur\ =\ ucl_object_iterate_safe\ (it,\ true))\ !=\ NULL)\ {
\ \ \ \ /*\ Do\ something\ */
}
/*\ Check\ error\ condition\ */
if\ (ucl_object_iter_chk_excpn(it))\ {
\ \ \ \ ucl_object_iterate_free\ (it);
\ \ \ \ exit(1);
}

/*\ Switch\ to\ another\ object\ */
it\ =\ ucl_object_iterate_reset\ (it,\ another_obj);

while\ ((cur\ =\ ucl_object_iterate_safe\ (it,\ true))\ !=\ NULL)\ {
\ \ \ \ /*\ Do\ something\ else\ */
}
/*\ Check\ error\ condition\ */
if\ (ucl_object_iter_chk_excpn(it))\ {
\ \ \ \ ucl_object_iterate_free\ (it);
\ \ \ \ exit(1);
}

ucl_object_iterate_free\ (it);
\f[]
Expand Down