8000 Small fixes · MuddSub/matplotlib-cpp@f3c0563 · GitHub
[go: up one dir, main page]

Skip to content

Commit f3c0563

Browse files
committed
Small fixes
1 parent 70d508f commit f3c0563

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

matplotlibcpp.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <iostream>
1414
#include <cstdint> // <cstdint> requires c++11 support
1515
#include <functional>
16+
#include <stdlib.h>
1617

1718
#ifndef WITHOUT_NUMPY
1819
# define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@@ -174,7 +175,11 @@ struct _interpreter {
174175
wchar_t const *dummy_args[] = {L"Python", NULL}; // const is needed because literals must not be modified
175176
wchar_t const **argv = dummy_args;
176177
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);
178183

179184
#ifndef WITHOUT_NUMPY
180185
import_numpy(); // initialize numpy C-API
@@ -356,7 +361,7 @@ PyObject* get_array(const std::vector<Numeric>& v)
356361
PyArray_UpdateFlags(reinterpret_cast<PyArrayObject*>(varray), NPY_ARRAY_OWNDATA);
357362
return varray;
358363
}
359-
364+
360365
PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (void*)(v.data()));
361366
return varray;
362367
}
@@ -423,7 +428,7 @@ PyObject* get_listlist(const std::vector<std::vector<Numeric>>& ll)
423428
} // namespace detail
424429

425430
/// Plot a line through the given x and y data points..
426-
///
431+
///
427432
/// See: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html
428433
template<typename Numeric>
429434
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,
564569
{
565570
detail::_interpreter::get();
566571

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
570575
// want to require it for people who don't need 3d plots.
571576
static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
572577
if (!mpl_toolkitsmod) {
@@ -1634,7 +1639,7 @@ inline void legend(const std::map<std::string, std::string>& keywords)
16341639
if(!res) throw std::runtime_error("Call to legend() failed.");
16351640

16361641
Py_DECREF(kwargs);
1637-
Py_DECREF(res);
1642+
Py_DECREF(res);
16381643
}
16391644

16401645
template<typename Numeric>
@@ -1874,7 +1879,7 @@ inline void tick_params(const std::map<std::string, std::string>& keywords, cons
18741879
inline void subplot(long nrows, long ncols, long plot_number)
18751880
{
18761881
detail::_interpreter::get();
1877-
1882+
18781883
// construct positional args
18791884
PyObject* args = PyTuple_New(3);
18801885
PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
@@ -1939,7 +1944,7 @@ inline void title(const std::string &titlestr, const std::map<std::string, std::
19391944
inline void suptitle(const std::string &suptitlestr, const std::map<std::string, std::string> &keywords = {})
19401945
{
19411946
detail::_interpreter::get();
1942-
1947+
19431948
PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str());
19441949
PyObject* args = PyTuple_New(1);
19451950
PyTuple_SetItem(args, 0, pysuptitlestr);
@@ -2069,9 +2074,9 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std::
20692074
{
20702075
detail::_interpreter::get();
20712076

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
20752080
// want to require it for people who don't need 3d plots.
20762081
static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
20772082
if (!mpl_toolkitsmod) {

0 commit comments

Comments
 (0)
0