我有一个导出此函数的 C dll:
DECLDIR int runTest (char *historyPath, unsigned int candleNumber, void (*testUpdate)(double percentageOfTestCompleted), void (*testFinished)(void), char **error);
我正在尝试以这种方式在我的 python 脚本中使用该函数:
historyFilePath_c = c_char_p(historyFilePath)
candleNumber_c = c_int(1000)
error_c = c_char_p(300);
TEST_UPDATE = CFUNCTYPE(c_int, POINTER(c_double))
testUpdate_c = TEST_UPDATE(testUpdate)
TEST_FINISHED = CFUNCTYPE(c_int)
testFinished_c = TEST_FINISHED(testFinished)
astdll.runTest (historyFilePath_c, candleNumber_c, testUpdate_c, testFinished_c, byref(error_c))
def testUpdate(percentageOfTestCompleted):
print 'Test running ' , percentageOfTestCompleted[0]
return True
def testFinished():
print 'Test finished!!'
return True
我收到此错误(多次因为回调函数运行多次。我将只留下最后一个错误。它们都是相同的)
Test running
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 314, in 'calling callback function'
File "ast.py", line 67, in testUpdate
print 'Test running ' , percentageOfTestCompleted[0]
ValueError: NULL pointer access
Test finished!!