aboutsummaryrefslogtreecommitdiff
path: root/crypto/sparse_array.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2019-02-14 08:13:58 +1000
committerPauli <paul.dale@oracle.com>2019-02-14 09:09:51 +1000
commit008b4ff92f785cf3808df26ac5b23f25a691b23c (patch)
tree01dd98cf5b1ec718fd720effef0c6152b37256bc /crypto/sparse_array.c
parentfa63e45262971b9c2a6aeb33db8c52a5a84fc8b5 (diff)
downloadopenssl-008b4ff92f785cf3808df26ac5b23f25a691b23c.zip
openssl-008b4ff92f785cf3808df26ac5b23f25a691b23c.tar.gz
openssl-008b4ff92f785cf3808df26ac5b23f25a691b23c.tar.bz2
Sparse array iterators include index position.
Iterators over the sparse array structures have gained an initial argument which indicates the index into the array of the element. This can be used, e.g., to delete or modify the associated value. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8229)
Diffstat (limited to 'crypto/sparse_array.c')
-rw-r--r--crypto/sparse_array.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/crypto/sparse_array.c b/crypto/sparse_array.c
index 8c9efed..796d35e 100644
--- a/crypto/sparse_array.c
+++ b/crypto/sparse_array.c
@@ -68,10 +68,11 @@ OPENSSL_SA *OPENSSL_SA_new(void)
}
static void sa_doall(const OPENSSL_SA *sa, void (*node)(void **),
- void (*leaf)(void *, void *), void *arg)
+ void (*leaf)(size_t, void *, void *), void *arg)
{
int i[SA_BLOCK_MAX_LEVELS];
void *nodes[SA_BLOCK_MAX_LEVELS];
+ size_t idx = 0;
int l = 0;
i[0] = 0;
@@ -84,14 +85,17 @@ static void sa_doall(const OPENSSL_SA *sa, void (*node)(void **),
if (p != NULL && node != NULL)
(*node)(p);
l--;
+ idx >>= OPENSSL_SA_BLOCK_BITS;
} else {
i[l] = n + 1;
if (p != NULL && p[n] != NULL) {
+ idx = (idx & ~SA_BLOCK_MASK) | n;
if (l < sa->levels - 1) {
i[++l] = 0;
nodes[l] = p[n];
+ idx <<= OPENSSL_SA_BLOCK_BITS;
} else if (leaf != NULL) {
- (*leaf)(p[n], arg);
+ (*leaf)(idx, p[n], arg);
}
}
}
@@ -103,7 +107,7 @@ static void sa_free_node(void **p)
OPENSSL_free(p);
}
-static void sa_free_leaf(void *p, void *arg)
+static void sa_free_leaf(size_t n, void *p, void *arg)
{
OPENSSL_free(p);
}
@@ -122,15 +126,15 @@ void OPENSSL_SA_free_leaves(OPENSSL_SA *sa)
/* Wrap this in a structure to avoid compiler warnings */
struct trampoline_st {
- void (*func)(void *);
+ void (*func)(size_t, void *);
};
-static void trampoline(void *l, void *arg)
+static void trampoline(size_t n, void *l, void *arg)
{
- ((const struct trampoline_st *)arg)->func(l);
+ ((const struct trampoline_st *)arg)->func(n, l);
}
-void OPENSSL_SA_doall(const OPENSSL_SA *sa, void (*leaf)(void *))
+void OPENSSL_SA_doall(const OPENSSL_SA *sa, void (*leaf)(size_t, void *))
{
struct trampoline_st tramp;
@@ -139,8 +143,8 @@ void OPENSSL_SA_doall(const OPENSSL_SA *sa, void (*leaf)(void *))
sa_doall(sa, NULL, &trampoline, &tramp);
}
-void OPENSSL_SA_doall_arg(const OPENSSL_SA *sa, void (*leaf)(void *, void *),
- void *arg)
+void OPENSSL_SA_doall_arg(const OPENSSL_SA *sa,
+ void (*leaf)(size_t, void *, void *), void *arg)
{
if (sa != NULL)
sa_doall(sa, NULL, leaf, arg);