summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/buffer.c25
-rw-r--r--src/utils/stack.c26
-rw-r--r--src/utils/vector.c28
3 files changed, 27 insertions, 52 deletions
diff --git a/src/utils/buffer.c b/src/utils/buffer.c
index 384e9a9..5a2a7ce 100644
--- a/src/utils/buffer.c
+++ b/src/utils/buffer.c
@@ -14,37 +14,31 @@
/**
* Create a memory buffer
*
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param buffer Pointer to location to receive memory buffer
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhausion
*/
-parserutils_error parserutils_buffer_create(parserutils_alloc alloc, void *pw,
- parserutils_buffer **buffer)
+parserutils_error parserutils_buffer_create(parserutils_buffer **buffer)
{
parserutils_buffer *b;
- if (alloc == NULL || buffer == NULL)
+ if (buffer == NULL)
return PARSERUTILS_BADPARM;
- b = alloc(NULL, sizeof(parserutils_buffer), pw);
+ b = malloc(sizeof(parserutils_buffer));
if (b == NULL)
return PARSERUTILS_NOMEM;
- b->data = alloc(NULL, DEFAULT_SIZE, pw);
+ b->data = malloc(DEFAULT_SIZE);
if (b->data == NULL) {
- alloc(b, 0, pw);
+ free(b);
return PARSERUTILS_NOMEM;
}
b->length = 0;
b->allocated = DEFAULT_SIZE;
- b->alloc = alloc;
- b->pw = pw;
-
*buffer = b;
return PARSERUTILS_OK;
@@ -61,8 +55,8 @@ parserutils_error parserutils_buffer_destroy(parserutils_buffer *buffer)
if (buffer == NULL)
return PARSERUTILS_BADPARM;
- buffer->alloc(buffer->data, 0, buffer->pw);
- buffer->alloc(buffer, 0, buffer->pw);
+ free(buffer->data);
+ free(buffer);
return PARSERUTILS_OK;
}
@@ -155,8 +149,7 @@ parserutils_error parserutils_buffer_discard(parserutils_buffer *buffer,
*/
parserutils_error parserutils_buffer_grow(parserutils_buffer *buffer)
{
- uint8_t *temp = buffer->alloc(buffer->data,
- buffer->allocated * 2, buffer->pw);
+ uint8_t *temp = realloc(buffer->data, buffer->allocated * 2);
if (temp == NULL)
return PARSERUTILS_NOMEM;
@@ -176,7 +169,7 @@ parserutils_error parserutils_buffer_randomise(parserutils_buffer *buffer)
return PARSERUTILS_BADPARM;
#ifndef NDEBUG
- temp = buffer->alloc(NULL, buffer->allocated, buffer->pw);
+ temp = malloc(buffer->allocated);
if (temp == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/utils/stack.c b/src/utils/stack.c
index 725a23a..539ec9d 100644
--- a/src/utils/stack.c
+++ b/src/utils/stack.c
@@ -20,9 +20,6 @@ struct parserutils_stack
size_t items_allocated; /**< Number of slots allocated */
int32_t current_item; /**< Index of current item */
void *items; /**< Items in stack */
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client-specific data */
};
/**
@@ -30,28 +27,26 @@ struct parserutils_stack
*
* \param item_size Length, in bytes, of an item in the stack
* \param chunk_size Number of stack slots in a chunk
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param stack Pointer to location to receive stack instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters
* PARSERUTILS_NOMEM on memory exhaustion
*/
parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size,
- parserutils_alloc alloc, void *pw, parserutils_stack **stack)
+ parserutils_stack **stack)
{
parserutils_stack *s;
- if (item_size == 0 || chunk_size == 0 || alloc == NULL || stack == NULL)
+ if (item_size == 0 || chunk_size == 0 || stack == NULL)
return PARSERUTILS_BADPARM;
- s = alloc(NULL, sizeof(parserutils_stack), pw);
+ s = malloc(sizeof(parserutils_stack));
if (s == NULL)
return PARSERUTILS_NOMEM;
- s->items = alloc(NULL, item_size * chunk_size, pw);
+ s->items = malloc(item_size * chunk_size);
if (s->items == NULL) {
- alloc(s, 0, pw);
+ free(s);
return PARSERUTILS_NOMEM;
}
@@ -60,9 +55,6 @@ parserutils_error parserutils_stack_create(size_t item_size, size_t chunk_size,
s->items_allocated = chunk_size;
s->current_item = -1;
- s->alloc = alloc;
- s->pw = pw;
-
*stack = s;
return PARSERUTILS_OK;
@@ -79,8 +71,8 @@ parserutils_error parserutils_stack_destroy(parserutils_stack *stack)
if (stack == NULL)
return PARSERUTILS_BADPARM;
- stack->alloc(stack->items, 0, stack->pw);
- stack->alloc(stack, 0, stack->pw);
+ free(stack->items);
+ free(stack);
return PARSERUTILS_OK;
}
@@ -107,9 +99,9 @@ parserutils_error parserutils_stack_push(parserutils_stack *stack,
slot = stack->current_item + 1;
if ((size_t) slot >= stack->items_allocated) {
- void *temp = stack->alloc(stack->items,
+ void *temp = realloc(stack->items,
(stack->items_allocated + stack->chunk_size) *
- stack->item_size, stack->pw);
+ stack->item_size);
if (temp == NULL)
return PARSERUTILS_NOMEM;
diff --git a/src/utils/vector.c b/src/utils/vector.c
index ab895e3..15c948b 100644
--- a/src/utils/vector.c
+++ b/src/utils/vector.c
@@ -20,9 +20,6 @@ struct parserutils_vector
size_t items_allocated; /**< Number of slots allocated */
int32_t current_item; /**< Index of current item */
void *items; /**< Items in vector */
-
- parserutils_alloc alloc; /**< Memory (de)allocation function */
- void *pw; /**< Client-specific data */
};
/**
@@ -30,30 +27,26 @@ struct parserutils_vector
*
* \param item_size Length, in bytes, of an item in the vector
* \param chunk_size Number of vector slots in a chunk
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
* \param vector Pointer to location to receive vector instance
* \return PARSERUTILS_OK on success,
* PARSERUTILS_BADPARM on bad parameters,
* PARSERUTILS_NOMEM on memory exhaustion
*/
parserutils_error parserutils_vector_create(size_t item_size,
- size_t chunk_size, parserutils_alloc alloc, void *pw,
- parserutils_vector **vector)
+ size_t chunk_size, parserutils_vector **vector)
{
parserutils_vector *v;
- if (item_size == 0 || chunk_size == 0 || alloc == NULL ||
- vector == NULL)
+ if (item_size == 0 || chunk_size == 0 || vector == NULL)
return PARSERUTILS_BADPARM;
- v = alloc(NULL, sizeof(parserutils_vector), pw);
+ v = malloc(sizeof(parserutils_vector));
if (v == NULL)
return PARSERUTILS_NOMEM;
- v->items = alloc(NULL, item_size * chunk_size, pw);
+ v->items = malloc(item_size * chunk_size);
if (v->items == NULL) {
- alloc(v, 0, pw);
+ free(v);
return PARSERUTILS_NOMEM;
}
@@ -62,9 +55,6 @@ parserutils_error parserutils_vector_create(size_t item_size,
v->items_allocated = chunk_size;
v->current_item = -1;
- v->alloc = alloc;
- v->pw = pw;
-
*vector = v;
return PARSERUTILS_OK;
@@ -81,8 +71,8 @@ parserutils_error parserutils_vector_destroy(parserutils_vector *vector)
if (vector == NULL)
return PARSERUTILS_BADPARM;
- vector->alloc(vector->items, 0, vector->pw);
- vector->alloc(vector, 0, vector->pw);
+ free(vector->items);
+ free(vector);
return PARSERUTILS_OK;
}
@@ -109,9 +99,9 @@ parserutils_error parserutils_vector_append(parserutils_vector *vector,
slot = vector->current_item + 1;
if ((size_t) slot >= vector->items_allocated) {
- void *temp = vector->alloc(vector->items,
+ void *temp = realloc(vector->items,
(vector->items_allocated + vector->chunk_size) *
- vector->item_size, vector->pw);
+ vector->item_size);
if (temp == NULL)
return PARSERUTILS_NOMEM;