I've been trying to use the CPython API to create a function which caluclates Bezier Curves. However, I am getting the following error (exit code rather) when I'm try to run the program. Everything compiles properly and here is my code:
static PyObject* BezierCurve_raw_bezier_curve(PyObject* self, PyObject* args){
    unsigned long long size;
    double t;
    PyObject *py_control_points, *temp1, *x, *y;
    if (!PyArg_ParseTuple(args, "dO", &t, &py_control_points))
        return NULL;
    size = PyLong_AsUnsignedLongLong(PyLong_FromSsize_t(PyList_GET_SIZE(py_control_points)));
    long long *control_points = (long long*)malloc(size * sizeof(long long) * 2);
    for (unsigned long long i = 0; i < size; i+=2){
        temp1 = PyList_GetItem(py_control_points, i);
        if (temp1 == NULL)
            return NULL;
        x = PyList_GetItem(temp1, 0);
        y = PyList_GetItem(temp1, 1);
        if (PyNumber_Check(x) != 1 || PyNumber_Check(y) != 1){
            PyErr_SetString(PyExc_TypeError, "Control Points Argument is Non-Numeric");
            return NULL;}
        control_points[i] = PyLong_AsLongLong(x);
        control_points[i + 1] = PyLong_AsLongLong(y);
        Py_DECREF(x);
        Py_DECREF(y);
        Py_DECREF(temp1);
        if (PyErr_Occurred())
            return NULL;
    }
    Py_DECREF(py_control_points);
    struct DoubleTuple2 point = raw_bezier_curve(t, size, control_points);
    printf("x: %lf, y: %lf", point.x, point.y);
    return Py_BuildValue("[dd]", point.x, point.y);
}
struct DoubleTuple2 {
    double x, y;
};
I printed the value of the point struct and here's what the output was:
x: 185.424000, y: 167.1840000.23040000000000005
Process finished with exit code -1073741819 (0xC0000005)
Why is this error being caused? The raw_bezier_curve function is also returning a double value.
struct DoubleTuple2 raw_bezier_curve(long double t, unsigned long long size, long long control_points[]) {...}
How can I make it work? and is there a way to get a more informative error message (for future debugging)?
 Bhavye Mathur
 Bhavye MathurFinally! I got it to work. Turns out, the issue was quite simple - I was missing a comma. To fix it, I changed:
return Py_BuildValue("[dd]", point.x, point.y);
to
return Py_BuildValue("[d, d]", point.x, point.y);
 Bhavye Mathur
 Bhavye MathurUser contributions licensed under CC BY-SA 3.0