apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r538391 - in /apr/apr/trunk: include/apr_tables.h tables/apr_tables.c test/testtable.c
Date Wed, 16 May 2007 00:17:04 GMT
Author: pquerna
Date: Tue May 15 17:17:03 2007
New Revision: 538391

URL: http://svn.apache.org/viewvc?view=rev&rev=538391
Log:
Add apr_array_clear() API.

* include/apr_tables.h
* tables/apr_tables.c
  (apr_array_clear): Declare and define new API.

* test/testtable.c
  (a1): Static variable for use across array tests.
  (array_clear): New test for apr_array_clear().
  (testtable): Add array_clear() to the test suite.

Submitted By: Daniel Rall <dlr apache.org>

Modified:
    apr/apr/trunk/include/apr_tables.h
    apr/apr/trunk/tables/apr_tables.c
    apr/apr/trunk/test/testtable.c

Modified: apr/apr/trunk/include/apr_tables.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_tables.h?view=diff&rev=538391&r1=538390&r2=538391
==============================================================================
--- apr/apr/trunk/include/apr_tables.h (original)
+++ apr/apr/trunk/include/apr_tables.h Tue May 15 17:17:03 2007
@@ -148,6 +148,14 @@
 APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr);
 
 /**
+ * Remove all elements from an array.
+ * @param arr The array to remove all elements from.
+ * @remark As the underlying storage is allocated from a pool, no
+ * memory is freed by this operation, but is available for reuse.
+ */
+APR_DECLARE(void) apr_array_clear(apr_array_header_t *arr);
+
+/**
  * Concatenate two arrays together
  * @param dst The destination array, and the one to go first in the combined 
  *            array

Modified: apr/apr/trunk/tables/apr_tables.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_tables.c?view=diff&rev=538391&r1=538390&r2=538391
==============================================================================
--- apr/apr/trunk/tables/apr_tables.c (original)
+++ apr/apr/trunk/tables/apr_tables.c Tue May 15 17:17:03 2007
@@ -90,6 +90,11 @@
     return res;
 }
 
+APR_DECLARE(void) apr_array_clear(apr_array_header_t *arr)
+{
+    arr->nelts = 0;
+}
+
 APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr)
 {
     if (apr_is_empty_array(arr)) {

Modified: apr/apr/trunk/test/testtable.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testtable.c?view=diff&rev=538391&r1=538390&r2=538391
==============================================================================
--- apr/apr/trunk/test/testtable.c (original)
+++ apr/apr/trunk/test/testtable.c Tue May 15 17:17:03 2007
@@ -30,8 +30,18 @@
 #include <string.h>
 #endif
 
+static apr_array_header_t *a1 = NULL;
 static apr_table_t *t1 = NULL;
 
+static void array_clear(abts_case *tc, void *data)
+{
+    a1 = apr_array_make(p, 2, sizeof(const char *));
+    APR_ARRAY_PUSH(a1, const char *) = "foo";
+    APR_ARRAY_PUSH(a1, const char *) = "bar";
+    apr_array_clear(a1);
+    ABTS_INT_EQUAL(tc, 0, a1->nelts);
+}
+
 static void table_make(abts_case *tc, void *data)
 {
     t1 = apr_table_make(p, 5);
@@ -174,6 +184,7 @@
 {
     suite = ADD_SUITE(suite)
 
+    abts_run_test(suite, array_clear, NULL);
     abts_run_test(suite, table_make, NULL);
     abts_run_test(suite, table_get, NULL);
     abts_run_test(suite, table_set, NULL);



Mime
View raw message