亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SWIG 在 Windows 中生成 C++ Python3 包裝器導致斷言 MSVC 2017

SWIG 在 Windows 中生成 C++ Python3 包裝器導致斷言 MSVC 2017

牛魔王的故事 2021-08-17 17:06:29
使用 SWIG 圍繞 C++ 類生成包裝器會在運行時導致奇怪的斷言:Assertion failed!Program: C:\Python37\python37_d.dllFile: c:\_work\4\s\objects\typeobject.cLine: 3634Expression: PyTuple_Check(args)For information on how your program can cause an assertionfailure, see the Visual C++ documentation on asserts(Press Retry to debug the application - JIT must be enabled)如果在彈出的對話框上點擊忽略,一切似乎都正常。我創建了一個示例程序來嘗試復制問題并遇到了同樣的問題:主程序#include "testwrapper.h"#pragma push_macro("slots")#undef slots#include "Python.h"#pragma pop_macro("slots")#include "SwigModules/generated/swig_runtime.h"PyObject * ConvertToWrapper(SwigInterface * instance){    swig_type_info * pTypeInfo = SWIG_TypeQuery("SwigInterface *");    PyObject* obj = SWIG_NewPointerObj(instance, pTypeInfo, 0); <- issue occurs here    return obj;}TestWrapper * wrapper = new TestWrapper();void TestSwig(){  Py_Initialize();  PyRun_SimpleString("import test_module");  ConvertToWrapper(wrapper);  Py_Finalize();}int main(int argc, char *argv[]){  TestSwig();  return 0;}測試包裝器.h#pragma once#include "swiginterface.h"class TestWrapper : public  SwigInterface{public:  TestWrapper(){}  virtual ~TestWrapper(){}  virtual void Test();};swiginterface.h#pragma onceclass SwigInterface{public:  virtual ~SwigInterface(){}  virtual void Test() = 0;};test_module.i(swig 接口文件)%module test_module%{#include "../swiginterface.h"%}%include "../SwigInterface.h"%inline %{  SwigInterface * test;%}setup_function (python)from distutils.core import setup, Extensionsetup(name="test_module",      py_modules=['test_module'],      ext_modules=[Extension("_test_module",                     ["test_module.i"],                     extra_compile_args=["-DSWIG_TYPE_TABLE=test_module"],                     swig_opts=["-c++", "-py3"],                  )])
查看完整描述

2 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

或者升級到 SWIG 4.0,它有一個修復。


查看完整回答
反對 回復 2021-08-17
?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

為了解決這個問題,我需要從 Python3.7 降級到 Python3.6


查看完整回答
反對 回復 2021-08-17
  • 2 回答
  • 0 關注
  • 297 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號