Merge pull request #3567 from YosysHQ/tcl_fix_crash

Fix tcl crash in case of error executing command
This commit is contained in:
Miodrag Milanović 2022-12-02 08:15:31 +01:00 committed by GitHub
commit a64ed824ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -590,7 +590,9 @@ void yosys_shutdown()
#ifdef YOSYS_ENABLE_TCL
if (yosys_tcl_interp != NULL) {
Tcl_DeleteInterp(yosys_tcl_interp);
if (!Tcl_InterpDeleted(yosys_tcl_interp)) {
Tcl_DeleteInterp(yosys_tcl_interp);
}
Tcl_Finalize();
yosys_tcl_interp = NULL;
}
@ -789,11 +791,13 @@ struct TclPass : public Pass {
script_args.push_back(Tcl_NewStringObj((*it).c_str(), (*it).size()));
Tcl_Interp *interp = yosys_get_tcl_interp();
Tcl_Preserve(interp);
Tcl_ObjSetVar2(interp, Tcl_NewStringObj("argc", 4), NULL, Tcl_NewIntObj(script_args.size()), 0);
Tcl_ObjSetVar2(interp, Tcl_NewStringObj("argv", 4), NULL, Tcl_NewListObj(script_args.size(), script_args.data()), 0);
Tcl_ObjSetVar2(interp, Tcl_NewStringObj("argv0", 5), NULL, Tcl_NewStringObj(args[1].c_str(), args[1].size()), 0);
if (Tcl_EvalFile(interp, args[1].c_str()) != TCL_OK)
log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(interp));
Tcl_Release(interp);
}
} TclPass;
#endif

View File

@ -82,6 +82,9 @@
# ifdef YOSYS_MXE_HACKS
extern Tcl_Command Tcl_CreateCommand(Tcl_Interp *interp, const char *cmdName, Tcl_CmdProc *proc, ClientData clientData, Tcl_CmdDeleteProc *deleteProc);
extern Tcl_Interp *Tcl_CreateInterp(void);
extern void Tcl_Preserve(ClientData data);
extern void Tcl_Release(ClientData clientData);
extern int Tcl_InterpDeleted(Tcl_Interp *interp);
extern void Tcl_DeleteInterp(Tcl_Interp *interp);
extern int Tcl_Eval(Tcl_Interp *interp, const char *script);
extern int Tcl_EvalFile(Tcl_Interp *interp, const char *fileName);