2021-07-06 20:11:47 +03:00
|
|
|
#include "idris_memory.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-07-04 10:53:53 +03:00
|
|
|
#include "idris_util.h"
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void *idris2_malloc(int size) {
|
|
|
|
IDRIS2_VERIFY(size >= 0, "malloc negative argument: %d", size);
|
2021-07-06 20:11:47 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
if (size == 0) {
|
|
|
|
// Do not depend on platform-speific behavior of malloc.
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-07-06 20:11:47 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void *ptr = malloc(size);
|
|
|
|
IDRIS2_VERIFY(ptr, "malloc failed: %s", strerror(errno));
|
|
|
|
return ptr;
|
2021-07-06 20:11:47 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void idris2_free(void *ptr) {
|
|
|
|
if (!ptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(ptr);
|
2021-07-06 20:11:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove `idrnet_malloc` and `idrnet_free` after bootstrap update
|
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void *idrnet_malloc(int size) { return idris2_malloc(size); }
|
2021-07-06 20:11:47 +03:00
|
|
|
|
2022-09-21 13:13:15 +03:00
|
|
|
void idrnet_free(void *ptr) { idris2_free(ptr); }
|