Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 19857 invoked from network); 5 Dec 2006 18:59:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Dec 2006 18:59:06 -0000 Received: (qmail 48993 invoked by uid 500); 5 Dec 2006 18:59:13 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 48930 invoked by uid 500); 5 Dec 2006 18:59:12 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 48914 invoked by uid 99); 5 Dec 2006 18:59:12 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Dec 2006 10:59:12 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [208.185.179.196] (HELO anvil) (208.185.179.196) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Dec 2006 10:59:00 -0800 Received: by anvil (Postfix, from userid 500) id 3FE97E74750; Tue, 5 Dec 2006 10:57:24 -0800 (PST) Date: Tue, 5 Dec 2006 10:57:24 -0800 From: Daniel Rall To: dev@apr.apache.org Cc: Paul Querna Subject: [patch] Add apr_array_clear() API Message-ID: <20061205185724.GA32114@anvil.sp.corp.collab.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="uAKRQypu60I7Lcqm" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Mail-Followups-To: Daniel Rall X-Virus-Checked: Checked by ClamAV on apache.org --uAKRQypu60I7Lcqm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The following patch adds a new apr_array_clear() API. While a trivial operation, the minimum (safe) implementation required to clear an apr_array_header_t is somewhat non-obvious without examining the source code. Looping over apr_array_pop() is probably a common fallback for those who still aren't sure after reading apr_array_header_t's doc string. To clarify things, we should instead present an obvious API. [[[ 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. ]]] Index: tables/apr_tables.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- tables/apr_tables.c (revision 482732) +++ tables/apr_tables.c (working copy) @@ -90,6 +90,11 @@ return res; } =20 +APR_DECLARE(void) apr_array_clear(apr_array_header_t *arr) +{ + arr->nelts =3D 0; +} + APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr) { if (apr_is_empty_array(arr)) { Index: test/testtable.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- test/testtable.c (revision 482732) +++ test/testtable.c (working copy) @@ -30,8 +30,18 @@ #include #endif =20 +static apr_array_header_t *a1 =3D NULL; static apr_table_t *t1 =3D NULL; =20 +static void array_clear(abts_case *tc, void *data) +{ + a1 =3D apr_array_make(p, 2, sizeof(const char *)); + APR_ARRAY_PUSH(a1, const char *) =3D "foo"; + APR_ARRAY_PUSH(a1, const char *) =3D "bar"; + apr_array_clear(a1); + ABTS_INT_EQUAL(tc, 0, a1->nelts); +} + static void table_make(abts_case *tc, void *data) { t1 =3D apr_table_make(p, 5); @@ -174,6 +184,7 @@ { suite =3D ADD_SUITE(suite) =20 + 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); Index: include/apr_tables.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/apr_tables.h (revision 482732) +++ include/apr_tables.h (working copy) @@ -148,6 +148,14 @@ APR_DECLARE(void *) apr_array_pop(apr_array_header_t *arr); =20 /** + * 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 combin= ed=20 * array --uAKRQypu60I7Lcqm Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFFdcEUZ9mySWdPBeARAs0dAKDT9BHKnaVVd9i0CthNE/SXps+XYgCdFAqu HPO12razI4mfGtg00ypDYfo= =KJgJ -----END PGP SIGNATURE----- --uAKRQypu60I7Lcqm--