question: numarray c extension error handling?

Russell E. Owen no at spam.invalid
Wed Mar 10 18:03:19 EST 2004


In article <qnksmggs6uh.fsf at arbutus.physics.mcmaster.ca>,
 cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote:

>...
>>     /* Align, Byteswap, Contiguous, Typeconvert */
>>     kernel  = NA_IoArray(okernel, tFloat64, C_ARRAY);
>> ...
>>     if (!kernel...)
>>         return PyErr_Format( _convolveError, 
>>                  "Convolve1d: error converting array inputs.");
>
>This is also ok (assuming there is nothing between this and the above
>which makes a reference to objects). If NA_IoArray returns NULL,
>there isn't anything to DECREF.

I'm afraid I was too selective in extracting code, making it look like 
no DECREF was even wanted. Here is a more complete extract. The first 
test can fail even if one or two of the arrays was successfullly 
"extracted", so a DECREF is wanted then, and all the more so for the two 
tests after that:

...
    /* Align, Byteswap, Contiguous, Typeconvert */
    kernel  = NA_IoArray(okernel, tFloat64, C_ARRAY);
    data    = NA_IoArray(odata, tFloat64, C_ARRAY);
    convolved = NA_OptionalOutputArray(oconvolved, tFloat64, C_ARRAY, 
data);

    if (!kernel || !data || !convolved)
        return PyErr_Format( _convolveError, 
                 "Convolve1d: error converting array inputs.");

    if ((kernel->nd != 1) || (data->nd != 1))
        return PyErr_Format(_convolveError,
                "Convolve1d: numarray must have 1 dimensions.");

    if (!NA_ShapeEqual(data, convolved))
        return PyErr_Format(_convolveError,
                "Convolve1d: data and output numarray need identitcal 
shapes.");

    Convolve1d(kernel->dimensions[0], 
           NA_OFFSETDATA(kernel),
           data->dimensions[0],   
           NA_OFFSETDATA(data),
           NA_OFFSETDATA(convolved));

    Py_XDECREF(kernel);
    Py_XDECREF(data);
...

It sounds as if I should submit a bug report on the example.

-- Russell



More information about the Python-list mailing list