--- projects/libstatgrab/src/libstatgrab/vector.h 2004/04/05 00:45:17 1.4 +++ projects/libstatgrab/src/libstatgrab/vector.h 2004/04/05 00:58:05 1.5 @@ -7,6 +7,7 @@ typedef struct { size_t item_size; int used_count; int alloc_count; + int error; int block_size; vector_init_function init_fn; vector_destroy_function destroy_fn; @@ -17,21 +18,13 @@ typedef struct { sizeof(item_type), \ 0, \ 0, \ + 0, \ block_size, \ (vector_init_function) init_fn, \ (vector_destroy_function) destroy_fn \ } -/* A pointer value that won't be returned by malloc, and isn't NULL, so can be - * used as a sentinel by allocation routines that need to return NULL - * sometimes. */ -extern char statgrab_vector_sentinel_value; -static void *statgrab_vector_sentinel = &statgrab_vector_sentinel_value; - -/* Internal function to resize the vector. Ideally it would take void ** as the - * first parameter, but ANSI strict-aliasing rules would then prevent it from - * doing anything with it, so we return a sentinel value as above instead if - * allocation fails. */ +/* Internal function to resize the vector. */ void *statgrab_vector_resize(void *vector, vector_header *h, int count); /* Declare a vector. Specify the init/destroy functions as NULL if you don't @@ -51,13 +44,10 @@ void *statgrab_vector_resize(void *vector, vector_head /* Resize a vector. Returns 0 on success, -1 on out-of-memory. On * out-of-memory, the old contents of the vector will be destroyed and the old - * vector will be freed. - * - * This is ugly because it needs to check for the sentinel value. - */ + * vector will be freed. */ #define VECTOR_RESIZE(name, num_items) \ - (((name = statgrab_vector_resize((char *) name, &name##_header, num_items)) \ - == statgrab_vector_sentinel) ? -1 : 0) + (name = statgrab_vector_resize((char *) name, &name##_header, num_items), \ + name##_header.error) /* Free a vector, destroying its contents. */ #define VECTOR_FREE(name) \