[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Avoiding svn_iter_apr_hash/array() [was: svn commit: r935579]

From: Julian Foad <julian.foad_at_wandisco.com>
Date: Tue, 20 Apr 2010 16:34:38 +0100

Daniel Shahaf wrote:
> Julian Foad wrote on Tue, 20 Apr 2010 at 11:49 +0100:
> > Hmm... I wonder if we could do something with a macro that takes the
> > whole block of code to be executed as an argument, like:
>
> A code block inside a macro call??

Well, I tried it and it works and I kind of like it... but really I
tried it for fun and I'm not sure if we should be seriously considering
anything like this.

> Perhaps we write a macro in the
> style of SVN_DBG --- one that is "pseudo-variadic"...
>
> For example (not tested):
>
> #define SVN_ITER_ARRAY2(element_type, element_name, array, iterpool, pool, func_name, (arg1, arg2)) \
> SVN_ITER_ARRAY(element_type, element_name, array, iterpool, pool, func_name(arg1, arg2))

I think you mean something like (with a backslash after every line):

#define SVN_ITER_ARRAY2(element_type, element_name, array,
                        iterpool, pool,
                        func_name, arg_list)
  SVN_ITER_ARRAY(element_type, element_name, array,
                 iterpool, pool,
    {
      svn_error_t *__err = func_name arg_list;
      if (__err->apr_err == SVN_ERR_ITER_BREAK)
        {
          svn_error_clear(err);
          break;
        }
      SVN_ERR(__err);
    }

And I think the advantages of your SVN_ITER_ARRAY2 are:

  * not taking a code block as an argument, thus avoiding the surprise
(and possible confusion of syntax-highlighting editors etc.);

and its disadvantages are:

  * the body of the loop has to be expressed as a single function call,
which adds a considerable overhead for simple operations.

- Julian

> where SVN_ITER_ARRAY() is the macro you defined:
>
> > #define SVN_ITER_ARRAY(element_type, element_name, array, \
> > iterpool_name, /* as subpool of */ pool, \
> > code_block) \
> > { apr_pool_t *iterpool_name = ... \
> > for (...) \
> > { \
> > element_type element_name = ...; \
> > apr_pool_clear(iterpool_name); \
> > code_block \
> > } \
> > apr_pool_destroy(iterpool_name); \
> > }
> >
>
> :-)
>
> Daniel
>
> > Usage:
> > SVN_ITER_ARRAY(svn_node_t *, node, nodes_array,
> > iterpool, existing_pool,
> > {
> > if (node->kind == svn_node_file)
> > SVN_ERR(bar(node, blah, iterpool));
> > else
> > break; /* breaks the iteration */
> > } ) /* macro ends here */
> >
> > Hmm...
> >
> > - Julian
> >
> >
> >
Received on 2010-04-20 17:35:14 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.