Я хочу получить указатель массива из библиотеки c ++ в python и сохранить его в переменной, а затем использовать переменную в качестве параметра для другой функции c ++.
Окружение
ubuntu18.04, pybind11, python3.6.8
Tried
ctypes
передача указателя на c-from-python-using-pybind11
Код
C ++
// class1:
static complex<double>* randomComplexArray(long size);
complex<double>* randomComplexArray(long n){
complex<double>* res = new complex<double>[n];
for ...
return res; //pointer
}
// class2:
void calc(complex<double>* vals);
pybuind11
// class1:
.def_static("randomComplexArray", &class1::randomCircleArray)
// class2:
.def("calc", (void (*)(complex<double>*)) &class2::calc)
python
p = randomComplexArray(1024)
calc(p) // what I hope
Segmentation fault
, Bus fault
и т. д.
Я делаю это впервые.Если кто-нибудь может мне помочь?
Большое спасибо!