httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <jwool...@virginia.edu>
Subject Re: Apr array functions
Date Tue, 09 Nov 2004 01:35:13 GMT
On Mon, 8 Nov 2004, Nathanael Noblet wrote:

> so that someone can use the array elements without removing them? Is
> there something I don't know that gives a reason why this is bad?

You don't have to remove elements to get at them... the array header
structure is visible to the application, so it can just do
arr->elts[index] and be done with it (insert bounds checking if
necessary).


> APR_DECLARE(void *) apr_array_get_element(aprt_array_header_t *arr, int
> index)
> {
> 	if(apr_is_empty_array(arr)) {
> 		return NULL;
> 	}
>
> 	if(index > arr->nelts) {
> 		return NULL;
> 	}
>
> 	if(index == 0) {
> 		return arr->elts;
> 	}
>
> 	return arr->elts+(arr->elt_size * (arr->nelts-1));
> }

Anyway, if this function is supposed to do what I expect it's supposed to
do, it seems to have several important bugs.  I assume you just typed this
up off the top of your head and never actually tried to compile it or use
it.  :)

 * apr_array_header_t, not aprt_array_header_t
 * the index==0 thing is superfluous
 * ..except that otherwise index is never used and so you can only ever
   return NULL, the first element, or the last element.  :)
 * you perform arithmetic on a void pointer

Anyway like I said it was probably just off the top of your head and
it was obviously enough to get the point across, so no big deal.

Also, of course it's not your bug, but:

 * apr_is_empty_array ... ooh, that's annoying.  Why did we not rename
that to apr_array_is_empty prior to APR 1.0?  :-(


--Cliff

Mime
View raw message