Skip to content

Commit d3c9763

Browse files
ChachayBenno Evers
authored andcommitted
Added Python3 support
* Added Python 3 support * fixed a small bug (lava#76)
1 parent 4a725eb commit d3c9763

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626
*.exe
2727
*.out
2828
*.app
29+
30+
# Logfiles
31+
*.tlog
32+
*.log

matplotlibcpp.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
#include <functional>
1111
#endif
1212

13+
#ifdef PY_INCLUDE
14+
#include <Python.h>
15+
#else
1316
#include <python2.7/Python.h>
17+
#endif
18+
19+
#if PY_MAJOR_VERSION >= 3
20+
#define PyString_FromString PyUnicode_FromString
21+
#endif
22+
1423

1524
namespace matplotlibcpp {
1625

@@ -48,8 +57,14 @@ namespace matplotlibcpp {
4857

4958
private:
5059
_interpreter() {
51-
char name[] = "plotting"; // silence compiler warning about const strings
52-
Py_SetProgramName(name); // optional but recommended
60+
61+
// optional but recommended
62+
#if PY_MAJOR_VERSION >= 3
63+
wchar_t name[] = L"plotting";
64+
#else
65+
char name[] = "plotting";
66+
#endif
67+
Py_SetProgramName(name);
5368
Py_Initialize();
5469

5570
PyObject* pyplotname = PyString_FromString("matplotlib.pyplot");
@@ -62,7 +77,7 @@ namespace matplotlibcpp {
6277

6378
PyObject* pylabmod = PyImport_Import(pylabname);
6479
Py_DECREF(pylabname);
65-
if(!pymod) { throw std::runtime_error("Error loading module pylab!"); }
80+
if(!pylabmod) { throw std::runtime_error("Error loading module pylab!"); }
6681

6782
s_python_function_show = PyObject_GetAttrString(pymod, "show");
6883
s_python_function_figure = PyObject_GetAttrString(pymod, "figure");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy