You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2012/01/31 03:13:44 UTC

svn commit: r1238132 - in /apr/apr/branches/1.5.x: include/apr_hash.h tables/apr_hash.c

Author: bojan
Date: Tue Jan 31 02:13:44 2012
New Revision: 1238132

URL: http://svn.apache.org/viewvc?rev=1238132&view=rev
Log:
Revert r817809 on 1.5.x branch.
Makes hash table data unavailabe in pool cleanups registered with the pool.

Modified:
    apr/apr/branches/1.5.x/include/apr_hash.h
    apr/apr/branches/1.5.x/tables/apr_hash.c

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=1238132&r1=1238131&r2=1238132&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/include/apr_hash.h (original)
+++ apr/apr/branches/1.5.x/include/apr_hash.h Tue Jan 31 02:13:44 2012
@@ -73,7 +73,7 @@ APR_DECLARE_NONSTD(unsigned int) apr_has
 /**
  * Create a hash table.
  * @param pool The pool to allocate the hash table out of
- * @return The hash table just created, or NULL if memory allocation failed
+ * @return The hash table just created
   */
 APR_DECLARE(apr_hash_t *) apr_hash_make(apr_pool_t *pool);
 
@@ -81,7 +81,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_make(
  * Create a hash table with a custom hash function
  * @param pool The pool to allocate the hash table out of
  * @param hash_func A custom hash function.
- * @return The hash table just created, or NULL if memory allocation failed
+ * @return The hash table just created
   */
 APR_DECLARE(apr_hash_t *) apr_hash_make_custom(apr_pool_t *pool, 
                                                apr_hashfunc_t hash_func);
@@ -90,7 +90,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_make_
  * Make a copy of a hash table
  * @param pool The pool from which to allocate the new hash table
  * @param h The hash table to clone
- * @return The hash table just created, or NULL if memory allocation failed
+ * @return The hash table just created
  * @remark Makes a shallow copy
  */
 APR_DECLARE(apr_hash_t *) apr_hash_copy(apr_pool_t *pool,
@@ -186,8 +186,7 @@ APR_DECLARE(void) apr_hash_clear(apr_has
  * @param p The pool to use for the new hash table
  * @param overlay The table to add to the initial table
  * @param base The table that represents the initial values of the new table
- * @return A new hash table containing all of the data from the two passed in,
- *         or NULL if memory allocation failed
+ * @return A new hash table containing all of the data from the two passed in
  */
 APR_DECLARE(apr_hash_t *) apr_hash_overlay(apr_pool_t *p,
                                            const apr_hash_t *overlay, 
@@ -205,8 +204,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_overl
  *  make values from h1 override values from h2 (same semantics as
  *  apr_hash_overlay())
  * @param data Client data to pass to the merger function
- * @return A new hash table containing all of the data from the two passed in,
- *         or NULL if memory allocation failed.
+ * @return A new hash table containing all of the data from the two passed in
  */
 APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p,
                                          const apr_hash_t *h1,

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=1238132&r1=1238131&r2=1238132&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/tables/apr_hash.c (original)
+++ apr/apr/branches/1.5.x/tables/apr_hash.c Tue Jan 31 02:13:44 2012
@@ -68,15 +68,12 @@ struct apr_hash_index_t {
 /*
  * The size of the array is always a power of two. We use the maximum
  * index rather than the size so that we can use bitwise-AND for
- * modular arithmetic. The count of hash entries may be greater
- * depending on the chosen collision rate.
- *
- * We allocate the bucket array in a sub-pool, "array_pool". This allows us
- * to reclaim the old bucket array after an expansion.
+ * modular arithmetic.
+ * The count of hash entries may be greater depending on the chosen
+ * collision rate.
  */
 struct apr_hash_t {
     apr_pool_t          *pool;
-    apr_pool_t          *array_pool;
     apr_hash_entry_t   **array;
     apr_hash_index_t     iterator;  /* For apr_hash_first(NULL, ...) */
     unsigned int         count, max, seed;
@@ -93,21 +90,16 @@ struct apr_hash_t {
 
 static apr_hash_entry_t **alloc_array(apr_hash_t *ht, unsigned int max)
 {
-   return apr_pcalloc(ht->array_pool, sizeof(*ht->array) * (max + 1));
+   return apr_pcalloc(ht->pool, sizeof(*ht->array) * (max + 1));
 }
 
 APR_DECLARE(apr_hash_t *) apr_hash_make(apr_pool_t *pool)
 {
-    apr_pool_t *array_pool;
     apr_hash_t *ht;
     apr_time_t now = apr_time_now();
 
-    if (apr_pool_create(&array_pool, pool) != APR_SUCCESS)
-        return NULL;
-
     ht = apr_palloc(pool, sizeof(apr_hash_t));
     ht->pool = pool;
-    ht->array_pool = array_pool;
     ht->free = NULL;
     ht->count = 0;
     ht->max = INITIAL_MAX;
@@ -177,17 +169,10 @@ APR_DECLARE(void) apr_hash_this(apr_hash
 
 static void expand_array(apr_hash_t *ht)
 {
-    apr_pool_t *new_array_pool;
-    apr_pool_t *old_array_pool;
     apr_hash_index_t *hi;
     apr_hash_entry_t **new_array;
     unsigned int new_max;
 
-    if (apr_pool_create(&new_array_pool, ht->pool) != APR_SUCCESS)
-        return; /* Give up and don't try to expand the array */
-    old_array_pool = ht->array_pool;
-    ht->array_pool = new_array_pool;
-
     new_max = ht->max * 2 + 1;
     new_array = alloc_array(ht, new_max);
     for (hi = apr_hash_first(NULL, ht); hi; hi = apr_hash_next(hi)) {
@@ -197,8 +182,6 @@ static void expand_array(apr_hash_t *ht)
     }
     ht->array = new_array;
     ht->max = new_max;
-
-    apr_pool_destroy(old_array_pool);
 }
 
 static unsigned int hashfunc_default(const char *char_key, apr_ssize_t *klen,
@@ -318,26 +301,23 @@ static apr_hash_entry_t **find_entry(apr
 APR_DECLARE(apr_hash_t *) apr_hash_copy(apr_pool_t *pool,
                                         const apr_hash_t *orig)
 {
-    apr_pool_t *array_pool;
     apr_hash_t *ht;
     apr_hash_entry_t *new_vals;
     unsigned int i, j;
 
-    if (apr_pool_create(&array_pool, pool) != APR_SUCCESS)
-        return NULL;
-
     ht = apr_palloc(pool, sizeof(apr_hash_t) +
+                    sizeof(*ht->array) * (orig->max + 1) +
                     sizeof(apr_hash_entry_t) * orig->count);
     ht->pool = pool;
-    ht->array_pool = array_pool;
     ht->free = NULL;
     ht->count = orig->count;
     ht->max = orig->max;
     ht->seed = orig->seed;
     ht->hash_func = orig->hash_func;
-    ht->array = alloc_array(ht, ht->max);
+    ht->array = (apr_hash_entry_t **)((char *)ht + sizeof(apr_hash_t));
 
-    new_vals = (apr_hash_entry_t *)((char *)(ht) + sizeof(apr_hash_t));
+    new_vals = (apr_hash_entry_t *)((char *)(ht) + sizeof(apr_hash_t) +
+                                    sizeof(*ht->array) * (orig->max + 1));
     j = 0;
     for (i = 0; i <= ht->max; i++) {
         apr_hash_entry_t **new_entry = &(ht->array[i]);
@@ -426,7 +406,6 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge
                                                      const void *data),
                                          const void *data)
 {
-    apr_pool_t *array_pool;
     apr_hash_t *res;
     apr_hash_entry_t *new_vals = NULL;
     apr_hash_entry_t *iter;
@@ -450,12 +429,8 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge
     }
 #endif
 
-    if (apr_pool_create(&array_pool, p) != APR_SUCCESS)
-        return NULL;
-
     res = apr_palloc(p, sizeof(apr_hash_t));
     res->pool = p;
-    res->array_pool = array_pool;
     res->free = NULL;
     res->hash_func = base->hash_func;
     res->count = base->count;