MCPcopy Create free account
hub / github.com/acl-dev/acl / stack_grow

Function stack_grow

lib_acl/src/stdlib/common/acl_stack.c:110–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108/* grows internal buffer to satisfy required minimal capacity */
109
110static void stack_grow(ACL_STACK *s, int min_capacity)
111{
112 const char *myname = "stack_grow";
113 const char *ptr;
114 int min_delta = 16;
115 int delta;
116
117 /* don't need to grow the capacity of the array */
118 if (s->capacity >= min_capacity)
119 return;
120 delta = min_capacity;
121 /* make delta a multiple of min_delta */
122 delta += min_delta - 1;
123 delta /= min_delta;
124 delta *= min_delta;
125 /* actual grow */
126 if (delta <= 0)
127 return;
128 s->capacity += delta;
129 if (s->items) {
130 s->items = (void **) acl_default_realloc(__FILE__, __LINE__,
131 s->items, s->capacity * sizeof(void *));
132 ptr = "realloc";
133 } else {
134 s->items = (void **) acl_default_malloc(__FILE__, __LINE__,
135 s->capacity * sizeof(void *));
136 ptr = "malloc";
137 }
138
139 if (s->items == NULL) {
140 char ebuf[256];
141 acl_msg_fatal("%s(%d): %s error(%s)",
142 myname, __LINE__, ptr,
143 acl_last_strerror(ebuf, sizeof(ebuf)));
144 }
145
146 /* reset, just in case */
147 memset(s->items + s->count, 0, (s->capacity - s->count) * sizeof(void *));
148}
149
150/* if you are going to append a known and large number of items, call this first */
151

Callers 3

acl_stack_spaceFunction · 0.85
acl_stack_appendFunction · 0.85
acl_stack_prependFunction · 0.85

Calls 4

acl_default_reallocFunction · 0.85
acl_default_mallocFunction · 0.85
acl_msg_fatalFunction · 0.85
acl_last_strerrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…