Skip to content

Commit 0341265

Browse files
committed
driver: fix special args passing to tcl and python
1 parent 9432e97 commit 0341265

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kernel/driver.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int main(int argc, char **argv)
222222
#endif // YOSYS_ENABLE_TCL
223223
#ifdef WITH_PYTHON
224224
("y,py-scriptfile", "execute the Python <script>",
225-
cxxopts::value<std::vector<std::string>>(), "<script>")
225+
cxxopts::value<std::string>(), "<script>")
226226
#endif // WITH_PYTHON
227227
("p,commands", "execute <commands> (to chain commands, separate them with semicolon + whitespace: 'cmd1; cmd2')",
228228
cxxopts::value<std::vector<std::string>>(), "<commands>")
@@ -530,11 +530,11 @@ int main(int argc, char **argv)
530530
if (!scriptfile.empty()) {
531531
if (scriptfile_tcl) {
532532
#ifdef YOSYS_ENABLE_TCL
533-
int tcl_argc = argc - optind;
533+
int tcl_argc = special_args.size();
534534
std::vector<Tcl_Obj*> script_args;
535535
Tcl_Interp *interp = yosys_get_tcl_interp();
536-
for (int i = optind; i < argc; ++i)
537-
script_args.push_back(Tcl_NewStringObj(argv[i], strlen(argv[i])));
536+
for (auto arg : special_args)
537+
script_args.push_back(Tcl_NewStringObj(arg.c_str(), arg.length()));
538538

539539
Tcl_ObjSetVar2(interp, Tcl_NewStringObj("argc", 4), NULL, Tcl_NewIntObj(tcl_argc), 0);
540540
Tcl_ObjSetVar2(interp, Tcl_NewStringObj("argv", 4), NULL, Tcl_NewListObj(tcl_argc, script_args.data()), 0);
@@ -548,10 +548,11 @@ int main(int argc, char **argv)
548548
} else if (scriptfile_python) {
549549
#ifdef WITH_PYTHON
550550
PyObject *sys = PyImport_ImportModule("sys");
551-
PyObject *new_argv = PyList_New(argc - optind + 1);
551+
int py_argc = special_args.size() + 1;
552+
PyObject *new_argv = PyList_New(py_argc);
552553
PyList_SetItem(new_argv, 0, PyUnicode_FromString(scriptfile.c_str()));
553-
for (int i = optind; i < argc; ++i)
554-
PyList_SetItem(new_argv, i - optind + 1, PyUnicode_FromString(argv[i]));
554+
for (int i = 1; i < py_argc; ++i)
555+
PyList_SetItem(new_argv, i, PyUnicode_FromString(special_args[i - 1].c_str()));
555556

556557
PyObject *old_argv = PyObject_GetAttrString(sys, "argv");
557558
PyObject_SetAttrString(sys, "argv", new_argv);

0 commit comments

Comments
 (0)