klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit 00acbb184d3223ba28505e286842e8b1a869c4a4
parent 6ad88b94038287a8998c301e5044936f9e5db5b4
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri, 24 Aug 2012 03:25:00 -0300

Added locking to imath/imrat around memory allocation/deallocation.

Diffstat:
Msrc/imath.c | 11++++++++++-
Msrc/imrat.c | 6++++++
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/imath.c b/src/imath.c @@ -374,7 +374,9 @@ mp_result mp_int_init(mp_int z) mp_int mp_int_alloc(klisp_State *K) { + klisp_lock(K); mp_int out = klispM_new(K, mpz_t); + klisp_unlock(K); if(out != NULL) mp_int_init(out); @@ -488,7 +490,9 @@ void mp_int_free(klisp_State *K, mp_int z) NRCHECK(z != NULL); mp_int_clear(K, z); + klisp_lock(K); klispM_free(K, z); /* note: NOT s_free() */ + klisp_unlock(K); } /* }}} */ @@ -2208,7 +2212,9 @@ const char *mp_error_string(mp_result res) STATIC mp_digit *s_alloc(klisp_State *K, mp_size num) { + klisp_lock(K); mp_digit *out = klispM_malloc(K, num * sizeof(mp_digit)); + klisp_unlock(K); assert(out != NULL); /* for debugging */ #if DEBUG > 1 @@ -2240,9 +2246,10 @@ STATIC mp_digit *s_realloc(klisp_State *K, mp_digit *old, mp_size osize, memcpy(new, old, osize * sizeof(mp_digit)); #else + klisp_lock(K); mp_digit *new = klispM_realloc_(K, old, osize * sizeof(mp_digit), nsize * sizeof(mp_digit)); - + klisp_unlock(K); assert(new != NULL); /* for debugging */ #endif return new; @@ -2254,7 +2261,9 @@ STATIC mp_digit *s_realloc(klisp_State *K, mp_digit *old, mp_size osize, STATIC void s_free(klisp_State *K, void *ptr, mp_size size) { + klisp_lock(K); klispM_freemem(K, ptr, size * sizeof(mp_digit)); + klisp_unlock(K); } /* }}} */ diff --git a/src/imrat.c b/src/imrat.c @@ -59,11 +59,15 @@ mp_result mp_rat_init(klisp_State *K, mp_rat r) mp_rat mp_rat_alloc(klisp_State *K) { + klisp_lock(K); mp_rat out = klispM_new(K, mpq_t); + klisp_unlock(K); if(out != NULL) { if(mp_rat_init(K, out) != MP_OK) { + klisp_lock(K); klispM_free(K, out); + klisp_unlock(K); return NULL; } } @@ -146,7 +150,9 @@ void mp_rat_free(klisp_State *K, mp_rat r) if(r->num.digits != NULL) mp_rat_clear(K, r); + klisp_lock(K); klispM_free(K, r); + klisp_unlock(K); } /* }}} */