ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/vector.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/vector.c (file contents):
Revision 1.1 by ats, Sun Apr 4 21:17:58 2004 UTC vs.
Revision 1.7 by ats, Wed Apr 7 10:33:50 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 29 | Line 29
29  
30   #include "vector.h"
31  
32 < int statgrab_vector_resize(void **vector, vector_header *h, int count) {
32 > void *sg_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  
# Line 45 | Line 50 | int statgrab_vector_resize(void **vector, vector_heade
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 = sg_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;
58 >                        sg_vector_resize(vector, h, 0);
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines