introduce mp_cleanup_multi()

This commit is contained in:
Steffen Jaeckel 2017-06-28 13:27:10 +02:00
parent 292f42d3c0
commit 76b9bba857
2 changed files with 19 additions and 0 deletions

View File

@ -493,6 +493,7 @@ extern ltc_math_descriptor ltc_mp;
int ltc_init_multi(void **a, ...);
void ltc_deinit_multi(void *a, ...);
void ltc_cleanup_multi(void **a, ...);
#ifdef LTM_DESC
extern const ltc_math_descriptor ltm_desc;
@ -515,6 +516,7 @@ extern const ltc_math_descriptor gmp_desc;
#define mp_init_multi ltc_init_multi
#define mp_clear(a) ltc_mp.deinit(a)
#define mp_clear_multi ltc_deinit_multi
#define mp_cleanup_multi ltc_cleanup_multi
#define mp_init_copy(a, b) ltc_mp.init_copy(a, b)
#define mp_neg(a, b) ltc_mp.neg(a, b)

View File

@ -53,6 +53,23 @@ void ltc_deinit_multi(void *a, ...)
va_end(args);
}
void ltc_cleanup_multi(void **a, ...)
{
void **cur = a;
va_list args;
va_start(args, a);
while (cur != NULL) {
if (*cur != NULL) {
mp_clear(*cur);
*cur = NULL;
}
cur = va_arg(args, void**);
}
va_end(args);
return;
}
#endif
/* ref: $Format:%D$ */