From 1a3fcdc73411b061d595690f58ac72d25fc65e37 Mon Sep 17 00:00:00 2001
From: zooko <zooko@zooko.com>
Date: Mon, 24 May 2010 12:30:36 +0530
Subject: [PATCH] apply patch from Samuel Neves to stop relying on C99
 features, fixes #7

Ignore-this: f1fd9d25d7d19e02618cb26b5bc77b4e

darcs-hash:201482cfa344b7a57abc07220d62a442017e38d1
---
 zfec/README.txt        |  4 ++--
 zfec/zfec/_fecmodule.c | 32 +++++++++++++++++++-------------
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/zfec/README.txt b/zfec/README.txt
index ac2959a..8c3b51f 100644
--- a/zfec/README.txt
+++ b/zfec/README.txt
@@ -263,11 +263,11 @@ Richard M. Stallman) and Valgrind (starting with Julian Seward) for a pair of
 excellent tools.  Thanks to my coworkers at Allmydata -- http://allmydata.com --
 Fabrice Grinda, Peter Secor, Rob Kinninmont, Brian Warner, Zandr Milewski,
 Justin Boreta, Mark Meras for sponsoring this work and releasing it under a Free
-Software licence.
+Software licence. Thanks to Jack Lloyd, Samuel Neves, and David-Sarah Hopwood.
 
 
 Enjoy!
 
 Zooko Wilcox-O'Hearn
-2008-01-20
+2010-05-24
 Boulder, Colorado
diff --git a/zfec/zfec/_fecmodule.c b/zfec/zfec/_fecmodule.c
index 9d04dc4..a742051 100644
--- a/zfec/zfec/_fecmodule.c
+++ b/zfec/zfec/_fecmodule.c
@@ -6,6 +6,7 @@
 #include <structmember.h>
 #include <stddef.h>
 
+
 #if (PY_VERSION_HEX < 0x02050000)
 typedef int Py_ssize_t;
 #endif
@@ -388,11 +389,11 @@ Decoder_decode(Decoder *self, PyObject *args) {
         goto err;
 
     if (PySequence_Fast_GET_SIZE(fastblocks) != self->kk) {
-        PyErr_Format(py_fec_error, "Precondition violation: Wrong length -- first argument is required to contain exactly k blocks.  len(first): %Zu, k: %d", PySequence_Fast_GET_SIZE(fastblocks), self->kk); 
+        PyErr_Format(py_fec_error, "Precondition violation: Wrong length -- first argument is required to contain exactly k blocks.  len(first): %Zu, k: %d", PySequence_Fast_GET_SIZE(fastblocks), self->kk);
         goto err;
     }
     if (PySequence_Fast_GET_SIZE(fastblocknums) != self->kk) {
-        PyErr_Format(py_fec_error, "Precondition violation: Wrong length -- blocknums is required to contain exactly k blocks.  len(blocknums): %Zu, k: %d", PySequence_Fast_GET_SIZE(fastblocknums), self->kk); 
+        PyErr_Format(py_fec_error, "Precondition violation: Wrong length -- blocknums is required to contain exactly k blocks.  len(blocknums): %Zu, k: %d", PySequence_Fast_GET_SIZE(fastblocknums), self->kk);
         goto err;
     }
 
@@ -552,9 +553,11 @@ static PyTypeObject Decoder_type = {
     Decoder_new,                 /* tp_new */
 };
 
+
 void
 _hexwrite(unsigned char*s, size_t l) {
-  for (size_t i = 0; i < l; i++)
+  size_t i;
+  for (i = 0; i < l; i++)
     printf("%.2x", s[i]);
 }
 
@@ -563,20 +566,27 @@ PyObject*
 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);
-  memset(b1, 2, 8);
-  memset(b2, 3, 8);
+
   const unsigned char *blocks[3] = {b0, b1, b2};
   unsigned char *outblocks[2] = {b3, b4};
   unsigned block_nums[] = {3, 4};
 
+  fec_t *const fec = fec_new(3, 5);
+
+  const unsigned char *inpkts[] = {b3, b4, b2};
+  unsigned char *outpkts[] = {b0, b1};
+  unsigned indexes[] = {3, 4, 2};
+
+  memset(b0, 1, 8);
+  memset(b1, 2, 8);
+  memset(b2, 3, 8);
+
   /*printf("_from_c before encoding:\n");
   printf("b0: "); _hexwrite(b0, 8); printf(", ");
   printf("b1: "); _hexwrite(b1, 8); printf(", ");
   printf("b2: "); _hexwrite(b2, 8); printf(", ");
   printf("\n");*/
 
-  fec_t *const fec = fec_new(3, 5);
   fec_encode(fec, blocks, outblocks, block_nums, 2, 8);
 
   /*printf("after encoding:\n");
@@ -586,10 +596,6 @@ test_from_agl(PyObject* self, PyObject* args) {
 
   memcpy(b0c, b0, 8); memcpy(b1c, b1, 8);
 
-  const unsigned char *inpkts[] = {b3, b4, b2};
-  unsigned char *outpkts[] = {b0, b1};
-  unsigned indexes[] = {3, 4, 2};
-
   fec_decode(fec, inpkts, outpkts, indexes, 8);
 
   /*printf("after decoding:\n");
@@ -603,9 +609,9 @@ test_from_agl(PyObject* self, PyObject* args) {
     Py_RETURN_FALSE;
 }
 
-static PyMethodDef fec_functions[] = { 
+static PyMethodDef fec_functions[] = {
     {"test_from_agl", test_from_agl, METH_NOARGS, NULL},
-    {NULL} 
+    {NULL}
 };
 
 #ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
-- 
2.45.2