#include "fec.h"
-/*
- * If you get a error returned (negative value) from a fec_* function,
- * look in here for the error message.
- */
-
-#define FEC_ERROR_SIZE 1025
-char fec_error[FEC_ERROR_SIZE+1];
-
-#define ERR(...) (snprintf(fec_error, FEC_ERROR_SIZE, __VA_ARGS__))
-
/*
* Primitive polynomials - see Lin & Costello, Appendix A,
* and Lee & Messerschmitt, p. 453.
gf_mul_table[0][j] = gf_mul_table[j][0] = 0;
}
-/*
- * i use malloc so many times, it is easier to put checks all in
- * one place.
- */
-static void *
-my_malloc (int sz, char *err_string) {
- void *p = malloc (sz);
- if (p == NULL) {
- ERR("Malloc failure allocating %s\n", err_string);
- exit (1);
- }
- return p;
-}
-
#define NEW_GF_MATRIX(rows, cols) \
- (gf*)my_malloc(rows * cols, " ## __LINE__ ## " )
+ (gf*)malloc(rows * cols)
/*
* initialize the data structures used for computations in GF.
unsigned icol = 0;
unsigned row, col, i, ix;
- unsigned* indxc = (unsigned*) my_malloc (k * sizeof(unsigned), "indxc");
- unsigned* indxr = (unsigned*) my_malloc (k * sizeof(unsigned), "indxr");
- unsigned* ipiv = (unsigned*) my_malloc (k * sizeof(unsigned), "ipiv");
+ unsigned* indxc = (unsigned*) malloc (k * sizeof(unsigned));
+ unsigned* indxr = (unsigned*) malloc (k * sizeof(unsigned));
+ unsigned* ipiv = (unsigned*) malloc (k * sizeof(unsigned));
gf *id_row = NEW_GF_MATRIX (1, k);
- gf *temp_row = NEW_GF_MATRIX (1, k);
memset (id_row, '\0', k * sizeof (gf));
/*
icol = ix;
goto found_piv;
}
- } else if (ipiv[ix] > 1) {
- ERR("singular matrix");
- goto fail;
- }
+ } else
+ assert (ipiv[ix] <= 1);
}
}
}
indxc[col] = icol;
pivot_row = &src[icol * k];
c = pivot_row[icol];
- if (c == 0) {
- ERR("singular matrix 2");
- goto fail;
- }
+ assert (c != 0);
if (c != 1) { /* otherwhise this is a NOP */
/*
* this is done often , but optimizing is not so
if (indxr[col-1] != indxc[col-1])
for (row = 0; row < k; row++)
SWAP (src[row * k + indxr[col-1]], src[row * k + indxc[col-1]], gf);
- fail:
- free (indxc);
- free (indxr);
- free (ipiv);
- free (id_row);
- free (temp_row);
- return;
}
/*
void
fec_free (fec_t *p) {
- if (p == NULL ||
- p->magic != (((FEC_MAGIC ^ p->k) ^ p->n) ^ (unsigned long) (p->enc_matrix))) {
- ERR("bad parameters to fec_free");
- return;
- }
+ assert (p != NULL && p->magic == (((FEC_MAGIC ^ p->k) ^ p->n) ^ (unsigned long) (p->enc_matrix)));
free (p->enc_matrix);
free (p);
}
fec_t *retval;
- fec_error[FEC_ERROR_SIZE] = '\0';
-
if (fec_initialized == 0)
init_fec ();
- retval = (fec_t *) my_malloc (sizeof (fec_t), "new_code");
+ retval = (fec_t *) malloc (sizeof (fec_t));
retval->k = k;
retval->n = n;
retval->enc_matrix = NEW_GF_MATRIX (n, k);