apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r1462461 - in /apr/apr/branches/1.5.x: ./ CHANGES include/apr_hash.h tables/apr_hash.c test/testhash.c
Date Fri, 29 Mar 2013 12:45:22 GMT
Author: rjung
Date: Fri Mar 29 12:45:21 2013
New Revision: 1462461

URL: http://svn.apache.org/r1462461
Log:
* 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.

PR: 49065
Submitted by: Hyrum K. Wright <hyrum_wright mail.utexas.edu>
Reviewed by: trawick, wrowe
Backport by: rjung

Backport of r931973 from trunk.

* test/testhash.c (dump_hash): Fix compiler warning due to lack of const.

Submitted by: jorton
Backport by: rjung

Backport of r951771 from trunk.

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/CHANGES
    apr/apr/branches/1.5.x/include/apr_hash.h
    apr/apr/branches/1.5.x/tables/apr_hash.c
    apr/apr/branches/1.5.x/test/testhash.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r931973,951771

Modified: apr/apr/branches/1.5.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/CHANGES?rev=1462461&r1=1462460&r2=1462461&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.5.x/CHANGES [utf-8] Fri Mar 29 12:45:21 2013
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.5.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>]
+
   *) MinGW/MSYS:  Support shared builds of APR, other general improvements
      to support of this toolchain.  PR 46175.  [Carlo Bramini 
      <carlo.bramix libero.it>]  

Modified: apr/apr/branches/1.5.x/include/apr_hash.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/include/apr_hash.h?rev=1462461&r1=1462460&r2=1462461&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/include/apr_hash.h (original)
+++ apr/apr/branches/1.5.x/include/apr_hash.h Fri Mar 29 12:45:21 2013
@@ -167,6 +167,27 @@ APR_DECLARE(void) apr_hash_this(apr_hash
                                 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.

Modified: apr/apr/branches/1.5.x/tables/apr_hash.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/tables/apr_hash.c?rev=1462461&r1=1462460&r2=1462461&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/tables/apr_hash.c (original)
+++ apr/apr/branches/1.5.x/tables/apr_hash.c Fri Mar 29 12:45:21 2013
@@ -162,6 +162,29 @@ APR_DECLARE(void) apr_hash_this(apr_hash
     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

Modified: apr/apr/branches/1.5.x/test/testhash.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/test/testhash.c?rev=1462461&r1=1462460&r2=1462461&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/test/testhash.c (original)
+++ apr/apr/branches/1.5.x/test/testhash.c Fri Mar 29 12:45:21 2013
@@ -32,12 +32,13 @@ static int comp_string(const void *str1,
 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);
+        const 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);



Mime
View raw message