You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Julian Foad <ju...@btopenworld.com> on 2009/07/09 17:30:16 UTC

[PATCH] Functions much easier to use than apr_hash_this()

The attached patch adds three functions for dereferencing an APR hash
index (iterator). The usage of apr_hash_this() can look something like:

  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
    {
      const char *name;
      svn_wc_entry_t *wc_entry;
      const void *key;
      void *val;

      apr_hash_this(hi, &key, NULL, &val);
      name = key;
      wc_entry = val;

      ... (code that uses the key "name" and value "wc_entry") ...
    }

The reason for the temporary variables "key" and "val" is that you can't
pass pointers to the correct-type variables ("name" and "wc_entry") to
apr_hash_this() without getting pointer type warnings on typical
compilers.

With the attached patch, the above can be rewritten as:

  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
    {
      const char *item = apr_hash_index_key(hi);
      svn_wc_entry_t *entry = apr_hash_index_val(hi);

      ... (code that uses the key "name" and value "wc_entry") ...
    }

We have just started using these functions (but with an additional
"svn_" prefix) in Subversion today, because the source code can then be
much cleaner.

I offer and recommend this patch for inclusion in APR. Please let me
know whether this is suitable or if there is anything I should do to
help get it in.

Thanks.
- Julian

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2369457

Re: [PATCH] Functions much easier to use than apr_hash_this()

Posted by Julian Foad <ju...@btopenworld.com>.
As it's not very clear, I'll point out that this email was addressed to
the APR development list, with Subversion as a CC.

- Julian


Julian Foad wrote:
> The attached patch adds three functions for dereferencing an APR hash
> index (iterator). The usage of apr_hash_this() can look something like:
[...]

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2369525