29 |
|
|
30 |
|
#include "vector.h" |
31 |
|
|
32 |
< |
int statgrab_vector_resize(void **vector, vector_header *h, int count) { |
32 |
> |
void *statgrab_vector_resize(void *vector, vector_header *h, int count) { |
33 |
|
int new_count, i; |
34 |
|
|
35 |
< |
/* Destroy any now-unused items. */ |
35 |
> |
/* Destroy any now-unused items. |
36 |
> |
* |
37 |
> |
* Note that there's an assumption here that making the vector smaller |
38 |
> |
* will never fail; if it did, then we would have destroyed items here |
39 |
> |
* but not actually got rid of the vector pointing to them before the |
40 |
> |
* error return.) */ |
41 |
|
if (count < h->used_count && h->destroy_fn != NULL) { |
42 |
|
for (i = count; i < h->used_count; i++) { |
43 |
< |
h->destroy_fn((*vector) + i * h->item_size); |
43 |
> |
h->destroy_fn((void *) (vector + i * h->item_size)); |
44 |
|
} |
45 |
|
} |
46 |
|
|
50 |
|
|
51 |
|
/* Resize the vector if necessary. */ |
52 |
|
if (new_count != h->alloc_count) { |
53 |
< |
void *new_vector; |
53 |
> |
char *new_vector; |
54 |
|
|
55 |
< |
new_vector = realloc(*vector, new_count * h->item_size); |
55 |
> |
new_vector = realloc(vector, new_count * h->item_size); |
56 |
|
if (new_vector == NULL && new_count != 0) { |
57 |
|
/* Out of memory -- free the contents of the vector. */ |
58 |
|
statgrab_vector_resize(vector, h, 0); |
59 |
< |
return -1; |
59 |
> |
h->error = -1; |
60 |
> |
return vector; |
61 |
|
} |
62 |
|
|
63 |
< |
*vector = new_vector; |
63 |
> |
vector = new_vector; |
64 |
|
h->alloc_count = new_count; |
65 |
|
} |
66 |
|
|
67 |
|
/* Initialise any new items. */ |
68 |
|
if (count > h->used_count && h->init_fn != NULL) { |
69 |
|
for (i = h->used_count; i < count; i++) { |
70 |
< |
h->init_fn((*vector) + i * h->item_size); |
70 |
> |
h->init_fn((void *) (vector + i * h->item_size)); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
h->used_count = count; |
75 |
< |
|
76 |
< |
return 0; |
75 |
> |
h->error = 0; |
76 |
> |
return vector; |
77 |
|
} |
78 |
|
|