我正在用C语言编写一个python扩展。C语言中有一个raspberry hw开发板库,所以我正在使用它。所以我将一个函数从C导出到python,在调用结束时,python不停地说*** stack smashing detected ***: python3 terminated。在
python调用:print("self.handle="+str(self.handle))
ret=dcc.dcc_send(self.handle, d[0], d[1], d[2], d[3], d[4], d[5])
print("returned: "+str(ret)) # never gets here
C python导出(完成):
^{pr2}$
堆栈中的另一个调用:int send_command(int handle, unsigned char count, unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4, unsigned char b5) {
unsigned char message[10];
message[0] = CMD_START_VAL;
message[1] = CMD_DCC_MESS;
message[2] = 0;
message[3] = 0xF0 | count; //2 byte size
message[4] = b1;
message[5] = b2;
message[6] = b3;
message[7] = b4;
message[8] = b5;
message[9] = CMD_STOP_VAL;
return write_uart(handle, message,10);
}
堆栈中的最后一个调用(我没有完全写出来,我只是从lib中获取它并修复了其中的一些问题,比如以前存在的无效内存访问):int write_uart(int handle, unsigned char *data,int bytes) {
#ifdef TEST
int length = bytes;
printf("handle: %d\n", handle);
printf("bytes: %d\ndata: ", length);
for (int i=0; i
printf("%d ", (int) data[i]);
printf("\n---\n");
#endif
int txed;
int offset=0;
while (length) {
txed = write(handle, (unsigned char*)data+offset, length);
if (txed==-1) {
fprintf(stderr,"UART WRITE ERRROR!!\n");
return 0;
}
length -= txed;
offset += txed;
}
tcdrain(handle);
return 1;
}
当我运行它时,我得到这样的信息:self.handle=3
1234-handle: 3
handle: 3
bytes: 10
data: 160 25 0 242 47 130 0 0 0 80
---
1235-after-send_command-return: 1
*** stack smashing detected ***: python3 terminated
Aborted
我做错什么了?谢谢