[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

patch: Add svn_pool_clear helper.

From: Bill Tutt <billtut_at_microsoft.com>
Date: 2001-01-10 10:54:55 CET

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);
 }
Received on Sat Oct 21 14:36:19 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.