swig help

VanL vlindberg at verio.net
Tue Apr 1 23:29:39 EST 2003


Hello,

I have a c file that has a function

void myfunc(int x, int y, int z, float *new_x, float *new_y, float *new_z);

I can create an interface to it fine, but the typemap stuff keeps 
tripping me up -- I cannot seem to get it so that from python it looks like

 >>> result = myfunc(1,2,3)
 >>> result
(1.0, 2.0, 3.0)

Instead, it complains that it expects six arguments, the last three of 
which need to be pointers to ints.

I have the following interface file:

%typemap(argout) float *OutValue {
     PyObject *o, *o2, *o3;
     o = PyFloat_FromFloat(*$1);
     if ((!$result) || ($result == Py_None)) {
         $result = o;
     } else {
         if (!PyTuple_Check($result)) {
             PyObject *o2 = $result;
             $result = PyTuple_New(1);
             PyTuple_SetItem(target,0,o2);
         }
         o3 = PyTuple_New(1);
         PyTuple_SetItem(o3,0,o);
         o2 = $result;
         $result = PySequence_Concat(o2,o3);
         Py_DECREF(o2);
         Py_DECREF(o3);
     }
}

%typemap(in,numinputs=0) double *OutValue(double temp) {
     $1 = &temp;
}


void next(int x, int y, float z,
           float *new_x, float *new_y, float *new_z);


Could anyone tell me what I have wrong?

Thanks,

VanL





More information about the Python-list mailing list