C function taking double pointer to a structure variable as OUTPUT parameter
fengmang_python at sina.com
fengmang_python at sina.com
Tue Jul 28 14:41:57 EDT 2009
Hi, Everyone,
I am a newbie to both Swig and Python. I am trying to export a set of C APIs to Python.
My C function is
int getInfor( char* name, int height, int weight, Infor** infor) //where infor is an OUTPUT parameter
{
......
*infor = (Infor*)malloc(sizeof(Infor));
......
}
The declare of structure Infor is :
typedef struct {
char name[20];
int height;
int weight;
} Infor
When wrote the below lines in the interface file named Extest.i
%module Extest
%{
#include "Extest.h"
%}
%typemap(out) Infor **OUTPUT {Infor **c}
%apply int *OUTPUT {int *c}
%include "Extest.h"
And then, How to write testing python file to call the function named getInfor()?
such as in test.py
infor = Extest.Infor()
res = Extest.getInfor("Test Name", 175, 80, infor)
when run upper's test.py, Error occured. The message is
TypeError: in method 'getInfor', argument 4 of type 'Infor **'
How to write the test.py to transfer the 'Infor **' type's parameter?
After putting lot of trail and errors, I am writing this mail.
Could you please help me to write the test.py or swig interface file for the above function?
Thank you,
jemmy
Awaiting you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090729/11c88104/attachment.html>
More information about the Python-list
mailing list