我正在嘗試創建自定義tcl通道並使用它來獲取tcl Interpreter的輸出。我添加了幾個Tcl_ChannelType函數的實現,但我得到了段錯誤。創建自定義tcl通道驅動程序時出現分段錯誤
#include <tcl.h>
#include <iostream>
int driverBlockModeProc(ClientData instanceData, int mode) {
std::cout << "driverBlockModeProc\n";
return 0;
}
int driverCloseProc(ClientData instanceData, Tcl_Interp *interp) {
std::cout << "driverCloseProc\n";
return 0;
}
int driverInputProc(ClientData instanceData, char* buf, int bufSize, int *errorCodePtr) {
std::cout << "driverInputProc\n";
return 0;
}
int driverOutputProc(ClientData instanceData, const char* buf, int toWrite, int *errorCodePtr) {
std::cout << "driverOutputProc\n";
return 0;
}
int main() {
Tcl_ChannelType *typePtr = new Tcl_ChannelType;
typePtr->blockModeProc = driverBlockModeProc;
typePtr->outputProc = driverOutputProc;
typePtr->closeProc = driverCloseProc;
typePtr->inputProc = driverInputProc;
typePtr->seekProc = NULL;
typePtr->setOptionProc = NULL;
typePtr->getOptionProc = NULL;
typePtr->watchProc = NULL;
typePtr->getHandleProc = NULL;
typePtr->close2Proc = NULL;
typePtr->blockModeProc = NULL;
typePtr->flushProc = NULL;
typePtr->handlerProc = NULL;
typePtr->wideSeekProc = NULL;
typePtr->threadActionProc = NULL;
ClientData data = new char[200];
Tcl_CreateChannel(typePtr, "im_chanel", data, TCL_WRITABLE | TCL_READABLE);
}
我無法調試段錯誤,因爲它的源不可用。我認爲segfault是因爲一個函數被調用,它是NULL。我只需要使用該通道來獲取解釋器的輸出。我不需要在這裏實現哪些功能,是解決問題的正確方向。
Tcl源代碼從[core.tcl.tk](http://core.tcl.tk) –
@JohannesKuhn aviable如何找到'Tcl_CreateChannel'的實現呢? – Ashot
http://core.tcl。tk/tcl/artifact/61eaeb7eca488501a7bd21df744453bfb8c2d4bf –