[C++-sig] (Stefan Seefeld) pass function pointerto c
Qinfeng(Javen) Shi
shiqinfeng at gmail.com
Mon Oct 9 17:54:29 CEST 2006
Hi Stefan,
Thanks very much.
> make that
>float f = boost::python::extract<float>(rlt);
>Would that work ?
It works if arg_op = plus or minus. ( here process(boost::python::object
arg_op)).
But it didn't work if arg_op = vectorPlus. It seems that arg_op can't accept
a c++ float pointer.
Acctually the real vectorPlus() used in my code has been optimized for speed
and kindof unfriendly readable. I listed the simple version of vectorPlus()
which had the same idea and problem. For speed reason, I can't use
plus(p1[i],p2[i]) instead of vectorPlus(p1,p2,length).So I hope vectorPlus
can work.
---------------------c extension-----------------
vectorPlus(float* p1, float* p2,int point_len)// plus for two vectors.
{
float sum = 0;
for (int i=0;i<point_len;i++)
{
sum += *(p1+i) + *(p2+i);
}
return (sum);
}
boost::python::object op;
void process(boost::python::object arg_op){
...
op = arg_op;
...
float * a = {1,2};
float * b = {3,4};
boost::python::object rlt = op(a,b,2); // can't accept float* parameters.
float * f = boost::python::extract<float> (rlt);
printf("%f \n",*f);
...
}
----------------------result --------------------
>>> import hello
>>> hello.process(hello.vectorPlus)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: No to_python (by-value) converter found for C++ type: float*
>>>
--
Qinfeng(Javen) Shi
Research School of Information Sciences and Engineering
Australian National University
Locked Bag 8001
Canberra ACT 2601
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20061010/57c23217/attachment.htm>
More information about the Cplusplus-sig
mailing list