Merge lp://staging/~jamesodhunt/libnih/iterators into lp://staging/libnih/1.0

Proposed by James Hunt
Status: Needs review
Proposed branch: lp://staging/~jamesodhunt/libnih/iterators
Merge into: lp://staging/libnih/1.0
Diff against target: 952 lines (+738/-8)
11 files modified
ChangeLog (+10/-0)
nih/hash.c (+62/-0)
nih/hash.h (+7/-0)
nih/list.c (+59/-0)
nih/list.h (+18/-0)
nih/tests/test_hash.c (+176/-2)
nih/tests/test_list.c (+154/-3)
nih/tests/test_tree.c (+170/-1)
nih/tree.c (+62/-0)
nih/tree.h (+18/-0)
po/libnih.pot (+2/-2)
To merge this branch: bzr merge lp://staging/~jamesodhunt/libnih/iterators
Reviewer Review Type Date Requested Status
Scott James Remnant (Canonical) Pending
Review via email: mp+60308@code.staging.launchpad.net

Description of the change

* New functions:
  - nih_list_foreach()
  - nih_hash_foreach()
  - nih_tree_foreach()
  - nih_list_count()
  - nih_hash_count()
  - nih_tree_count()

These functions will be marginally slower to run than the corresponding NIH_LIST_FOREACH(), NIH_HASH_FOREACH() and NIH_TREE_FOREACH_*() macros, but have the advantage of being (more easily) callable from within a debugger. Additionally, trivial handlers can be created by apps using nih which also simplifies debug.

For example, we could change Upstart to include functions like this:

init/conf.c:
#ifdef DEBUG
  int conf_sources_handler (ConfSource *source, void *data)
      __attribute__((unused));

  int
  conf_sources_handler (ConfSource *source, void *data)
  {
    nih_assert (source);
    return TRUE;
  }
#endif

This minimal handler is enough such that from within gdb, we can then say:

(gdb) b conf_sources_handler
(gdb) call nih_list_foreach (conf_sources, NULL, (NihListHandler)conf_sources_handler, NULL)
(gdb) r

And then when the breakpoint is hit...

(gdb) p source

This avoids cluttering our applications source code with horrid hard-coded functions to print out data structures - we can rely on gdb to do that for us.

To post a comment you must log in.

Unmerged revisions

1049. By James Hunt

* Changelog: Summary of new functions.
* nih/hash.c: New functions:
  - nih_hash_foreach()
  - nih_hash_count()
* nih/hash.h: Prototypes for new functions:
  - nih_hash_foreach()
  - nih_hash_count()
* nih/list.c: New functions:
  - nih_list_foreach()
  - nih_list_count()
* nih/list.h:
  - Prototypes for new functions:
    - nih_list_foreach()
    - nih_list_count()
  - New type: NihListHandler.
* nih/tree.c: New functions:
  - nih_tree_foreach()
  - nih_tree_count()
* nih/tree.h:
  - Prototypes for new functions:
    - nih_tree_foreach()
    - nih_tree_count()
  - New type: NihTreeHandler.
* nih/tests/test_hash.c:
  - New functions:
    - test_count()
    - test_foreach_func () and supporting functions:
      - hash_handler1()
      - hash_handler2()
      - hash_handler3()
  - Updated main to call test_foreach_func() and test_count().
  - Changed description for existing functions to make it clear that
    NIH_HASH_FOREACH() is a macro.
* nih/tests/test_list.c:
  - New functions:
    - test_count()
    - test_foreach_func() and supporting functions:
      - list_handler1()
      - list_handler2()
      - list_handler3()
  - Updated main to call test_foreach_func() and test_count().
  - Changed description for existing functions to make it clear that
    NIH_LIST_*() are macros.
* nih/tests/test_tree.c
  - New functions:
    - test_count()
    - test_foreach_func () and supporting functions:
      - tree_handler1()
      - tree_handler2()
      - tree_handler3()
  - Updated main to call test_foreach_func() and test_count().
  - Changed description for existing functions to make it clear that
    NIH_TREE_FOREACH_*() are macros.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: