1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 01:37:19 +00:00

Merge branch 'master' of github.com:janet-lang/janet

This commit is contained in:
Calvin Rose 2020-01-02 22:10:13 -06:00
commit e6f897f4ef
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);