diff options
-rw-r--r-- | kernel/yosys.cc | 6 | ||||
-rw-r--r-- | kernel/yosys.h | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 4a22d0a7b..01085d29b 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -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 diff --git a/kernel/yosys.h b/kernel/yosys.h index b5b1553f2..29415ff84 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -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); |