From: Michael Wallner Date: Wed, 26 Jul 2017 16:06:07 +0000 (+0200) Subject: add malloc stubs X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=commitdiff_plain;h=d583a661f2349ac7be4922e6eca0687ea8ccfef3 add malloc stubs --- diff --git a/m4/posix/stdlib.m4 b/m4/posix/stdlib.m4 index 0840883..c9ce354 100644 --- a/m4/posix/stdlib.m4 +++ b/m4/posix/stdlib.m4 @@ -24,6 +24,7 @@ PSI_CHECK_STDLIB() { PSI_DECL(double atof, [(char *str)]) PSI_DECL(int atoi, [(char *str)]) PSI_DECL(long atol, [(char *str)]) + PSI_DECL(void *calloc, [(size_t nmemb, size_t size)]) PSI_DECL(div_t div, [(int numerator, int denominator)]) PSI_DECL(double drand48, [()]) PSI_DECL(double erand48, [(unsigned short xsubi@<:@3@:>@)]) @@ -38,6 +39,7 @@ PSI_CHECK_STDLIB() { PSI_DECL(ldiv_t ldiv, [(long numerator, long denominator)]) PSI_DECL(lldiv_t lldiv, [(long long numerator, long long denominator)]) PSI_DECL(long lrand48, [()]) + PSI_DECL(void *malloc, [(size_t size)]) PSI_DECL(int mblen, [(const char *s, size_t n)]) PSI_DECL(size_t mbstowcs, [(wchar_t *dest, char *src, size_t n)]) PSI_DECL(int mbtowc, [(wchar_t *pwc, char *s, size_t n)]) @@ -52,6 +54,7 @@ PSI_CHECK_STDLIB() { PSI_DECL(int rand, [()]) PSI_DECL(int rand_r, [(unsigned *seed_p)]) PSI_DECL(long random, [()]) + PSI_DECL(void *realloc, [(void *ptr, size_t size)]) PSI_DECL(char *realpath, [(char *path, char *resolved)]) PSI_DECL(unsigned short *seed48, [(unsigned short seed16v@<:@3@:>@)]) PSI_DECL(int setenv, [(char *var, char *val, int overwrite)]) diff --git a/psi.d/stdlib.psi b/psi.d/stdlib.psi index 0b4a506..8191c2f 100644 --- a/psi.d/stdlib.psi +++ b/psi.d/stdlib.psi @@ -35,3 +35,23 @@ function psi\free(object $memory) : void { let ptr = objval($memory); return void(free); } + +function psi\malloc(int $size) : object { + let size = intval($size); + pre_assert size >= 0; + return to_object(malloc); +} + +function psi\calloc(int $nmemb, int $size) : object { + let nmemb = intval($nmemb); + let size = intval($size); + pre_assert size >= 0; + return to_object(calloc); +} + +function psi\realloc(object $obj, int $size) : object { + let ptr = objval($obj); + let size = intval($size); + pre_assert size >= 0; + return to_object(realloc); +}