summaryrefslogtreecommitdiffstats
path: root/mpi
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-01-18 10:43:02 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-01-18 10:43:02 -0800
commita666ae690ad548b5f357e70ed124aa3ab64afa5b (patch)
tree41ef41689b4d7852a65977d53903a57fcca0600c /mpi
parentfe4a764a7d40c79b25c5fe0278bded857864f416 (diff)
downloadtxr-a666ae690ad548b5f357e70ed124aa3ab64afa5b.tar.gz
txr-a666ae690ad548b5f357e70ed124aa3ab64afa5b.tar.bz2
txr-a666ae690ad548b5f357e70ed124aa3ab64afa5b.zip
mpi: use wchar_t string for text-to-bignum.
* mpi/mpi.c (mp_read_radix): Take const wchar_t * string rather than unsigned char *. (s_mp_tovalue): Take character argument as wchar_t rather than int. * mpi/mpi.h (mp_read_radix): Declaration updated. * lib.c (int_str): Avoid a malloc/free and UTF-8 conversion by passing the original wide string to mp_read_radix. This removes a TODO dating back to December 2011.
Diffstat (limited to 'mpi')
-rw-r--r--mpi/mpi.c6
-rw-r--r--mpi/mpi.h2
2 files changed, 4 insertions, 4 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 198a5a86..d3e4cb05 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -156,7 +156,7 @@ int s_mp_cmp_d(mp_int *a, mp_digit d); /* magnitude digit compare */
mp_size s_mp_ispow2(mp_int *v); /* is v a power of 2? */
int s_mp_ispow2d(mp_digit d); /* is d a power of 2? */
-int s_mp_tovalue(int ch, int r); /* convert ch to value */
+int s_mp_tovalue(wchar_t ch, int r); /* convert ch to value */
char s_mp_todigit(int val, int r, int low); /* convert val to digit */
size_t s_mp_outlen(mp_size bits, int r); /* output length in bytes */
@@ -2568,7 +2568,7 @@ mp_size mp_is_pow_two(mp_int *mp)
* characters are ignored, and the function reads until a non-digit
* character or the end of the string.
*/
-mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix)
+mp_err mp_read_radix(mp_int *mp, const wchar_t *str, int radix)
{
size_t ix = 0;
int val = 0;
@@ -3959,7 +3959,7 @@ int s_mp_ispow2d(mp_digit d)
* The results will be odd if you use a radix < 2 or > 62, you are
* expected to know what you're up to.
*/
-int s_mp_tovalue(int ch, int r)
+int s_mp_tovalue(wchar_t ch, int r)
{
int val, xch;
diff --git a/mpi/mpi.h b/mpi/mpi.h
index 8bd469f7..1106abde 100644
--- a/mpi/mpi.h
+++ b/mpi/mpi.h
@@ -189,7 +189,7 @@ mp_size mp_is_pow_two(mp_int *mp);
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
#endif
-mp_nign mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix);
+mp_nign mp_err mp_read_radix(mp_int *mp, const wchar_t *str, int radix);
mp_size mp_radix_size(mp_int *mp, int radix);
mp_size mp_value_radix_size(mp_size num, mp_size qty, int radix);
mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix);