You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Bill Tutt <bi...@microsoft.com> on 2001/01/10 09:54:55 UTC

patch: Add svn_pool_clear helper.

The comment in svn_error.h pretty much says it all.
I ran into this by trying to reuse the same pool for all VB UI thread pool
needs.
(i.e. calling apr_pool_clear before returning from each COM function call)

*	include/svn_error.h: Prototype svn_pool_clear in order to reattach
error pool.
*	libsvn_subr/svn_error.c: Implement svn_pool_clear.
*	libsvn_fs/tests/skel-test.c: Use svn_pool_clear.

Ok to commit?

Thanks,
Bill

Index: include/svn_error.h
===================================================================
RCS file: /cvs/subversion/subversion/include/svn_error.h,v
retrieving revision 1.64
diff -u -r1.64 svn_error.h
--- include/svn_error.h	2000/12/26 23:28:29	1.64
+++ include/svn_error.h	2001/01/10 09:54:27
@@ -268,6 +268,16 @@
 apr_pool_t *svn_pool_create (apr_pool_t *parent_pool);
 
 
+/* Clear the passed in pool.
+ *
+ * The reason we need this wrapper to apr_pool_clear, is because
+ * apr_pool_clear removes the association with the appropriate
+ * error pool. This wrapper calls apr_pool_clear, and then
+ * reattaches the error pool.
+ *
+ * If anything goes wrong, an abort function will be called.
+ */
+void svn_pool_clear (apr_pool_t *p);
 
 
 /*** SVN error creation and destruction. ***/
Index: libsvn_subr/svn_error.c
===================================================================
RCS file: /cvs/subversion/subversion/libsvn_subr/svn_error.c,v
retrieving revision 1.47
diff -u -r1.47 svn_error.c
--- libsvn_subr/svn_error.c	2000/11/22 23:49:16	1.47
+++ libsvn_subr/svn_error.c	2001/01/10 09:54:27
@@ -109,12 +109,39 @@
                            top_pool);
 }
 
+static void
+svn_pool__attach_error_pool(apr_pool_t *p)
+{
+  apr_pool_t *error_pool;
+  apr_status_t apr_err;
+  apr_pool_t *parent_pool;
+
+  if (p->parent == NULL)
+	  parent_pool = p;
+  else
+	  parent_pool = p->parent;
+
+  /* Fetch the error pool from the parent (possibly the new one). */
+  apr_get_userdata ((void **) &error_pool, SVN_ERROR_POOL, parent_pool);
+  if (error_pool == NULL)
+    (*abort_on_pool_failure) (SVN_ERR_BAD_CONTAINING_POOL);
+
+  /* Set the error pool on the newly-created pool. */
+  apr_err = apr_set_userdata (error_pool,
+                              SVN_ERROR_POOL,
+                              apr_null_cleanup,
+                              p);
+  if (apr_err)
+    (*abort_on_pool_failure) (apr_err);
+
+}
+
+
 apr_pool_t *
 svn_pool_create (apr_pool_t *parent_pool)
 {
   apr_pool_t *ret_pool;
   apr_status_t apr_err;
-  apr_pool_t *error_pool;
 
   ret_pool = apr_make_sub_pool (parent_pool, abort_on_pool_failure);
 
@@ -127,20 +154,21 @@
         (*abort_on_pool_failure) (apr_err);
     }
 
-  /* Fetch the error pool from the parent (possibly the new one). */
-  apr_get_userdata ((void **) &error_pool, SVN_ERROR_POOL, parent_pool);
-  if (error_pool == NULL)
-    (*abort_on_pool_failure) (SVN_ERR_BAD_CONTAINING_POOL);
+  svn_pool__attach_error_pool(ret_pool);
+  
+  return ret_pool;
+}
+
 
-  /* Set the error pool on the newly-created pool. */
-  apr_err = apr_set_userdata (error_pool,
-                              SVN_ERROR_POOL,
-                              apr_null_cleanup,
-                              ret_pool);
-  if (apr_err)
-    (*abort_on_pool_failure) (apr_err);
 
-  return ret_pool;
+void 
+svn_pool_clear(apr_pool_t *p)
+{
+  apr_clear_pool(p);
+  /* Clearing the pool, invalidates all userdata attached to the pool,
+	 so reattach the error pool. */
+  
+  svn_pool__attach_error_pool(p);
 }
 
 
Index: libsvn_fs/tests/skel-test.c
===================================================================
RCS file: /cvs/subversion/subversion/libsvn_fs/tests/skel-test.c,v
retrieving revision 1.12
diff -u -r1.12 skel-test.c
--- libsvn_fs/tests/skel-test.c	2000/12/15 05:19:52	1.12
+++ libsvn_fs/tests/skel-test.c	2001/01/10 09:54:27
@@ -39,7 +39,7 @@
 static svn_string_t *
 get_empty_string (void)
 {
-  apr_clear_pool (pool);
+  svn_pool_clear (pool);
 
   return svn_string_ncreate (0, 0, pool);
 }