gpt4 book ai didi

python - Ctypes:OSError:异常:堆栈溢出

转载 作者:行者123 更新时间:2023-12-02 10:38:30 34 4
gpt4 key购买 nike

问题已解决。函数名称重复。



C++

此代码在exe中有效,但在使用python时在dll中无效。

当程序运行到dec(&buffer2, &length, &buffer);时,Python抛出此错误。

python和dll均为x64。

#include "Decompress.h"
#pragma comment (lib,"Decompress.lib")

#define DLLEXPORT extern "C" __declspec(dllexport)

DLLEXPORT void try_dec()
{
int buffer[20];
int buffer2[20];
int length = 20;

dec(&buffer2, &length, &buffer);

return;
}

python
import ctypes

dll = ctypes.CDLL('Dec.dll')
dll.try_dec()

错误
    dll.dec()
OSError: exception: stack overflow

最佳答案

该函数将自行调用,您最终陷入无限循环,从而导致堆栈溢出。
为了避免这种错误,您应该将函数签名更改为

void dec (void)

关于python - Ctypes:OSError:异常:堆栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57514845/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com