comparison oct-py-init.cc @ 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 478d83448b0b
children 95c6ad0be828
comparison
equal deleted inserted replaced
406:16e79a1e96b8 407:78448e4de20a
35 #include "arrayobjectdefs.h" 35 #include "arrayobjectdefs.h"
36 36
37 namespace pytave 37 namespace pytave
38 { 38 {
39 39
40 #if PY_VERSION_HEX >= 0x03000000
41 wchar_t *sys_argv[] { L"", nullptr };
42 #else
43 char *sys_argv[] { "", nullptr };
44 #endif
45
40 void 46 void
41 py_init () 47 py_init ()
42 { 48 {
49 bool is_initialized = Py_IsInitialized ();
50
43 Py_Initialize (); 51 Py_Initialize ();
52
53 if (! is_initialized)
54 PySys_SetArgvEx (1, sys_argv, 0);
44 55
45 // FIXME: these are only needed for Boost.Python implicit conversion 56 // FIXME: these are only needed for Boost.Python implicit conversion
46 // of Octave arrays to NumPy arrays 57 // of Octave arrays to NumPy arrays
47 boost::python::numeric::array::set_module_and_type ("numpy", "ndarray"); 58 boost::python::numeric::array::set_module_and_type ("numpy", "ndarray");
48 _import_array (); 59 _import_array ();