summaryrefslogtreecommitdiff
path: root/src/pyinterp.cc
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2019-12-03 22:59:35 +0000
committerJohn Wiegley <johnw@newartisans.com>2019-12-05 15:06:44 +0100
commit12a74c66c6656bbf6a89bfae83b76e3df37d9199 (patch)
tree189bc4543ff839662d4032dbf66cd2e283f17829 /src/pyinterp.cc
parent23d818175a81e46a899c5e8b00be54cfa0881a4e (diff)
downloadfork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.tar.gz
fork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.tar.bz2
fork-ledger-12a74c66c6656bbf6a89bfae83b76e3df37d9199.zip
Port to python3
Diffstat (limited to 'src/pyinterp.cc')
-rw-r--r--src/pyinterp.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pyinterp.cc b/src/pyinterp.cc
index fad0b559..9ae37687 100644
--- a/src/pyinterp.cc
+++ b/src/pyinterp.cc
@@ -153,7 +153,22 @@ void python_interpreter_t::initialize()
main_module = import_module("__main__");
+#if PY_MAJOR_VERSION >= 3
+ static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "ledger", /* m_name */
+ NULL, /* m_doc */
+ -1, /* m_size */
+ NULL, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
+ };
+ python::detail::init_module(moduledef, &initialize_for_python);
+#else
python::detail::init_module("ledger", &initialize_for_python);
+#endif
is_initialized = true;
}
@@ -313,6 +328,18 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
if (! is_initialized)
initialize();
+#if PY_MAJOR_VERSION >= 3
+ wchar_t ** argv = new wchar_t *[args.size() + 1];
+
+ argv[0] = new wchar_t[std::strlen(argv0) + 1];
+ mbstowcs(argv[0], argv0, std::strlen(argv0));
+
+ for (std::size_t i = 0; i < args.size(); i++) {
+ string arg = args.get<string>(i);
+ argv[i + 1] = new wchar_t[arg.length() + 1];
+ mbstowcs(argv[0], arg.c_str(), std::strlen(arg.c_str()));
+ }
+#else
char ** argv = new char *[args.size() + 1];
argv[0] = new char[std::strlen(argv0) + 1];
@@ -323,6 +350,7 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
argv[i + 1] = new char[arg.length() + 1];
std::strcpy(argv[i + 1], arg.c_str());
}
+#endif
int status = 1;