Skip to content

Commit

Permalink
Adopted size_t where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
geky committed Jul 30, 2016
1 parent d11bd98 commit f602cb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string.h>


int equeue_create(equeue_t *q, unsigned size) {
int equeue_create(equeue_t *q, size_t size) {
void *buffer = malloc(size);
if (!buffer) {
return -1;
Expand All @@ -21,7 +21,7 @@ int equeue_create(equeue_t *q, unsigned size) {
return err;
}

int equeue_create_inplace(equeue_t *q, unsigned size, void *buffer) {
int equeue_create_inplace(equeue_t *q, size_t size, void *buffer) {
q->slab.size = size;
q->slab.data = buffer;
q->chunks = 0;
Expand Down Expand Up @@ -67,7 +67,7 @@ void equeue_destroy(equeue_t *q) {
}

// equeue allocation functions
static void *equeue_mem_alloc(equeue_t *q, unsigned size) {
static void *equeue_mem_alloc(equeue_t *q, size_t size) {
size = size + sizeof(unsigned);
size = (size + sizeof(unsigned)-1) & ~(sizeof(unsigned)-1);
if (size < sizeof(struct equeue_chunk)) {
Expand Down Expand Up @@ -134,7 +134,7 @@ static inline int equeue_next_id(equeue_t *q) {
return id;
}

void *equeue_alloc(equeue_t *q, unsigned size) {
void *equeue_alloc(equeue_t *q, size_t size) {
struct equeue_event *e = equeue_mem_alloc(q,
sizeof(struct equeue_event) + size);
if (!e) {
Expand Down
10 changes: 6 additions & 4 deletions equeue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern "C" {
#include "equeue_mutex.h"
#include "equeue_sema.h"

#include <stddef.h>


// Definition of the minimum size of an event
// This size fits the events created in the event_call set of functions.
Expand Down Expand Up @@ -44,7 +46,7 @@ typedef struct equeue {
struct equeue_chunk *nchunk;
} *chunks;
struct equeue_slab {
unsigned size;
size_t size;
unsigned char *data;
} slab;

Expand All @@ -59,8 +61,8 @@ typedef struct equeue {
// Queue operations
//
// Creation results in negative value on failure.
int equeue_create(equeue_t *queue, unsigned size);
int equeue_create_inplace(equeue_t *queue, unsigned size, void *buffer);
int equeue_create(equeue_t *queue, size_t size);
int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer);
void equeue_destroy(equeue_t *queue);

// Dispatch events
Expand Down Expand Up @@ -98,7 +100,7 @@ int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data);
//
// equeue_alloc will result in null if no memory is available
// or the requested size is less than the size passed to equeue_create.
void *equeue_alloc(equeue_t *queue, unsigned size);
void *equeue_alloc(equeue_t *queue, size_t size);
void equeue_dealloc(equeue_t *queue, void *event);

// Configure an allocated event
Expand Down
4 changes: 2 additions & 2 deletions tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void timing_func(void *p) {

struct fragment {
equeue_t *q;
unsigned size;
size_t size;
struct timing timing;
};

Expand Down Expand Up @@ -293,7 +293,7 @@ void fragmenting_barrage_test(int N) {
test_assert(!err);

for (int i = 0; i < N; i++) {
unsigned size = sizeof(struct fragment) + i*sizeof(int);
size_t size = sizeof(struct fragment) + i*sizeof(int);
struct fragment *fragment = equeue_alloc(&q, size);
test_assert(fragment);

Expand Down

0 comments on commit f602cb5

Please sign in to comment.