Передача указателя массива из c ++ в python с использованием pybind11 - PullRequest
0 голосов
/ 23 сентября 2019

Я хочу получить указатель массива из библиотеки 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 и т. д.

Я делаю это впервые.Если кто-нибудь может мне помочь?

Большое спасибо!

...