#ifndef U_DYNARRAY_H
#define U_DYNARRAY_H
-#include "pipe/p_compiler.h"
-#include "util/u_memory.h"
+#include <stdlib.h>
/* A zero-initialized version of this is guaranteed to represent an
* empty array.
static inline void
util_dynarray_fini(struct util_dynarray *buf)
{
- if(buf->data)
- {
- FREE(buf->data);
+ if (buf->data) {
+ free(buf->data);
util_dynarray_init(buf);
}
}
static inline void *
util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
{
- char *p;
- if(newsize > buf->capacity)
- {
+ void *p;
+ if (newsize > buf->capacity) {
unsigned newcap = buf->capacity << 1;
- if(newsize > newcap)
+ if (newsize > newcap)
newcap = newsize;
- buf->data = REALLOC(buf->data, buf->capacity, newcap);
+ buf->data = realloc(buf->data, newcap);
buf->capacity = newcap;
}
- p = (char *)buf->data + buf->size;
+ p = (void *)((char *)buf->data + buf->size);
buf->size = newsize;
+
return p;
}
{
if (buf->size != buf->capacity) {
if (buf->size) {
- buf->data = REALLOC(buf->data, buf->capacity, buf->size);
+ buf->data = realloc(buf->data, buf->size);
buf->capacity = buf->size;
- }
- else {
- FREE(buf->data);
+ } else {
+ free(buf->data);
buf->data = 0;
buf->capacity = 0;
}