aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2020-05-06 16:56:32 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2020-06-02 11:18:47 +0200
commit8174a918ea3b7cb216bf7ea98cfdc10661b5c37d (patch)
tree0747ec3ccb9f8d7eeccfac35977fc17855ca3bbb /src/malloc.c
parent8f52e8fc02dd235582f5961941bcd564e9a681cd (diff)
downloadallocbench-8174a918ea3b7cb216bf7ea98cfdc10661b5c37d.tar.gz
allocbench-8174a918ea3b7cb216bf7ea98cfdc10661b5c37d.zip
make the whole project more python idiomatic
* rename src directory to allocbench * make global variable names UPPERCASE * format a lot of code using yapf * use lowercase ld_preload and ld_library_path as Allocator members * name expected Errors 'err' and don't raise a new Exception * disable some pylint messages
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c111
1 files changed, 0 insertions, 111 deletions
diff --git a/src/malloc.c b/src/malloc.c
deleted file mode 100644
index 92265cb..0000000
--- a/src/malloc.c
+++ /dev/null
@@ -1,111 +0,0 @@
-#include <malloc.h> /* memalign */
-#include <stdlib.h> /* malloc, free */
-#include <stddef.h> /* NULL, size_t */
-#include <stdint.h> /* uintptr_t */
-#include <string.h> /* memcpy */
-#include <unistd.h> /* sysconf */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void* realloc(void* ptr, size_t size) {
- if(ptr == NULL)
- return malloc(size);
-
- void* new_ptr = malloc(size);
- // this may copies to much
- memcpy(new_ptr, ptr, size);
- return new_ptr;
-}
-
-int posix_memalign(void **memptr, size_t alignment, size_t size)
-{
- void *out;
-
- if((alignment % sizeof(void*)) != 0) {
- return 22;
- }
-
- /* if not power of two */
- if(!((alignment != 0) && !(alignment & (alignment - 1)))) {
- return 22;
- }
-
- if(size == 0) {
- *memptr = NULL;
- return 0;
- }
-
- out = malloc(size);
- if(out == NULL) {
- return 12;
- }
-
- *memptr = out;
- return 0;
-}
-
-void* calloc(size_t nmemb, size_t size)
-{
- void *out;
- size_t fullsize = nmemb * size;
-
- if((size != 0) && ((fullsize / size) != nmemb)) {
- return NULL;
- }
-
- out = malloc(fullsize);
- if(out == NULL) {
- return NULL;
- }
-
- memset(out, 0, fullsize);
- return out;
-}
-
-void* valloc(size_t size)
-{
- long ret = sysconf(_SC_PAGESIZE);
- if(ret == -1) {
- return NULL;
- }
-
- return memalign(ret, size);
-}
-
-void* pvalloc(size_t size)
-{
- size_t ps, rem, allocsize;
-
- long ret = sysconf(_SC_PAGESIZE);
- if(ret == -1) {
- return NULL;
- }
-
- ps = ret;
- rem = size % ps;
- allocsize = size;
- if(rem != 0) {
- allocsize = ps + (size - rem);
- }
-
- return memalign(ps, allocsize);
-}
-
-void* aligned_alloc(size_t alignment, size_t size)
-{
- if(alignment > size) {
- return NULL;
- }
-
- if((size % alignment) != 0) {
- return NULL;
- }
-
- return memalign(alignment, size);
-}
-
-#ifdef __cplusplus
-}
-#endif