From bc7142b5277791782db11d5e9a9e462fb592fac9 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 8 Oct 2012 13:36:50 -0400 Subject: [PATCH] Introduce isl_int_free_str to remove GMP dependency in isl_int interface Signed-off-by: Andreas Kloeckner Signed-off-by: Sven Verdoolaege --- include/isl/int.h | 16 +++++++++------- isl_printer.c | 4 +--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/isl/int.h b/include/isl/int.h index f9c1d579..9391df95 100644 --- a/include/isl/int.h +++ b/include/isl/int.h @@ -46,6 +46,13 @@ typedef mpz_t isl_int; #define isl_int_get_ui(r) mpz_get_ui(r) #define isl_int_get_d(r) mpz_get_d(r) #define isl_int_get_str(r) mpz_get_str(0, 10, r) +typedef void (*isl_int_print_gmp_free_t)(void *, size_t); +#define isl_int_free_str(s) \ + do { \ + isl_int_print_gmp_free_t gmp_free; \ + mp_get_memory_functions(NULL, NULL, &gmp_free); \ + (*gmp_free)(s, strlen(s) + 1); \ + } while (0) #define isl_int_abs(r,i) mpz_abs(r,i) #define isl_int_neg(r,i) mpz_neg(r,i) #define isl_int_swap(i,j) mpz_swap(i,j) @@ -73,15 +80,12 @@ typedef mpz_t isl_int; #define isl_int_fdiv_q_ui(r,i,j) mpz_fdiv_q_ui(r,i,j) #define isl_int_read(r,s) mpz_set_str(r,s,10) -typedef void (*isl_int_print_gmp_free_t)(void *, size_t); #define isl_int_print(out,i,width) \ do { \ char *s; \ - isl_int_print_gmp_free_t gmp_free; \ s = mpz_get_str(0, 10, i); \ fprintf(out, "%*s", width, s); \ - mp_get_memory_functions(NULL, NULL, &gmp_free); \ - (*gmp_free)(s, strlen(s)+1); \ + isl_int_free_str(s); \ } while (0) #define isl_int_sgn(i) mpz_sgn(i) @@ -122,11 +126,9 @@ extern "C" { typedef void (*isl_gmp_free_t)(void *, size_t); } static inline std::ostream &operator<<(std::ostream &os, isl_int i) { char *s; - isl_gmp_free_t gmp_free; s = mpz_get_str(0, 10, i); os << s; - mp_get_memory_functions(NULL, NULL, &gmp_free); - (*gmp_free)(s, strlen(s)+1); + isl_int_free_str(s); return os; } #endif diff --git a/isl_printer.c b/isl_printer.c index 17932708..e0821f2a 100644 --- a/isl_printer.c +++ b/isl_printer.c @@ -163,15 +163,13 @@ static __isl_give isl_printer *str_print_isl_int(__isl_take isl_printer *p, { char *s; int len; - isl_int_print_gmp_free_t gmp_free; s = isl_int_get_str(i); len = strlen(s); if (len < p->width) p = str_print_indent(p, p->width - len); p = str_print(p, s, len); - mp_get_memory_functions(NULL, NULL, &gmp_free); - (*gmp_free)(s, len + 1); + isl_int_free_str(s); return p; } -- 2.11.4.GIT