#include <Python.h>
#include <structmember.h>
+#include <stddef.h>
#if (PY_VERSION_HEX < 0x02050000)
typedef int Py_ssize_t;
PyObject_HEAD
/* expose these */
- short kk;
- short mm;
+ unsigned short kk;
+ unsigned short mm;
/* internal */
fec_t* fec_matrix;
NULL
};
int ink, inm;
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &ink, &inm))
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii:Encoder.__init__", kwlist, &ink, &inm))
return -1;
if (ink < 1) {
- PyErr_Format(py_fec_error, "Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", self->kk);
+ PyErr_Format(py_fec_error, "Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", ink);
return -1;
}
if (inm < 1) {
- PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm);
+ PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", inm);
return -1;
}
if (inm > 256) {
- PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm);
+ PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be less than or equal to 256, but it was %d", inm);
return -1;
}
if (ink > inm) {
PyErr_Format(py_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 = (short)ink;
- self->mm = (short)inm;
+ self->kk = (unsigned short)ink;
+ self->mm = (unsigned short)inm;
self->fec_matrix = fec_new(self->kk, self->mm);
return 0;
Py_ssize_t sz, oldsz = 0;
unsigned char check_block_index = 0; /* index into the check_blocks_produced and (parallel) pystrs_produced arrays */
- if (!PyArg_ParseTuple(args, "O|O", &inblocks, &desired_blocks_nums))
+ if (!PyArg_ParseTuple(args, "O|O:Encoder.encode", &inblocks, &desired_blocks_nums))
return NULL;
for (i=0; i<self->mm - self->kk; i++)
}
oldsz = sz;
}
-
+
/* Allocate space for all of the check blocks. */
for (i=0; i<num_desired_blocks; i++) {
static void
Encoder_dealloc(Encoder * self) {
- fec_free(self->fec_matrix);
+ if (self->fec_matrix)
+ fec_free(self->fec_matrix);
self->ob_type->tp_free((PyObject*)self);
}
PyObject_HEAD
/* expose these */
- short kk;
- short mm;
+ unsigned short kk;
+ unsigned short mm;
/* internal */
fec_t* fec_matrix;
};
int ink, inm;
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &ink, &inm))
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii:Decoder.__init__", kwlist, &ink, &inm))
return -1;
if (ink < 1) {
- PyErr_Format(py_fec_error, "Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", self->kk);
+ PyErr_Format(py_fec_error, "Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", ink);
return -1;
}
if (inm < 1) {
- PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm);
+ PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", inm);
return -1;
}
if (inm > 256) {
- PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be less than or equal to 256, but it was %d", self->mm);
+ PyErr_Format(py_fec_error, "Precondition violation: second argument is required to be less than or equal to 256, but it was %d", inm);
return -1;
}
if (ink > inm) {
PyErr_Format(py_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 = (short)ink;
- self->mm = (short)inm;
+ self->kk = (unsigned short)ink;
+ self->mm = (unsigned short)inm;
self->fec_matrix = fec_new(self->kk, self->mm);
return 0;
long tmpl;
unsigned nextrecoveredix=0;
- if (!PyArg_ParseTuple(args, "OO", &blocks, &blocknums))
+ if (!PyArg_ParseTuple(args, "OO:Decoder.decode", &blocks, &blocknums))
return NULL;
for (i=0; i<self->kk; i++)
static void
Decoder_dealloc(Decoder * self) {
- fec_free(self->fec_matrix);
+ if (self->fec_matrix)
+ fec_free(self->fec_matrix);
self->ob_type->tp_free((PyObject*)self);
}
printf("%.2x", s[i]);
}
+
PyObject*
-test_from_agl() {
+test_from_agl(PyObject* self, PyObject* args) {
unsigned char b0c[8], b1c[8];
unsigned char b0[8], b1[8], b2[8], b3[8], b4[8];
memset(b0, 1, 8);
}
static PyMethodDef fec_functions[] = {
- {"test_from_agl", test_from_agl, METH_NOARGS, NULL},
+ {"test_from_agl", test_from_agl, METH_NOARGS, NULL},
{NULL}
};