changeset 407:78448e4de20a

Ensure that sys.argv has a value (fixes issue #83) * oct-py-init.cc (pytave::py_init): Initialize sys.argv to be [''].
author Mike Miller <mtmiller@octave.org>
date Mon, 01 May 2017 09:15:40 -0700
parents 16e79a1e96b8
children f833e29b2c12
files oct-py-init.cc
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/oct-py-init.cc	Mon May 01 08:41:01 2017 -0700
+++ b/oct-py-init.cc	Mon May 01 09:15:40 2017 -0700
@@ -37,11 +37,22 @@
 namespace pytave
 {
 
+#if PY_VERSION_HEX >= 0x03000000
+  wchar_t *sys_argv[] { L"", nullptr };
+#else
+  char *sys_argv[] { "", nullptr };
+#endif
+
   void
   py_init ()
   {
+    bool is_initialized = Py_IsInitialized ();
+
     Py_Initialize ();
 
+    if (! is_initialized)
+      PySys_SetArgvEx (1, sys_argv, 0);
+
     // FIXME: these are only needed for Boost.Python implicit conversion
     // of Octave arrays to NumPy arrays
     boost::python::numeric::array::set_module_and_type ("numpy", "ndarray");