One tiny embedding problem, please

VanL van at lindbergs.org
Tue Mar 26 19:06:32 EST 2002


Hello,

Do to various constraints, I am having to use C for a certain project, 
even after I did the (working!) prototype in Python.  I am trying to 
embed python so as to not lose my work.

I have it working and compiling, but I am not getting values out 
correctly.  I think this is just a tiny problem, but I haven't been able 
to fix it.

Code is below, can anyone spot the error?

Thanks,

VanL

Here is the C function:
+++++++++++++++++++++++++++++++++++
void getWP(WP *WP_ptr)
{
    int status;
    PyObject *results;
    status = PP_Run_Function(
            "code", "getWP",
            "O", &results,
            "(i)", 1);

    if (status == -1)
    {
        printf("\n\nScript Error: Get WP Failed.\n");
        PyErr_Print();
    }
    PyArg_ParseTuple(results, "(fff)", &WP_ptr->id, &WP_ptr->x, &WP_ptr->y);
    Py_DECREF(results);
}
+++++++++++++++++++++++++++++++++++++
Here is the python being called:
+++++++++++++++++++++++++++++++++++++
def getWP():
    num = get_sequence() * 1.0
    print "I'm returning," (num, 1.0, 2.0)
    return (num, 1.0, 2.0)
+++++++++++++++++++++++++++++++++++++
Here is the test function in C:
+++++++++++++++++++++++++++++++++++++
   for (i=0; i<2; i++)
    {
        x +=2;
        y +=4;
        v +=8;
        printf("\nInput: %d, %d, %d\n", x, y, v);
        update(x, y, v);
        printf("Updated.");

        getWP(WP_ptr);
        printf("Got WP");
        printf("\nOutput: %f, %f, %f\n\n\n", WP_ptr->id, WP_ptr->x, 
WP_ptr->y);
    }
+++++++++++++++++++++++++++++++++++++++
And here is the output:
+++++++++++++++++++++++++++++++++++++++
Input: 2, 4, 8
1
Updated.I'm returning (2.0, 1.0, 2.0)
Got WP
Output: 0.000000, -1.997108, 0.000000



Input: 4, 8, 16
3
Updated.I'm returning (4.0, 1.0, 2.0)
Got WP
Output: 0.000000, -1.997108, 0.000000






More information about the Python-list mailing list