|
13 | 13 | #include <iostream>
|
14 | 14 | #include <cstdint> // <cstdint> requires c++11 support
|
15 | 15 | #include <functional>
|
| 16 | +#include <stdlib.h> |
16 | 17 |
|
17 | 18 | #ifndef WITHOUT_NUMPY
|
18 | 19 | # define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
@@ -174,7 +175,11 @@ struct _interpreter {
|
174 | 175 | wchar_t const *dummy_args[] = {L"Python", NULL}; // const is needed because literals must not be modified
|
175 | 176 | wchar_t const **argv = dummy_args;
|
176 | 177 | int argc = sizeof(dummy_args)/sizeof(dummy_args[0])-1;
|
177 |
| - PySys_SetArgv(argc, const_cast<wchar_t **>(argv)); |
| 178 | + |
| 179 | + const size_t argv_size = wcslen(*argv); |
| 180 | + char* argv_char = static_cast<char*>(malloc(argv_size)); |
| 181 | + wcstombs(argv_char, *argv, argv_size); |
| 182 | + PySys_SetArgv(argc, &argv_char); |
178 | 183 |
|
179 | 184 | #ifndef WITHOUT_NUMPY
|
180 | 185 | import_numpy(); // initialize numpy C-API
|
@@ -356,7 +361,7 @@ PyObject* get_array(const std::vector<Numeric>& v)
|
356 | 361 | PyArray_UpdateFlags(reinterpret_cast<PyArrayObject*>(varray), NPY_ARRAY_OWNDATA);
|
357 | 362 | return varray;
|
358 | 363 | }
|
359 |
| - |
| 364 | + |
360 | 365 | PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (void*)(v.data()));
|
361 | 366 | return varray;
|
362 | 367 | }
|
@@ -423,7 +428,7 @@ PyObject* get_listlist(const std::vector<std::vector<Numeric>>& ll)
|
423 | 428 | } // namespace detail
|
424 | 429 |
|
425 | 430 | /// Plot a line through the given x and y data points..
|
426 |
| -/// |
| 431 | +/// |
427 | 432 | /// See: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html
|
428 | 433 | template<typename Numeric>
|
429 | 434 | bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
|
@@ -564,9 +569,9 @@ void plot3(const std::vector<Numeric> &x,
|
564 | 569 | {
|
565 | 570 | detail::_interpreter::get();
|
566 | 571 |
|
567 |
| - // Same as with plot_surface: We lazily load the modules here the first time |
568 |
| - // this function is called because I'm not sure that we can assume "matplotlib |
569 |
| - // installed" implies "mpl_toolkits installed" on all platforms, and we don't |
| 572 | + // Same as with plot_surface: We lazily load the modules here the first time |
| 573 | + // this function is called because I'm not sure that we can assume "matplotlib |
| 574 | + // installed" implies "mpl_toolkits installed" on all platforms, and we don't |
570 | 575 | // want to require it for people who don't need 3d plots.
|
571 | 576 | static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
|
572 | 577 | if (!mpl_toolkitsmod) {
|
@@ -1634,7 +1639,7 @@ inline void legend(const std::map<std::string, std::string>& keywords)
|
1634 | 1639 | if(!res) throw std::runtime_error("Call to legend() failed.");
|
1635 | 1640 |
|
1636 | 1641 | Py_DECREF(kwargs);
|
1637 |
| - Py_DECREF(res); |
| 1642 | + Py_DECREF(res); |
1638 | 1643 | }
|
1639 | 1644 |
|
1640 | 1645 | template<typename Numeric>
|
@@ -1874,7 +1879,7 @@ inline void tick_params(const std::map<std::string, std::string>& keywords, cons
|
1874 | 1879 | inline void subplot(long nrows, long ncols, long plot_number)
|
1875 | 1880 | {
|
1876 | 1881 | detail::_interpreter::get();
|
1877 |
| - |
| 1882 | + |
1878 | 1883 | // construct positional args
|
1879 | 1884 | PyObject* args = PyTuple_New(3);
|
1880 | 1885 | PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
|
@@ -1939,7 +1944,7 @@ inline void title(const std::string &titlestr, const std::map<std::string, std::
|
1939 | 1944 | inline void suptitle(const std::string &suptitlestr, const std::map<std::string, std::string> &keywords = {})
|
1940 | 1945 | {
|
1941 | 1946 | detail::_interpreter::get();
|
1942 |
| - |
| 1947 | + |
1943 | 1948 | PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str());
|
1944 | 1949 | PyObject* args = PyTuple_New(1);
|
1945 | 1950 | PyTuple_SetItem(args, 0, pysuptitlestr);
|
@@ -2069,9 +2074,9 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std::
|
2069 | 2074 | {
|
2070 | 2075 | detail::_interpreter::get();
|
2071 | 2076 |
|
2072 |
| - // Same as with plot_surface: We lazily load the modules here the first time |
2073 |
| - // this function is called because I'm not sure that we can assume "matplotlib |
2074 |
| - // installed" implies "mpl_toolkits installed" on all platforms, and we don't |
| 2077 | + // Same as with plot_surface: We lazily load the modules here the first time |
| 2078 | + // this function is called because I'm not sure that we can assume "matplotlib |
| 2079 | + // installed" implies "mpl_toolkits installed" on all platforms, and we don't |
2075 | 2080 | // want to require it for people who don't need 3d plots.
|
2076 | 2081 | static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
|
2077 | 2082 | if (!mpl_toolkitsmod) {
|
|
0 commit comments