summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--include/apr_hash.h21
-rw-r--r--tables/apr_hash.c23
-rw-r--r--test/testhash.c7
4 files changed, 52 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 555dc85a6..4a2d60dad 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
-*- coding: utf-8 -*-
Changes for APR 2.0.0
+ *) Add apr_hash_this_key(), apr_hash_this_key_len(), and
+ apr_hash_this_val() for easier access to those attributes from
+ a hash iterator. [Hyrum K. Wright <hyrum_wright mail.utexas.edu>]
+
*) Enable platform specific support for the opening of a file or
pipe in non blocking module through the APR_FOPEN_NONBLOCK flag.
[Graham Leggett]
diff --git a/include/apr_hash.h b/include/apr_hash.h
index 8e48c7ecf..37d972f9d 100644
--- a/include/apr_hash.h
+++ b/include/apr_hash.h
@@ -167,6 +167,27 @@ APR_DECLARE(void) apr_hash_this(apr_hash_index_t *hi, const void **key,
apr_ssize_t *klen, void **val);
/**
+ * Get the current entry's key from the iteration state.
+ * @param hi The iteration state
+ * @return The pointer to the key
+ */
+APR_DECLARE(const void*) apr_hash_this_key(apr_hash_index_t *hi);
+
+/**
+ * Get the current entry's key length from the iteration state.
+ * @param hi The iteration state
+ * @return The key length
+ */
+APR_DECLARE(apr_ssize_t) apr_hash_this_key_len(apr_hash_index_t *hi);
+
+/**
+ * Get the current entry's value from the iteration state.
+ * @param hi The iteration state
+ * @return The pointer to the value
+ */
+APR_DECLARE(void*) apr_hash_this_val(apr_hash_index_t *hi);
+
+/**
* Get the number of key/value pairs in the hash table.
* @param ht The hash table
* @return The number of key/value pairs in the hash table.
diff --git a/tables/apr_hash.c b/tables/apr_hash.c
index 05ee42f46..d64e77941 100644
--- a/tables/apr_hash.c
+++ b/tables/apr_hash.c
@@ -156,6 +156,29 @@ APR_DECLARE(void) apr_hash_this(apr_hash_index_t *hi,
if (val) *val = (void *)hi->this->val;
}
+APR_DECLARE(const void *) apr_hash_this_key(apr_hash_index_t *hi)
+{
+ const void *key;
+
+ apr_hash_this(hi, &key, NULL, NULL);
+ return key;
+}
+
+APR_DECLARE(apr_ssize_t) apr_hash_this_key_len(apr_hash_index_t *hi)
+{
+ apr_ssize_t klen;
+
+ apr_hash_this(hi, NULL, &klen, NULL);
+ return klen;
+}
+
+APR_DECLARE(void *) apr_hash_this_val(apr_hash_index_t *hi)
+{
+ void *val;
+
+ apr_hash_this(hi, NULL, NULL, &val);
+ return val;
+}
/*
* Expanding a hash table
diff --git a/test/testhash.c b/test/testhash.c
index 6e7e518d5..9b6190b96 100644
--- a/test/testhash.c
+++ b/test/testhash.c
@@ -32,12 +32,13 @@ static int comp_string(const void *str1, const void *str2)
static void dump_hash(apr_pool_t *p, apr_hash_t *h, char str[][MAX_LTH])
{
apr_hash_index_t *hi;
- char *val, *key;
- apr_ssize_t len;
int i = 0;
for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) {
- apr_hash_this(hi,(void*) &key, &len, (void*) &val);
+ char *key = apr_hash_this_key(hi);
+ apr_ssize_t len = apr_hash_this_key_len(hi);
+ char *val = apr_hash_this_val(hi);
+
str[i][0]='\0';
apr_snprintf(str[i], MAX_LTH, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n",
str[i], key, len, val);