@@ -31,6 +31,7 @@ namespace matplotlibcpp {
31
31
32
32
struct _interpreter {
33
33
PyObject *s_python_function_show;
34
+ PyObject *s_python_function_close;
34
35
PyObject *s_python_function_draw;
35
36
PyObject *s_python_function_pause;
36
37
PyObject *s_python_function_save;
@@ -116,6 +117,7 @@ namespace matplotlibcpp {
116
117
if (!pylabmod) { throw std::runtime_error (" Error loading module pylab!" ); }
117
118
118
119
s_python_function_show = PyObject_GetAttrString (pymod, " show" );
120
+ s_python_function_close = PyObject_GetAttrString (pymod, " close" );
119
121
s_python_function_draw = PyObject_GetAttrString (pymod, " draw" );
120
122
s_python_function_pause = PyObject_GetAttrString (pymod, " pause" );
121
123
s_python_function_figure = PyObject_GetAttrString (pymod, " figure" );
@@ -138,6 +140,7 @@ namespace matplotlibcpp {
138
140
s_python_function_tight_layout = PyObject_GetAttrString (pymod, " tight_layout" );
139
141
140
142
if ( !s_python_function_show
143
+ || !s_python_function_close
141
144
|| !s_python_function_draw
142
145
|| !s_python_function_pause
143
146
|| !s_python_function_figure
@@ -161,6 +164,7 @@ namespace matplotlibcpp {
161
164
) { throw std::runtime_error (" Couldn't find required function!" ); }
162
165
163
166
if ( !PyFunction_Check (s_python_function_show)
167
+ || !PyFunction_Check (s_python_function_close)
164
168
|| !PyFunction_Check (s_python_function_draw)
165
169
|| !PyFunction_Check (s_python_function_pause)
166
170
|| !PyFunction_Check (s_python_function_figure)
@@ -673,11 +677,21 @@ namespace matplotlibcpp {
673
677
res = PyObject_Call ( detail::_interpreter::get ().s_python_function_show , detail::_interpreter::get ().s_python_empty_tuple , kwargs);
674
678
}
675
679
680
+ if (!res) throw std::runtime_error (" Call to show() failed." );
676
681
677
- if (!res) throw std::runtime_error (" Call to show() failed." );
682
+ Py_DECREF (res);
683
+ }
678
684
679
- Py_DECREF (res);
680
- }
685
+ inline void close ()
686
+ {
687
+ PyObject* res = PyObject_CallObject (
688
+ detail::_interpreter::get ().s_python_function_close ,
689
+ detail::_interpreter::get ().s_python_empty_tuple );
690
+
691
+ if (!res) throw std::runtime_error (" Call to close() failed." );
692
+
693
+ Py_DECREF (res);
694
+ }
681
695
682
696
inline void draw ()
683
697
{
0 commit comments