define galois_uninit_field

To free resources allocated by galois_init_default_field.

Signed-off-by: Loic Dachary <loic-201408@dachary.org>
master
Loic Dachary 2014-09-13 23:15:57 +02:00
parent 21de983833
commit 4fdbeeebe0
5 changed files with 44 additions and 2 deletions

3
Examples/.gitignore vendored
View File

@ -5,4 +5,5 @@
/liberation_[0-9][0-9]
/reed_sol_[0-9][0-9]
/reed_sol_test_gf
/reed_sol_time_gf
/reed_sol_time_gf
/test_galois

View File

@ -25,10 +25,15 @@ bin_PROGRAMS = jerasure_01 \
encoder \
decoder
TESTS=test_all_gfs.sh
check_PROGRAMS =
TESTS=test_all_gfs.sh $(check_PROGRAMS)
dist_noinst_SCRIPTS = test_all_gfs.sh time_all_gfs_argv_init.sh
test_galois_SOURCES = test_galois.c
check_PROGRAMS += test_galois
jerasure_01_SOURCES = jerasure_01.c
jerasure_02_SOURCES = jerasure_02.c
jerasure_03_SOURCES = jerasure_03.c

23
Examples/test_galois.c Normal file
View File

@ -0,0 +1,23 @@
#include <assert.h>
#include "galois.h"
int main(int argc, char **argv)
{
assert(galois_init_default_field(4) == 0);
assert(galois_uninit_field(4) == 0);
assert(galois_init_default_field(4) == 0);
assert(galois_uninit_field(4) == 0);
assert(galois_init_default_field(8) == 0);
assert(galois_uninit_field(8) == 0);
assert(galois_init_default_field(8) == 0);
assert(galois_uninit_field(8) == 0);
return 0;
}
/*
* Local Variables:
* compile-command: "make test_galois &&
* libtool --mode=execute valgrind --tool=memcheck --leak-check=full ./test_galois"
* End:
*/

View File

@ -47,6 +47,7 @@ extern "C" {
#endif
extern int galois_init_default_field(int w);
extern int galois_uninit_field(int w);
extern void galois_change_technique(gf_t *gf, int w);
extern int galois_single_multiply(int a, int b, int w);

View File

@ -181,6 +181,18 @@ int galois_init_default_field(int w)
return 0;
}
int galois_uninit_field(int w)
{
int ret = 0;
if (gfp_array[w] != NULL) {
int recursive = 1;
ret = gf_free(gfp_array[w], recursive);
free(gfp_array[w]);
gfp_array[w] = NULL;
}
return ret;
}
static void galois_init(int w)
{
if (w <= 0 || w > 32) {