Add shorter types, use nil macro
This commit is contained in:
37
gebs.h
37
gebs.h
@ -95,6 +95,17 @@ int main(int argc, char ** argv)
|
||||
#include <sys/wait.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define nil ((void *)0)
|
||||
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long long vlong;
|
||||
|
||||
#define discard __attribute__((unused))
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -199,7 +210,7 @@ void gebs_arena_destroy_chunk(Gebs_Arena_Chunk *chunk);
|
||||
|
||||
#define gebs_list_append_alloc(alloc, list, item) \
|
||||
do { \
|
||||
if ((list)->items == NULL) { \
|
||||
if ((list)->items == nil) { \
|
||||
(list)->capacity = 1; \
|
||||
(list)->items = gebs_malloc((alloc), \
|
||||
sizeof(*(list)->items) * (list)->capacity); \
|
||||
@ -220,9 +231,9 @@ void gebs_arena_destroy_chunk(Gebs_Arena_Chunk *chunk);
|
||||
|
||||
#define gebs_list_free_alloc(alloc, list) \
|
||||
do { \
|
||||
if ((list)->items != NULL) { \
|
||||
if ((list)->items != nil) { \
|
||||
gebs_free((alloc), (list)->items); \
|
||||
(list)->items = NULL; \
|
||||
(list)->items = nil; \
|
||||
} \
|
||||
(list)->count = 0; \
|
||||
} while(0)
|
||||
@ -352,7 +363,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
||||
const char *__flags[] = { __VA_ARGS__ }; \
|
||||
FILE *__out = fopen("compile_flags.txt", "w"); \
|
||||
char __nl = '\n'; \
|
||||
if (__out != NULL) { \
|
||||
if (__out != nil) { \
|
||||
for (size_t __i = 0; __i < sizeof(__flags)/sizeof(__flags[0]); __i++) { \
|
||||
const char *__flag = __flags[__i]; \
|
||||
fwrite(__flag, strlen(__flag), 1, __out); \
|
||||
@ -393,7 +404,7 @@ int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd)
|
||||
for (size_t i = 0; i < cmd->count; i++) {
|
||||
gebs_cmd_append_alloc(alloc, &new_cmd, cmd->items[i]);
|
||||
}
|
||||
gebs_cmd_append_alloc((alloc), &new_cmd, NULL);
|
||||
gebs_cmd_append_alloc((alloc), &new_cmd, nil);
|
||||
|
||||
pid_t pid = vfork();
|
||||
switch (pid) {
|
||||
@ -437,7 +448,7 @@ int gebs_cmd_run_sync_collect_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd, Gebs_S
|
||||
for (size_t i = 0; i < cmd->count; i++) {
|
||||
gebs_cmd_append_alloc(alloc, &new_cmd, cmd->items[i]);
|
||||
}
|
||||
gebs_cmd_append_alloc((alloc), &new_cmd, NULL);
|
||||
gebs_cmd_append_alloc((alloc), &new_cmd, nil);
|
||||
|
||||
int pipe_ends[2];
|
||||
pipe(pipe_ends);
|
||||
@ -515,7 +526,7 @@ Gebs_Arena_Chunk *gebs_arena_create_chunk(size_t capacity)
|
||||
{
|
||||
size_t size = sizeof(Gebs_Arena_Chunk) + sizeof(uintptr_t)*capacity;
|
||||
Gebs_Arena_Chunk *chunk = (Gebs_Arena_Chunk *)malloc(size);
|
||||
chunk->next = NULL;
|
||||
chunk->next = nil;
|
||||
chunk->size = 0;
|
||||
chunk->capacity = capacity;
|
||||
return chunk;
|
||||
@ -532,7 +543,7 @@ void *gebs_arena_malloc(void *self, size_t size)
|
||||
|
||||
size_t sz = (size + sizeof(uintptr_t) - 1)/sizeof(uintptr_t);
|
||||
|
||||
if (a->end == NULL) {
|
||||
if (a->end == nil) {
|
||||
size_t capacity = GEBS_ARENA_CHUNK_CAPACITY;
|
||||
if (capacity < sz) {
|
||||
capacity = sz;
|
||||
@ -541,7 +552,7 @@ void *gebs_arena_malloc(void *self, size_t size)
|
||||
a->begin = a->end;
|
||||
}
|
||||
|
||||
while (a->end->size + sz > a->end->capacity && a->end->next != NULL) {
|
||||
while (a->end->size + sz > a->end->capacity && a->end->next != nil) {
|
||||
a->end = a->end->next;
|
||||
}
|
||||
|
||||
@ -581,7 +592,7 @@ void *gebs_arena_realloc(void *self, void *memory,
|
||||
|
||||
void gebs_arena_reset(Gebs_Arena *a)
|
||||
{
|
||||
for (Gebs_Arena_Chunk *chunk = a->begin; chunk != NULL; chunk = chunk->next) {
|
||||
for (Gebs_Arena_Chunk *chunk = a->begin; chunk != nil; chunk = chunk->next) {
|
||||
chunk->size = 0;
|
||||
}
|
||||
a->end = a->begin;
|
||||
@ -595,8 +606,8 @@ void gebs_arena_destroy(Gebs_Arena *a)
|
||||
chunk = chunk->next;
|
||||
gebs_arena_destroy_chunk(chunk1);
|
||||
}
|
||||
a->begin = NULL;
|
||||
a->end = NULL;
|
||||
a->begin = nil;
|
||||
a->end = nil;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -624,7 +635,7 @@ char *gebs_fmt(const char *fmt, ...)
|
||||
|
||||
va_list list_copy;
|
||||
va_copy(list_copy, list);
|
||||
size_t size = vsnprintf(NULL, 0, fmt, list_copy);
|
||||
size_t size = vsnprintf(nil, 0, fmt, list_copy);
|
||||
va_end(list_copy);
|
||||
|
||||
char *buf = gebs_malloc(&gebs_scratch_arena, size+1);
|
||||
|
Reference in New Issue
Block a user