From: Zooko O'Whielacronx zooko@zooko.com Date: Wed, 11 Apr 2007 17:34:27 +0000 (+0530) Subject: merge changes and fix wrong type -- k and m need more than 8 bits (because they are... X-Git-Url: https://git.rkrishnan.org/vdrive/%5B/%5D%20/uri/flags/%3C?a=commitdiff_plain;h=61c67e4884000ad5ce69fc8e7a9eaf02311569ce;p=tahoe-lafs%2Fzfec.git merge changes and fix wrong type -- k and m need more than 8 bits (because they are the count rather than the index, i.e. they are 1-indexed) darcs-hash:1bfd6670f2d2b7c8882bde603614daa3dc90a5fa --- diff --git a/pyfec/fec/_fecmodule.c b/pyfec/fec/_fecmodule.c index 1a69e00..2c7fa1b 100644 --- a/pyfec/fec/_fecmodule.c +++ b/pyfec/fec/_fecmodule.c @@ -71,8 +71,8 @@ typedef struct { PyObject_HEAD /* expose these */ - int kk; - int mm; + unsigned short kk; + unsigned short mm; /* internal */ fec_t* fec_matrix; @@ -111,16 +111,16 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm); return -1; } - if (self->mm > 255) { - py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm); + if (inm > 256) { + py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm); return -1; } if (ink > inm) { py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", ink, inm); return -1; } - self->kk = (unsigned char)ink; - self->mm = (unsigned char)inm; + self->kk = (unsigned short)ink; + self->mm = (unsigned short)inm; self->fec_matrix = fec_new(self->kk, self->mm); return 0; @@ -326,8 +326,8 @@ typedef struct { PyObject_HEAD /* expose these */ - int kk; - int mm; + unsigned short kk; + unsigned short mm; /* internal */ fec_t* fec_matrix; @@ -367,16 +367,16 @@ Decoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm); return -1; } - if (self->mm > 255) { - py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm); + if (inm > 256) { + py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm); return -1; } if (ink > inm) { py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", ink, inm); return -1; } - self->kk = (unsigned char)ink; - self->mm = (unsigned char)inm; + self->kk = (unsigned short)ink; + self->mm = (unsigned short)inm; self->fec_matrix = fec_new(self->kk, self->mm); return 0; diff --git a/pyfec/fec/fec.c b/pyfec/fec/fec.c index a848d0f..dce7706 100644 --- a/pyfec/fec/fec.c +++ b/pyfec/fec/fec.c @@ -434,14 +434,14 @@ _invert_mat(gf* src, unsigned k) { * p = coefficients of the matrix (p_i) * q = values of the polynomial (known) */ -int -_invert_vdm (gf * src, int k) { - int i, j, row, col; +void +_invert_vdm (gf* src, unsigned k) { + unsigned i, j, row, col; gf *b, *c, *p; gf t, xx; if (k == 1) /* degenerate case, matrix must be p^0 = 1 */ - return 0; + return; /* * c holds the coefficient of P(x) = Prod (x - p_i), i=0..k-1 * b holds the coefficient for the matrix inversion @@ -486,7 +486,7 @@ _invert_vdm (gf * src, int k) { free (c); free (b); free (p); - return 0; + return; } static int fec_initialized = 0; diff --git a/pyfec/fec/test/test_pyfec.py b/pyfec/fec/test/test_pyfec.py index 013a389..e536d3b 100755 --- a/pyfec/fec/test/test_pyfec.py +++ b/pyfec/fec/test/test_pyfec.py @@ -30,6 +30,17 @@ import sys import fec +from base64 import b32encode +def ab(x): # debuggery + if len(x) >= 3: + return "%s:%s" % (len(x), b32encode(x[-3:]),) + elif len(x) == 2: + return "%s:%s" % (len(x), b32encode(x[-2:]),) + elif len(x) == 1: + return "%s:%s" % (len(x), b32encode(x[-1:]),) + elif len(x) == 0: + return "%s:%s" % (len(x), "--empty--",) + def _h(k, m, ss): # sys.stdout.write("k: %s, m: %s, len(ss): %r, len(ss[0]): %r" % (k, m, len(ss), len(ss[0]),)) ; sys.stdout.flush() encer = fec.Encoder(k, m) @@ -47,7 +58,7 @@ def _h(k, m, ss): decoded = decer.decode(blocks, nums) # sys.stdout.write("decoded.\n") ; sys.stdout.flush() assert len(decoded) == len(ss), (len(decoded), len(ss),) - assert tuple([str(s) for s in decoded]) == tuple([str(s) for s in ss]), (tuple([str(s) for s in decoded]), tuple([str(s) for s in ss]),) + assert tuple([str(s) for s in decoded]) == tuple([str(s) for s in ss]), (tuple([ab(str(s)) for s in decoded]), tuple([ab(str(s)) for s in ss]),) def randstr(n): return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n)))