tabs->spaces

This commit is contained in:
Nils O. Selåsdal
2013-11-22 20:06:05 +01:00
parent 3e05476694
commit 9090de0663
31 changed files with 1214 additions and 1214 deletions
+59 -59
View File
@@ -6,8 +6,8 @@
typedef struct Chunk Chunk;
struct Chunk {
Chunk *next;
size_t firstfree; //index to the first free byte in this chunk
Chunk *next;
size_t firstfree; //index to the first free byte in this chunk
union data { //for alignment
long long ll;
void *p;
@@ -19,99 +19,99 @@ struct Chunk {
};
struct SAlloc {
size_t chunksz; //data size of each chunk
Chunk *first; //head of the chunk list
Chunk *current;
size_t chunksz; //data size of each chunk
Chunk *first; //head of the chunk list
Chunk *current;
};
static Chunk *
add_chunk(SAlloc *p)
{
Chunk *newchunk;
Chunk *newchunk;
newchunk = malloc(sizeof *newchunk + p->chunksz - (sizeof *newchunk - offsetof(Chunk, data.data)));
if (newchunk == NULL)
return NULL;
newchunk = malloc(sizeof *newchunk + p->chunksz - (sizeof *newchunk - offsetof(Chunk, data.data)));
if (newchunk == NULL)
return NULL;
if (p->current != NULL)
p->current->next = newchunk;
if (p->current != NULL)
p->current->next = newchunk;
newchunk->next = NULL;
newchunk->firstfree = 0;
newchunk->next = NULL;
newchunk->firstfree = 0;
return newchunk;
return newchunk;
}
static Chunk *
next_chunk(SAlloc *p)
{
Chunk *newchunk;
Chunk *newchunk;
if (p->current->next) {
newchunk = p->current->next;
newchunk->firstfree = 0;
} else
newchunk = add_chunk(p);
if (p->current->next) {
newchunk = p->current->next;
newchunk->firstfree = 0;
} else
newchunk = add_chunk(p);
if (newchunk)
p->current = newchunk;
if (newchunk)
p->current = newchunk;
return newchunk;
return newchunk;
}
SAlloc *
uc_new_salloc(size_t chunksz)
{
SAlloc *p;
Chunk *first;
p = malloc(sizeof *p);
if (p == NULL)
return NULL;
SAlloc *p;
Chunk *first;
p = malloc(sizeof *p);
if (p == NULL)
return NULL;
p->chunksz = chunksz;
p->current = NULL;
p->chunksz = chunksz;
p->current = NULL;
if ((first = add_chunk(p)) == NULL) {
free(p);
return NULL;
}
p->first = p->current = first;
if ((first = add_chunk(p)) == NULL) {
free(p);
return NULL;
}
p->first = p->current = first;
return p;
return p;
}
void
uc_reset_salloc(SAlloc *p)
{
Chunk *tmp;
Chunk *tmp;
for(tmp = p->first; tmp; tmp = tmp->next)
tmp->firstfree = 0;
for(tmp = p->first; tmp; tmp = tmp->next)
tmp->firstfree = 0;
p->current = p->first;
p->current = p->first;
}
void *
uc_s_alloc(SAlloc *p,size_t sz)
{
Chunk *chunk;
void *newmem;
chunk = p->current;
if (chunk->firstfree + sz > p->chunksz) {
if (sz > p->chunksz)
return NULL;
Chunk *chunk;
void *newmem;
chunk = p->current;
if (chunk->firstfree + sz > p->chunksz) {
if (sz > p->chunksz)
return NULL;
chunk = next_chunk(p);
if (chunk == NULL)
return NULL;
}
newmem = &chunk->data.data[chunk->firstfree];
chunk->firstfree += sz;
chunk = next_chunk(p);
if (chunk == NULL)
return NULL;
}
newmem = &chunk->data.data[chunk->firstfree];
chunk->firstfree += sz;
return newmem;
return newmem;
}
void *
@@ -132,15 +132,15 @@ free_chunks(Chunk *chunk)
for (next = NULL; chunk != NULL; chunk = next) {
next = chunk->next;
free(chunk);
free(chunk);
}
}
void
uc_free_salloc(SAlloc *p)
{
free_chunks(p->first);
free(p);
free_chunks(p->first);
free(p);
}