subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r1173170 - in /subversion/trunk/subversion: include/private/svn_subr_private.h libsvn_subr/spillbuf.c tests/libsvn_subr/spillbuf-test.c
Date Tue, 20 Sep 2011 14:39:52 GMT
Author: gstein
Date: Tue Sep 20 14:39:52 2011
New Revision: 1173170

URL: http://svn.apache.org/viewvc?rev=1173170&view=rev
Log:
Add a pool parameter to the spill buffer's read callback, and add a test
for the callback.

* subversion/include/private/svn_subr_private.h:
  (svn_spillbuf_read_t): add a SCRATCH_POOL parameter

* subversion/libsvn_subr/spillbuf.c:
  (svn_spillbuf_write): delete the file on close, rather than pool
    cleanup. we may periodically close the file during the course of a
    spill buffer's usage.
  (svn_spillbuf_process): create an iterpool and pass it to the callback

* subversion/tests/libsvn_subr/spillbuf-test.c:
  (read_callback): new callback for reading content from the buffer
  (test_spillbuf_callback): new test for the callback style of reading
  (test_funcs): add new test

Modified:
    subversion/trunk/subversion/include/private/svn_subr_private.h
    subversion/trunk/subversion/libsvn_subr/spillbuf.c
    subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c

Modified: subversion/trunk/subversion/include/private/svn_subr_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_subr_private.h?rev=1173170&r1=1173169&r2=1173170&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_subr_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_subr_private.h Tue Sep 20 14:39:52 2011
@@ -79,7 +79,8 @@ svn_spillbuf_read(const char **data,
 typedef svn_error_t * (*svn_spillbuf_read_t)(svn_boolean_t *stop,
                                              void *baton,
                                              const char *data,
-                                             apr_size_t len);
+                                             apr_size_t len,
+                                             apr_pool_t *scratch_pool);
 
 
 /* Process the content stored in the spill buffer. @a exhausted will be

Modified: subversion/trunk/subversion/libsvn_subr/spillbuf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/spillbuf.c?rev=1173170&r1=1173169&r2=1173170&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/spillbuf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/spillbuf.c Tue Sep 20 14:39:52 2011
@@ -24,6 +24,8 @@
 #include <apr_file_io.h>
 
 #include "svn_io.h"
+#include "svn_pools.h"
+
 #include "private/svn_subr_private.h"
 
 
@@ -150,7 +152,7 @@ svn_spillbuf_write(svn_spillbuf_t *buf,
       SVN_ERR(svn_io_open_unique_file3(&buf->spill,
                                        NULL /* temp_path */,
                                        NULL /* dirpath */,
-                                       svn_io_file_del_on_pool_cleanup,
+                                       svn_io_file_del_on_close,
                                        buf->pool, scratch_pool));
     }
 
@@ -345,6 +347,7 @@ svn_spillbuf_process(svn_boolean_t *exha
                      apr_pool_t *scratch_pool)
 {
   svn_boolean_t has_seeked = FALSE;
+  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
 
   *exhausted = FALSE;
 
@@ -354,30 +357,33 @@ svn_spillbuf_process(svn_boolean_t *exha
       svn_error_t *err;
       svn_boolean_t stop;
 
+      svn_pool_clear(iterpool);
+
       /* If this call to read_data() will read from the spill file, and we
          have not seek'd the file... then do it now.  */
       if (!has_seeked)
-        SVN_ERR(maybe_seek(&has_seeked, buf, scratch_pool));
+        SVN_ERR(maybe_seek(&has_seeked, buf, iterpool));
 
       /* Get some content to pass to the read callback.  */
-      SVN_ERR(read_data(&mem, buf, scratch_pool));
+      SVN_ERR(read_data(&mem, buf, iterpool));
       if (mem == NULL)
         {
           *exhausted = TRUE;
-          return SVN_NO_ERROR;
+          break;
         }
 
-      err = read_func(&stop, read_baton, mem->data, mem->size);
+      err = read_func(&stop, read_baton, mem->data, mem->size, iterpool);
 
       return_buffer(buf, mem);
-      
+
       if (err)
         return svn_error_trace(err);
 
       /* If the callbacks told us to stop, then we're done for now.  */
       if (stop)
-        return SVN_NO_ERROR;
+        break;
     }
 
-  /* NOTREACHED */
+  svn_pool_destroy(iterpool);
+  return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c?rev=1173170&r1=1173169&r2=1173170&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Tue Sep 20 14:39:52 2011
@@ -76,6 +76,52 @@ test_spillbuf_basic(apr_pool_t *pool)
 
 
 static svn_error_t *
+read_callback(svn_boolean_t *stop,
+              void *baton,
+              const char *data,
+              apr_size_t len,
+              apr_pool_t *scratch_pool)
+{
+  int *counter = baton;
+
+  SVN_TEST_ASSERT(len == sizeof(basic_data));
+  SVN_TEST_ASSERT(memcmp(data, basic_data, len) == 0);
+
+  *stop = (++*counter == 10);
+
+  return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+test_spillbuf_callback(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf_create(
+                          sizeof(basic_data) /* blocksize */,
+                          10 * sizeof(basic_data) /* maxsize */,
+                          pool);
+  int i;
+  int counter;
+  svn_boolean_t exhausted;
+
+  /* Place enough data into the buffer to cause a spill to disk.  */
+  for (i = 20; i--; )
+    SVN_ERR(svn_spillbuf_write(buf, basic_data, sizeof(basic_data), pool));
+
+  counter = 0;
+  SVN_ERR(svn_spillbuf_process(&exhausted, buf, read_callback, &counter,
+                               pool));
+  SVN_TEST_ASSERT(!exhausted);
+  
+  SVN_ERR(svn_spillbuf_process(&exhausted, buf, read_callback, &counter,
+                               pool));
+  SVN_TEST_ASSERT(exhausted);
+
+  return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
 test_spillbuf_file(apr_pool_t *pool)
 {
   svn_spillbuf_t *buf = svn_spillbuf_create(
@@ -200,6 +246,7 @@ struct svn_test_descriptor_t test_funcs[
   {
     SVN_TEST_NULL,
     SVN_TEST_PASS2(test_spillbuf_basic, "basic spill buffer test"),
+    SVN_TEST_PASS2(test_spillbuf_callback, "spill buffer read callback"),
     SVN_TEST_PASS2(test_spillbuf_file, "spill buffer file test"),
     SVN_TEST_PASS2(test_spillbuf_interleaving,
                    "interleaving reads and writes"),



Mime
View raw message