1 /* iter.c : iteration drivers
3 * ====================================================================
4 * Copyright (c) 2007 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
20 #include "svn_error_codes.h"
22 static svn_error_t internal_break_error
=
24 SVN_ERR_ITER_BREAK
, /* APR status */
26 NULL
, /* child error */
28 __FILE__
, /* file name */
29 __LINE__
/* line number */
33 svn_iter_apr_hash(svn_boolean_t
*completed
,
35 svn_iter_apr_hash_cb_t func
,
39 svn_error_t
*err
= SVN_NO_ERROR
;
40 apr_pool_t
*iterpool
= svn_pool_create(pool
);
43 for (hi
= apr_hash_first(pool
, hash
);
44 ! err
&& hi
; hi
= apr_hash_next(hi
))
50 svn_pool_clear(iterpool
);
52 apr_hash_this(hi
, &key
, &len
, &val
);
53 err
= (*func
)(baton
, key
, len
, val
, iterpool
);
59 if (err
&& err
->apr_err
== SVN_ERR_ITER_BREAK
)
61 if (err
!= &internal_break_error
)
62 /* Errors - except those created by svn_iter_break() -
63 need to be cleared when not further propagated. */
69 /* Clear iterpool, because callers may clear the error but have no way
70 to clear the iterpool with potentially lots of allocated memory */
71 svn_pool_destroy(iterpool
);
77 svn_iter_apr_array(svn_boolean_t
*completed
,
78 const apr_array_header_t
*array
,
79 svn_iter_apr_array_cb_t func
,
83 svn_error_t
*err
= SVN_NO_ERROR
;
84 apr_pool_t
*iterpool
= svn_pool_create(pool
);
87 for (i
= 0; (! err
) && i
< array
->nelts
; ++i
)
89 void *item
= array
->elts
+ array
->elt_size
*i
;
91 svn_pool_clear(iterpool
);
93 err
= (*func
)(baton
, item
, pool
);
99 if (err
&& err
->apr_err
== SVN_ERR_ITER_BREAK
)
101 if (err
!= &internal_break_error
)
102 /* Errors - except those created by svn_iter_break() -
103 need to be cleared when not further propagated. */
104 svn_error_clear(err
);
109 /* Clear iterpool, because callers may clear the error but have no way
110 to clear the iterpool with potentially lots of allocated memory */
111 svn_pool_destroy(iterpool
);
117 svn_iter__break(void)
119 return &internal_break_error
;