Two small improvements for apr_pool_userdata_set():
* A "setn" variant that doesn't strdup the key (useful when,
 for example, the key is a compile-time constant)
* Support for passing in NULL as the cleanup callback, so
 that items that don't require a cleanup need not incur
 the overhead of registering a no-op callback.

The patch includes changes for Apache's request.c and
mod_log_config to take advantage of these features.

--Brian

Index: srclib/apr/include/apr_pools.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_pools.h,v
retrieving revision 1.61
diff -u -r1.61 apr_pools.h
--- srclib/apr/include/apr_pools.h      2001/09/28 15:22:35     1.61
+++ srclib/apr/include/apr_pools.h      2001/10/17 05:13:22
@@ -264,7 +264,7 @@
  * 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.
@@ -280,6 +280,24 @@
                                                const char *key,
                                                apr_status_t (*cleanup)(void *),
                                                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.
Index: srclib/apr/memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvspublic/apr/memory/unix/apr_pools.c,v
retrieving revision 1.113
diff -u -r1.113 apr_pools.c
--- srclib/apr/memory/unix/apr_pools.c  2001/09/28 15:22:35     1.113
+++ srclib/apr/memory/unix/apr_pools.c  2001/10/17 05:13:23
@@ -1284,7 +1284,26 @@
         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;
 }
 
Index: server/request.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/request.c,v
retrieving revision 1.74
diff -u -r1.74 request.c
--- server/request.c    2001/10/16 02:23:42     1.74
+++ server/request.c    2001/10/17 05:13:24
@@ -327,8 +327,7 @@
             cache = apr_pcalloc(r->pool, sizeof(*cache));
             cache->walked = apr_array_make(r->pool, 4, sizeof(walk_walked_t));
         }
-        apr_pool_userdata_set(cache, cache_name, 
-                              apr_pool_cleanup_null, r->pool);
+        apr_pool_userdata_setn(cache, cache_name, NULL, r->pool);
     }
     return cache;
 }
Index: modules/loggers/mod_log_config.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/loggers/mod_log_config.c,v
retrieving revision 1.69
diff -u -r1.69 mod_log_config.c
--- modules/loggers/mod_log_config.c    2001/09/19 06:53:26     1.69
+++ modules/loggers/mod_log_config.c    2001/10/17 05:13:25
@@ -1024,8 +1024,8 @@
      */
     apr_pool_userdata_get(&data, userdata_key, s->process->pool);
     if (!data) {
-        apr_pool_userdata_set((const void *)1, userdata_key,
-                         apr_pool_cleanup_null, s->process->pool);
+        apr_pool_userdata_setn((const void *)1, userdata_key,
+                               NULL, s->process->pool);
         /* If logging for the first time after a restart, keep going. */
         if (!ap_my_generation) {
             return cls;

Reply via email to