diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | include/apr_pools.h | 20 | ||||
-rw-r--r-- | memory/unix/apr_pools.c | 21 |
3 files changed, 43 insertions, 2 deletions
@@ -1,5 +1,9 @@ Changes with APR b1 + *) Introduce the apr_pool_userdata_setn() variant that doesn't + strdup the key. Allows both the _setn() and _set() variant to + accept NULL for the cleanup. [Brian Pane <bpane@pacbell.net] + *) Re-vamp the apr_proc_wait and apr_proc_wait_all functions. We now return the exit code from the program and a reason that the program died, either normal exit or signalled. diff --git a/include/apr_pools.h b/include/apr_pools.h index d2075245c..6bd94e230 100644 --- a/include/apr_pools.h +++ b/include/apr_pools.h @@ -264,7 +264,7 @@ APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool); * Set the data associated with the current pool * @param data The user data associated with the pool. * @param key The key to use for association - * @param cleanup The cleanup program to use to cleanup the data + * @param cleanup The cleanup program to use to cleanup the data (NULL if none) * @param cont The current pool * @warning The data to be attached to the pool should have a life span * at least as long as the pool it is being attached to. @@ -282,6 +282,24 @@ APR_DECLARE(apr_status_t) apr_pool_userdata_set(const void *data, apr_pool_t *cont); /** + * Set the data associated with the current pool + * @param data The user data associated with the pool. + * @param key The key to use for association + * @param cleanup The cleanup program to use to cleanup the data (NULL if none) + * @param cont The current pool + * @note same as apr_pool_userdata_set(), except that this version doesn't + * make a copy of the key (this function is useful, for example, when + * the key is a string literal) + * @warning The key and the data to be attached to the pool should have + * a life span at least as long as the pool itself. + * + */ +APR_DECLARE(apr_status_t) apr_pool_userdata_setn(const void *data, + const char *key, + apr_status_t (*cleanup)(void *), + apr_pool_t *cont); + +/** * Return the data associated with the current pool. * @param data The user data associated with the pool. * @param key The key for the data to retrieve diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c index fd0ba05cb..5f043f77e 100644 --- a/memory/unix/apr_pools.c +++ b/memory/unix/apr_pools.c @@ -1284,7 +1284,26 @@ APR_DECLARE(apr_status_t) apr_pool_userdata_set(const void *data, const char *ke apr_hash_set(cont->prog_data, key, keylen, data); } - apr_pool_cleanup_register(cont, data, cleanup, cleanup); + if (cleanup) { + apr_pool_cleanup_register(cont, data, cleanup, cleanup); + } + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_pool_userdata_setn(const void *data, const char *key, + apr_status_t (*cleanup) (void *), + apr_pool_t *cont) +{ + apr_size_t keylen = strlen(key); + + if (cont->prog_data == NULL) + cont->prog_data = apr_hash_make(cont); + + apr_hash_set(cont->prog_data, key, keylen, data); + + if (cleanup) { + apr_pool_cleanup_register(cont, data, cleanup, cleanup); + } return APR_SUCCESS; } |