Ticket #194: c89.diff

File c89.diff, 7.7 KB (added by ghazel, at 2007-10-27T07:23:17Z)

c89 diff

  • zfec/_fecmodule.c

    diff -ru ..\zfec\zfec-1.1/zfec/_fecmodule.c ./zfec/_fecmodule.c
    old new  
    113113    PyObject* desired_blocks_nums = NULL; /* The blocknums of the blocks that should be returned. */
    114114    PyObject* result = NULL;
    115115
    116     if (!PyArg_ParseTuple(args, "O|O", &inblocks, &desired_blocks_nums))
    117         return NULL;
    118 
    119     gf* check_blocks_produced[self->mm - self->kk]; /* This is an upper bound -- we will actually use only num_check_blocks_produced of these elements (see below). */
    120     PyObject* pystrs_produced[self->mm - self->kk]; /* This is an upper bound -- we will actually use only num_check_blocks_produced of these elements (see below). */
     116    gf** check_blocks_produced = (gf**)alloca(self->mm - self->kk); /* This is an upper bound -- we will actually use only num_check_blocks_produced of these elements (see below). */
     117    PyObject** pystrs_produced = (PyObject**)alloca(self->mm - self->kk); /* This is an upper bound -- we will actually use only num_check_blocks_produced of these elements (see below). */
    121118    unsigned num_check_blocks_produced = 0; /* The first num_check_blocks_produced elements of the check_blocks_produced array and of the pystrs_produced array will be used. */
    122     const gf* incblocks[self->kk];
     119    const gf** incblocks = (const gf**)alloca(self->kk);
    123120    unsigned num_desired_blocks;
    124121    PyObject* fast_desired_blocks_nums = NULL;
    125122    PyObject** fast_desired_blocks_nums_items;
    126     unsigned c_desired_blocks_nums[self->mm];
    127     unsigned c_desired_checkblocks_ids[self->mm - self->kk];
     123    unsigned* c_desired_blocks_nums = (unsigned*)alloca(self->mm);
     124    unsigned* c_desired_checkblocks_ids = (unsigned*)alloca(self->mm - self->kk);
    128125    unsigned i;
    129126    PyObject* fastinblocks = NULL;
     127    PyObject** fastinblocksitems;
     128    Py_ssize_t sz, oldsz = 0;
     129    unsigned char check_block_index = 0; /* index into the check_blocks_produced and (parallel) pystrs_produced arrays */
     130
     131    if (!PyArg_ParseTuple(args, "O|O", &inblocks, &desired_blocks_nums))
     132        return NULL;
    130133
    131134    for (i=0; i<self->mm - self->kk; i++)
    132135        pystrs_produced[i] = NULL;
     
    162165    }
    163166
    164167    /* Construct a C array of gf*'s of the input data. */
    165     PyObject** fastinblocksitems = PySequence_Fast_ITEMS(fastinblocks);
     168    fastinblocksitems = PySequence_Fast_ITEMS(fastinblocks);
    166169    if (!fastinblocksitems)
    167170        goto err;
    168     Py_ssize_t sz, oldsz = 0;
     171
    169172    for (i=0; i<self->kk; i++) {
    170173        if (!PyObject_CheckReadBuffer(fastinblocksitems[i])) {
    171174            py_raise_fec_error("Precondition violation: %u'th item is required to offer the single-segment read character buffer protocol, but it does not.", i);
     
    181184    }
    182185   
    183186    /* Allocate space for all of the check blocks. */
    184     unsigned char check_block_index = 0; /* index into the check_blocks_produced and (parallel) pystrs_produced arrays */
     187   
    185188    for (i=0; i<num_desired_blocks; i++) {
    186189        if (c_desired_blocks_nums[i] >= self->kk) {
    187190            c_desired_checkblocks_ids[check_block_index] = c_desired_blocks_nums[i];
     
    371374    PyObject*restrict blocknums;
    372375    PyObject* result = NULL;
    373376
     377    const gf**restrict cblocks = (const gf**restrict)alloca(self->kk);
     378    unsigned* cblocknums = (unsigned*)alloca(self->kk);
     379    gf**restrict recoveredcstrs = (gf**)alloca(self->kk); /* self->kk is actually an upper bound -- we probably won't need all of this space. */
     380    PyObject**restrict recoveredpystrs = (PyObject**restrict)alloca(self->kk); /* self->kk is actually an upper bound -- we probably won't need all of this space. */
     381    unsigned i;
     382    PyObject*restrict fastblocknums = NULL;
     383    PyObject*restrict fastblocks;
     384    unsigned needtorecover=0;
     385    PyObject** fastblocksitems;
     386    PyObject** fastblocknumsitems;
     387    Py_ssize_t sz, oldsz = 0;
     388    long tmpl;
     389    unsigned nextrecoveredix=0;
     390
    374391    if (!PyArg_ParseTuple(args, "OO", &blocks, &blocknums))
    375392        return NULL;
    376393
    377     const gf*restrict cblocks[self->kk];
    378     unsigned cblocknums[self->kk];
    379     gf*restrict recoveredcstrs[self->kk]; /* self->kk is actually an upper bound -- we probably won't need all of this space. */
    380     PyObject*restrict recoveredpystrs[self->kk]; /* self->kk is actually an upper bound -- we probably won't need all of this space. */
    381     unsigned i;
    382394    for (i=0; i<self->kk; i++)
    383395        recoveredpystrs[i] = NULL;
    384     PyObject*restrict fastblocknums = NULL;
    385     PyObject*restrict fastblocks = PySequence_Fast(blocks, "First argument was not a sequence.");
     396    fastblocks = PySequence_Fast(blocks, "First argument was not a sequence.");
    386397    if (!fastblocks)
    387398        goto err;
    388399    fastblocknums = PySequence_Fast(blocknums, "Second argument was not a sequence.");
     
    399410    }
    400411
    401412    /* Construct a C array of gf*'s of the data and another of C ints of the blocknums. */
    402     unsigned needtorecover=0;
    403     PyObject** fastblocknumsitems = PySequence_Fast_ITEMS(fastblocknums);
     413    fastblocknumsitems = PySequence_Fast_ITEMS(fastblocknums);
    404414    if (!fastblocknumsitems)
    405415        goto err;
    406     PyObject** fastblocksitems = PySequence_Fast_ITEMS(fastblocks);
     416    fastblocksitems = PySequence_Fast_ITEMS(fastblocks);
    407417    if (!fastblocksitems)
    408418        goto err;
    409     Py_ssize_t sz, oldsz = 0;
     419   
    410420    for (i=0; i<self->kk; i++) {
    411421        if (!PyInt_Check(fastblocknumsitems[i])) {
    412422            py_raise_fec_error("Precondition violation: second argument is required to contain int.");
    413423            goto err;
    414424        }
    415         long tmpl = PyInt_AsLong(fastblocknumsitems[i]);
     425        tmpl = PyInt_AsLong(fastblocknumsitems[i]);
    416426        if (tmpl < 0 || tmpl > 255) {
    417427            py_raise_fec_error("Precondition violation: block nums can't be less than zero or greater than 255.  %ld\n", tmpl);
    418428            goto err;
     
    462472    fec_decode(self->fec_matrix, cblocks, recoveredcstrs, cblocknums, sz);
    463473
    464474    /* Wrap up both original primary blocks and decoded blocks into a Python list of Python strings. */
    465     unsigned nextrecoveredix=0;
    466475    result = PyList_New(self->kk);
    467476    if (result == NULL)
    468477        goto err;
  • zfec/fec.c

    diff -ru ..\zfec\zfec-1.1/zfec/fec.c ./zfec/fec.c
    old new  
    494494
    495495void
    496496fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, size_t sz) {
    497     gf m_dec[code->k * code->k];
     497    gf* m_dec = (gf*)alloca(code->k * code->k);
     498    unsigned char outix=0;
     499    unsigned char row=0;
     500    unsigned char col=0;
    498501    build_decode_matrix_into_space(code, index, code->k, m_dec);
    499502
    500     unsigned char outix=0;
    501     for (unsigned char row=0; row<code->k; row++) {
     503    for (row=0; row<code->k; row++) {
    502504        if (index[row] >= code->k) {
    503505            memset(outpkts[outix], 0, sz);
    504             for (unsigned char col=0; col < code->k; col++)
     506            for (col=0; col < code->k; col++)
    505507                addmul(outpkts[outix], inpkts[col], m_dec[row * code->k + col], sz);
    506508            outix++;
    507509        }
  • zfec/fec.h

    diff -ru ..\zfec\zfec-1.1/zfec/fec.h ./zfec/fec.h
    old new  
    22 * zfec -- fast forward error correction library with Python interface
    33 */
    44
     5#if defined(_MSC_VER)
     6// actually, some of the flavors (i.e. Enterprise) do support it
     7//#define restrict __restrict
     8#define restrict
     9#define inline __inline
     10#define alloca _alloca
     11#endif
     12
    513typedef unsigned char gf;
    614
    715typedef struct {