POLY: provide cleanup function for polynomial arrays

This commit is contained in:
hasufell 2014-05-25 19:22:17 +02:00
parent 7693805741
commit 4d8b6a78e5
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
2 changed files with 21 additions and 6 deletions

View File

@ -110,9 +110,7 @@ void poly_new(fmpz_poly_t new_poly,
/** /**
* This deletes the internal structure of a polynomial, * This deletes the internal structure of a polynomial,
* and frees the pointer. Don't call this on stack variables, * and frees the pointer.
* this is intended for use after ntru_ functions, that
* return a polynomial pointer.
* *
* @param poly the polynomial to delete * @param poly the polynomial to delete
*/ */
@ -121,11 +119,26 @@ void poly_delete(fmpz_poly_t poly)
fmpz_poly_clear(poly); fmpz_poly_clear(poly);
} }
/**
* Delete the internal structure of a polynomial
* array which must be NULL terminated.
*
* @param poly_array the polynomial array
*/
void poly_delete_array(fmpz_poly_t **poly_array)
{
unsigned int i = 0;
while(poly_array[i]) {
poly_delete(*(poly_array[i]));
free(*(poly_array[i]));
i++;
}
}
/** /**
* This deletes the internal structure of all polynomials, * This deletes the internal structure of all polynomials,
* and frees the pointers. Don't call this on stack variables, * and frees the pointers.
* this is intended for use after ntru_ functions, that
* return a polynomial pointer.
* You must call this with NULL as last argument! * You must call this with NULL as last argument!
* *
* @param poly the polynomial to delete * @param poly the polynomial to delete

View File

@ -44,6 +44,8 @@ void poly_new(fmpz_poly_t new_poly,
void poly_delete(fmpz_poly_t poly); void poly_delete(fmpz_poly_t poly);
void poly_delete_array(fmpz_poly_t **poly_array);
void poly_delete_all(fmpz_poly_t poly, ...); void poly_delete_all(fmpz_poly_t poly, ...);
void fmpz_poly_mod_unsigned(fmpz_poly_t a, void fmpz_poly_mod_unsigned(fmpz_poly_t a,