This commit is contained in:
wangjiyu 2025-04-10 21:33:07 +08:00
parent f18c52ad03
commit 30c05fd514
1 changed files with 12 additions and 1 deletions

View File

@ -85,9 +85,20 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
throw std::runtime_error("NumPy C-API not initialized. Call import_array() in module init");
}
std::cout << "step2" << std::endl;
using PyArray_SimpleNew_t = PyObject*(*)(int, npy_intp*, int);
void* func_ptr = numpyApi_[93];
std::cout << "Raw function pointer: " << func_ptr << std::endl;
// 2. 使用memcpy避免编译器优化问题
PyArray_SimpleNew_t PyArray_SimpleNew;
static_assert(sizeof(func_ptr) == sizeof(PyArray_SimpleNew),
"Pointer size mismatch");
std::cout << "step3" << std::endl;
auto PyArray_SimpleNew = reinterpret_cast<PyArray_SimpleNew_t>(numpyApi_[93]);
memcpy(&PyArray_SimpleNew, &func_ptr, sizeof(func_ptr));
//auto PyArray_SimpleNew = reinterpret_cast<PyArray_SimpleNew_t>(numpyApi_[93]);
std::cout << "step4, PyArray_SimpleNew:" << PyArray_SimpleNew << std::endl;
// 3. 严格校验输入数据