Add and run WebKit based clang-format

This commit is contained in:
olemorud
2023-05-15 21:35:50 +02:00
parent 98b67e1a53
commit 42cb5d0c4e
5 changed files with 33 additions and 34 deletions

2
.clang-format Normal file
View File

@@ -0,0 +1,2 @@
BasedOnStyle: WebKit

View File

@@ -20,8 +20,7 @@ void* call_alloc_backend(size_t size)
MAP_ANONYMOUS | MAP_PRIVATE,
-1, /* man mmap(2): "[...], some implementations require fd to be
-1 if MAP_ANONYMOUS is specified [...]" */
0
);
0);
if (p == MAP_FAILED)
return NULL;

View File

@@ -32,7 +32,6 @@ struct arena* arena_new()
return (arena_t*)a;
}
/*
* Frees all memory in arena
*/
@@ -41,7 +40,6 @@ void arena_reset(struct arena *a)
a->next = a->begin;
}
/*
* Allocate new memory using arena
*/
@@ -57,4 +55,3 @@ void* arena_alloc(struct arena *a, size_t len)
return p;
}

View File

@@ -14,5 +14,4 @@ arena_t* arena_new();
void arena_reset(arena_t* a);
void* arena_alloc(arena_t* a, size_t len);
#endif

View File

@@ -1,6 +1,5 @@
// _start test_arena_alloc.c
#include "arena.h"
@@ -19,14 +18,17 @@ int main()
err(errno, "failed to allocate arena");
}
printf("\ntest 1: %s", "attempt to allocate arena->cap x 1 byte");
printf("\nAttempt to do `arena->cap` allocations of 1 byte");
for (size_t i = 0; i < default_arena->cap; i++) {
volatile void *c = arena_alloc(default_arena, 1);
char* c = arena_alloc(default_arena, 1);
*c = i & 0xff;
if (c == NULL) {
err(EXIT_FAILURE, "failed to allocate memory");
}
}
printf("\n OK");
return 0;
}