Skip to content

Commit

Permalink
fixup! to previous commit. add argv[0] which python argv expects
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Oct 24, 2023
1 parent a043228 commit e0b98c8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gnucash/gnucash-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,11 @@ Gnucash::run_scripting (std::vector<std::string> m_script_args,
gnc_shutdown_cli (1);
}

std::vector<char*> newArgv (m_script_args.size());
auto to_c_str = [](std::string& s) { return (char*)s.c_str(); };
std::transform (m_script_args.begin(), m_script_args.end(), newArgv.begin(), to_c_str);
// note the vector<char*> is valid as long as m_script_args's strings are not damaged!
std::vector<const char*> newArgv (m_script_args.size() + 1);
newArgv.push_back ("gnucash-cli"); // because python strips argv[0]
std::transform (m_script_args.begin(), m_script_args.end(), std::back_inserter(newArgv),
[](const std::string& s) { return s.c_str(); });
// note the vector<const char*> is valid as long as m_script_args's strings are not damaged!

gnc_prefs_init ();
gnc_ui_util_init();
Expand All @@ -624,7 +625,7 @@ Gnucash::run_scripting (std::vector<std::string> m_script_args,
scripting_args args { m_script, m_language, m_interactive };
if (m_language == "guile")
{
scm_boot_guile (newArgv.size(), newArgv.data(), run_guile_cli, &args);
scm_boot_guile (newArgv.size(), (char**)newArgv.data(), run_guile_cli, &args);
return 0; // never reached...
}

Expand All @@ -634,7 +635,7 @@ Gnucash::run_scripting (std::vector<std::string> m_script_args,
PyConfig config;
PyConfig_InitPythonConfig(&config);

PyStatus status = PyConfig_SetBytesArgv(&config, newArgv.size(), newArgv.data());
PyStatus status = PyConfig_SetBytesArgv(&config, newArgv.size(), (char**)newArgv.data());
try
{
if (PyStatus_Exception(status))
Expand Down

0 comments on commit e0b98c8

Please sign in to comment.