diff --git a/util/RTCContext.cpp b/util/RTCContext.cpp index d2b6178..72d1715 100644 --- a/util/RTCContext.cpp +++ b/util/RTCContext.cpp @@ -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(numpyApi_[93]); + memcpy(&PyArray_SimpleNew, &func_ptr, sizeof(func_ptr)); + + //auto PyArray_SimpleNew = reinterpret_cast(numpyApi_[93]); std::cout << "step4, PyArray_SimpleNew:" << PyArray_SimpleNew << std::endl; // 3. 严格校验输入数据