~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/iter.c

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* iter.c : iteration drivers
2
2
 *
3
3
 * ====================================================================
4
 
 * Copyright (c) 2007 CollabNet.  All rights reserved.
5
 
 *
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.
11
 
 *
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/.
 
4
 *    Licensed to the Apache Software Foundation (ASF) under one
 
5
 *    or more contributor license agreements.  See the NOTICE file
 
6
 *    distributed with this work for additional information
 
7
 *    regarding copyright ownership.  The ASF licenses this file
 
8
 *    to you under the Apache License, Version 2.0 (the
 
9
 *    "License"); you may not use this file except in compliance
 
10
 *    with the License.  You may obtain a copy of the License at
 
11
 *
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 *    Unless required by applicable law or agreed to in writing,
 
15
 *    software distributed under the License is distributed on an
 
16
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
 *    KIND, either express or implied.  See the License for the
 
18
 *    specific language governing permissions and limitations
 
19
 *    under the License.
15
20
 * ====================================================================
16
21
 */
17
22
 
18
23
 
19
24
#include "svn_iter.h"
20
25
#include "svn_pools.h"
 
26
#include "private/svn_dep_compat.h"
21
27
 
22
28
#include "svn_error_codes.h"
23
29
 
31
37
    __LINE__ /* line number */
32
38
  };
33
39
 
 
40
#if APR_VERSION_AT_LEAST(1, 4, 0)
 
41
struct hash_do_baton
 
42
{
 
43
  void *baton;
 
44
  svn_iter_apr_hash_cb_t func;
 
45
  svn_error_t *err;
 
46
  apr_pool_t *iterpool;
 
47
};
 
48
 
 
49
static
 
50
int hash_do_callback(void *baton,
 
51
                     const void *key,
 
52
                     apr_ssize_t klen,
 
53
                     const void *value)
 
54
{
 
55
  struct hash_do_baton *hdb = baton;
 
56
 
 
57
  svn_pool_clear(hdb->iterpool);
 
58
  hdb->err = (*hdb->func)(hdb->baton, key, klen, (void *)value, hdb->iterpool);
 
59
 
 
60
  return hdb->err == SVN_NO_ERROR;
 
61
}
 
62
#endif
 
63
 
34
64
svn_error_t *
35
65
svn_iter_apr_hash(svn_boolean_t *completed,
36
66
                  apr_hash_t *hash,
38
68
                  void *baton,
39
69
                  apr_pool_t *pool)
40
70
{
 
71
#if APR_VERSION_AT_LEAST(1, 4, 0)
 
72
  struct hash_do_baton hdb;
 
73
  svn_boolean_t error_received;
 
74
 
 
75
  hdb.func = func;
 
76
  hdb.baton = baton;
 
77
  hdb.iterpool = svn_pool_create(pool);
 
78
 
 
79
  error_received = !apr_hash_do(hash_do_callback, &hdb, hash);
 
80
 
 
81
  svn_pool_destroy(hdb.iterpool);
 
82
 
 
83
  if (completed)
 
84
    *completed = !error_received;
 
85
 
 
86
  if (!error_received)
 
87
    return SVN_NO_ERROR;
 
88
 
 
89
  if (hdb.err->apr_err == SVN_ERR_ITER_BREAK
 
90
        && hdb.err != &internal_break_error)
 
91
    {
 
92
        /* Errors - except those created by svn_iter_break() -
 
93
           need to be cleared when not further propagated. */
 
94
        svn_error_clear(hdb.err);
 
95
 
 
96
        hdb.err = SVN_NO_ERROR;
 
97
    }
 
98
 
 
99
  return hdb.err;
 
100
#else
41
101
  svn_error_t *err = SVN_NO_ERROR;
42
102
  apr_pool_t *iterpool = svn_pool_create(pool);
43
103
  apr_hash_index_t *hi;
73
133
  svn_pool_destroy(iterpool);
74
134
 
75
135
  return err;
 
136
#endif
76
137
}
77
138
 
78
139
svn_error_t *
92
153
 
93
154
      svn_pool_clear(iterpool);
94
155
 
95
 
      err = (*func)(baton, item, pool);
 
156
      err = (*func)(baton, item, iterpool);
96
157
    }
97
158
 
98
159
  if (completed)
120
181
{
121
182
  return &internal_break_error;
122
183
}
 
184
 
 
185
/* Note about the type casts:  apr_hash_this() does not expect a const hash
 
186
 * index pointer even though it does not modify the hash index.  In
 
187
 * Subversion we're trying to be const-correct, so these functions all take
 
188
 * a const hash index and we cast away the const when passing it down to
 
189
 * APR.  (A compiler may warn about casting away 'const', but at least this
 
190
 * cast is explicit and gathered in one place.) */
 
191
 
 
192
const void *svn__apr_hash_index_key(const apr_hash_index_t *hi)
 
193
{
 
194
  const void *key;
 
195
 
 
196
  apr_hash_this((apr_hash_index_t *)hi, &key, NULL, NULL);
 
197
  return key;
 
198
}
 
199
 
 
200
apr_ssize_t svn__apr_hash_index_klen(const apr_hash_index_t *hi)
 
201
{
 
202
  apr_ssize_t klen;
 
203
 
 
204
  apr_hash_this((apr_hash_index_t *)hi, NULL, &klen, NULL);
 
205
  return klen;
 
206
}
 
207
 
 
208
void *svn__apr_hash_index_val(const apr_hash_index_t *hi)
 
209
{
 
210
  void *val;
 
211
 
 
212
  apr_hash_this((apr_hash_index_t *)hi, NULL, NULL, &val);
 
213
  return val;
 
214
}