我有一个问题,我正在处理WORD(2字节无符号整数)。以下是我经常运行的命令
import mySimLib
mySimLib.init()
strPtr = mySimLib.strInit( 200 ) #where 200 is the number of characters I want in the
#string. strInit returns a malloc'd pointer
wPtr = mySimLib.wordInit () # where wordInit returns a malloc'd pointer to a WORD.
mySimLib.Write ("Title", "Data", 4) # 4 is the number of bytes required to store data
mySimLib.Search ("Title", strPtr, 200, wPtr) #Search finds the record with same title,
#copies the data into strPtr up to the number of bytes in the record - as long as
#the number of bytes in the strPtr is greater.
mySimLib.printWord (wPtr) #Since I cannot use python to dereference word pointers, I call a C function to print it out.
此时,我的程序崩溃了。它抛出异常(读取违规)或某些GC Object Already跟踪错误。问题是 - 我有一个字符串打印功能,当我打印它时永远不会失败。当我试图打印这个词时,我确实遇到了错误。
这是我的wordptr启动功能:
unsigned int * wordInit () {
unsigned int * d = malloc ( sizeof ( unsigned int ) );
*d = 0;
return d;
}
这是我的打印功能:
void wordPrint (unsigned int * d){
printf ("\nWptr: %d",*d);
}
我不知道我在这里做错了什么,但是这些崩溃非常不稳定和烦人。