I am trying to embed a c function in my python script for a first time.
 When I try to call it I get an error

SystemError: new style getargs format but argument is not a tuple

Guido said on some mailing list, that it is probably an effect of the
lack of METH_VARARGS in the functions' array, but it's ok in my source
code.  Here is the full code:

#include <python2.4/Python.h>

static PyObject * mandelpixel(PyObject *self, PyObject *args)
{
        double z_real = 0, z_imag = 0, z_real2 = 0, z_imag2 = 0, c_real,
c_imag, bailoutsquare;
        int iteration_number;
        register int i;
        PyObject coord;
        if (!PyArg_ParseTuple(args, "Oid", &coord, &iteration_number,
&bailoutsquare))
                return NULL;
        if (!PyArg_ParseTuple(&coord, "dd", &c_real, &c_imag))
                return NULL;
        


        for(i = 1; i <= iteration_number; i++)
        {
                z_imag = 2 * z_real * z_imag + c_imag;
                z_real = z_real2 - z_imag2 + c_real;
                z_real2 = z_real * z_real;
                z_imag2 = z_imag * z_imag;
                if (z_real2 + z_imag2 > bailoutsquare)
                        return Py_BuildValue("i", i);
        }
        return Py_BuildValue("i", 0);
}

static PyMethodDef MandelcMethods[] =
{
        {
                "mandelpixel", mandelpixel, METH_VARARGS, "check the pixel for
Mandelbrot set"
        },
        {
                NULL, NULL, 0, NULL
        }
};

PyMODINIT_FUNC initmandelc(void)
{
        (void) Py_InitModule ("mandelc", MandelcMethods);
}

int main(int argc, char **argv)
{
    Py_SetProgramName(argv[0]);
    Py_Initialize();
    initmandelc();
    return 0;
}

Greets
zefciu
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to