klisp

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

commit 1c36293fb92d83bd6f0d7a9e945f923f10c8a60a
parent f862983271078cad671256b19de31ded7221b19a
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 12 Apr 2011 14:57:38 -0300

Added klisp_State parameter to mp_int_to_string/read_string/read_cstring.

Diffstat:
Msrc/imath.c | 17+++++++++--------
Msrc/imath.h | 11+++++++----
2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/imath.c b/src/imath.c @@ -1848,7 +1848,7 @@ mp_result mp_int_to_uint(mp_int z, mp_usmall *out) /* {{{ mp_int_to_string(z, radix, str, limit) */ -mp_result mp_int_to_string(mp_int z, mp_size radix, +mp_result mp_int_to_string(klisp_State *K, mp_int z, mp_size radix, char *str, int limit) { mp_result res; @@ -1866,7 +1866,7 @@ mp_result mp_int_to_string(mp_int z, mp_size radix, mpz_t tmp; char *h, *t; - if((res = mp_int_init_copy(KK, &tmp, z)) != MP_OK) + if((res = mp_int_init_copy(K, &tmp, z)) != MP_OK) return res; if(MP_SIGN(z) == MP_NEG) { @@ -1894,7 +1894,7 @@ mp_result mp_int_to_string(mp_int z, mp_size radix, *t-- = tc; } - mp_int_clear(KK, &tmp); + mp_int_clear(K, &tmp); } *str = '\0'; @@ -1931,17 +1931,18 @@ mp_result mp_int_string_len(mp_int z, mp_size radix) /* {{{ mp_int_read_string(z, radix, *str) */ /* Read zero-terminated string into z */ -mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str) +mp_result mp_int_read_string(klisp_State *K, mp_int z, mp_size radix, + const char *str) { - return mp_int_read_cstring(z, radix, str, NULL); - + return mp_int_read_cstring(K, z, radix, str, NULL); } /* }}} */ /* {{{ mp_int_read_cstring(z, radix, *str, **end) */ -mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end) +mp_result mp_int_read_cstring(klisp_State *K, mp_int z, mp_size radix, + const char *str, char **end) { int ch; @@ -1972,7 +1973,7 @@ mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **e ++str; /* Make sure there is enough space for the value */ - if(!s_pad(KK, z, s_inlen(strlen(str), radix))) + if(!s_pad(K, z, s_inlen(strlen(str), radix))) return MP_MEMORY; MP_USED(z) = 1; z->digits[0] = 0; diff --git a/src/imath.h b/src/imath.h @@ -247,19 +247,22 @@ mp_result mp_int_to_uint(mp_int z, mp_usmall *out); /* Convert to nul-terminated string with the specified radix, writing at most limit characters including the nul terminator */ -mp_result mp_int_to_string(mp_int z, mp_size radix, +mp_result mp_int_to_string(klisp_State *K, mp_int z, mp_size radix, char *str, int limit); /* Return the number of characters required to represent z in the given radix. May over-estimate. */ +/* NOTE: this doesn't use the allocator */ mp_result mp_int_string_len(mp_int z, mp_size radix); /* Read zero-terminated string into z */ -mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str); -mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, - char **end); +mp_result mp_int_read_string(klisp_State *K, mp_int z, mp_size radix, + const char *str); +mp_result mp_int_read_cstring(klisp_State *K, mp_int z, mp_size radix, + const char *str, char **end); /* Return the number of significant bits in z */ +/* NOTE: this doesn't use the allocator */ mp_result mp_int_count_bits(mp_int z); /* Convert z to two's complement binary, writing at most limit bytes */