aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiodrag Milanović <mmicko@gmail.com>2022-12-02 08:15:31 +0100
committerGitHub <noreply@github.com>2022-12-02 08:15:31 +0100
commita64ed824ed6fadf24cf2871d7752f63ab6613c8b (patch)
tree7ef996bb64529953bb78f1d814d8edd75598753f
parentdcc1cb7ddd580aaf68f9a225e6b45356fc327709 (diff)
parentb0469b3863037cdf7a82b413c7bb7e9d9ae855f3 (diff)
downloadyosys-a64ed824ed6fadf24cf2871d7752f63ab6613c8b.tar.gz
yosys-a64ed824ed6fadf24cf2871d7752f63ab6613c8b.tar.bz2
yosys-a64ed824ed6fadf24cf2871d7752f63ab6613c8b.zip
Merge pull request #3567 from YosysHQ/tcl_fix_crash
Fix tcl crash in case of error executing command
-rw-r--r--kernel/yosys.cc6
-rw-r--r--kernel/yosys.h3
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);