1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-29 03:19:54 +00:00

Add scratch calloc.

This commit is contained in:
Andrew Chambers 2020-01-03 12:10:17 +13:00
parent ef02dacdb4
commit acdbf8911c
2 changed files with 11 additions and 0 deletions

View File

@ -491,6 +491,16 @@ void *janet_smalloc(size_t size) {
return (char *)mem + SCRATCH_HDR_SIZE;
}
void *janet_scalloc(size_t nmemb, size_t size) {
if (nmemb && size > (size_t)-1/size) {
JANET_OUT_OF_MEMORY;
}
size_t n = nmemb * size;
void *p = janet_smalloc(n);
memset(p, 0, n);
return p;
}
void *janet_srealloc(void *mem, size_t size) {
if (NULL == mem) return janet_smalloc(size);
mem = (char *)mem - SCRATCH_HDR_SIZE;

View File

@ -1355,6 +1355,7 @@ JANET_API void janet_stacktrace(JanetFiber *fiber, Janet err);
typedef void (*ScratchFinalizer)(void *);
JANET_API void *janet_smalloc(size_t size);
JANET_API void *janet_srealloc(void *mem, size_t size);
JANET_API void *janet_scalloc(size_t nmemb, size_t size);
JANET_API void janet_sfinalizer(void *mem, ScratchFinalizer finalizer);
JANET_API void janet_sfree(void *mem);