删除或释放数组时,Boost-wrapped python进程死亡

删除或释放数组时,Boost-wrapped python进程死亡,python,boost,heap,wrapper,Python,Boost,Heap,Wrapper,我一直在用python包装C dll。 dll端提供了blackbox,我制作了额外的包装类。 python提供了C dll numpy数据数组。然后C dll处理它并返回它 当我在C中删除数组时,整个程序都会死掉。有或没有深度拷贝。下面是要复制的简短代码 python主机 import mypyd, numpy myobject = mypyd.myimpro() image = readimg() #ndarray result = myobject.process(image) &

我一直在用python包装C dll。 dll端提供了blackbox,我制作了额外的包装类。 python提供了C dll numpy数据数组。然后C dll处理它并返回它

当我在C中删除数组时,整个程序都会死掉。有或没有深度拷贝。下面是要复制的简短代码

python主机

import mypyd, numpy

myobject = mypyd.myimpro()
image = readimg()    #ndarray
result = myobject.process(image) <- process die here with exit code -1073741819
c包装器代码

mywrapclass::mywrapclass(){
    Py_Initialize();
    np::initialize();
    m_handler = initInDLL()
}

np::ndarray mywrapclass::process(np::ndarray input){
    myimagestruct image = ndarray2struct(input); ## deep copy data array
    myimagestruct result = processInDLL(m_handler, image);
    np::ndarray ret = struct2ndarray(result); ## also deep copy data array. just in case.
    return ret;
}
dll的c头(我无法修改此代码。它是用dll提供的)

对不起,代码错了。起初,我天真地认为boost.python或深度复制可以解决这个堆内存问题,哈哈。我尝试了大脑中几乎所有的关键字,但甚至找不到任何开始点

dll在没有boost包装的情况下工作得非常完美。因此,解决这个问题必须是我的责任。
无论如何,感谢您的阅读。

您是否初始化了numpy<代码>np::初始化()是的。只是忘了写。谢谢。你应该发布这些函数的作用以及segfault的来源。或者在发生崩溃时将其删除
namespace np = boost::python::numpy;

class mywrapclass{
    dllhandler m_handler;
    myimagestruct process(np::ndarray);
}
mywrapclass::mywrapclass(){
    Py_Initialize();
    np::initialize();
    m_handler = initInDLL()
}

np::ndarray mywrapclass::process(np::ndarray input){
    myimagestruct image = ndarray2struct(input); ## deep copy data array
    myimagestruct result = processInDLL(m_handler, image);
    np::ndarray ret = struct2ndarray(result); ## also deep copy data array. just in case.
    return ret;
}
typedef struct {
    void *data
    ... size, type etc
} myimagestruct;

typedef void * dllhandler;

dllhandler = initInDLL();
myimagestruct processInDLL(myimagestruct);