Fix some memory leaks #278
Fix some memory leaks
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,7 +277,7 @@ struct _interpreter { | |
s_python_function_colorbar = PyObject_GetAttrString(pymod, "colorbar"); | ||
s_python_function_subplots_adjust = safe_import(pymod,"subplots_adjust"); | ||
s_python_function_rcparams = PyObject_GetAttrString(pymod, "rcParams"); | ||
s_python_function_spy = PyObject_GetAttrString(pymod, "spy"); | ||
#ifndef WITHOUT_NUMPY | ||
s_python_function_imshow = safe_import(pymod, "imshow"); | ||
#endif | ||
|
@@ -560,19 +560,16 @@ void plot_surface(const std::vector<::std::vector<Numeric>> &x, | |
|
||
PyObject *gca = PyObject_GetAttrString(fig, "gca"); | ||
if (!gca) throw std::runtime_error("No gca"); | ||
PyObject *axis = PyObject_Call( | ||
gca, detail::_interpreter::get().s_python_empty_tuple, gca_kwargs); | ||
|
||
if (!axis) throw std::runtime_error("No axis"); | ||
|
||
Py_DECREF(gca); | ||
Py_DECREF(gca_kwargs); | ||
|
||
PyObject *plot_surface = PyObject_GetAttrString(axis, "plot_surface"); | ||
if (!plot_surface) throw std::runtime_error("No surface"); | ||
PyObject *res = PyObject_Call(plot_surface, args, kwargs); | ||
if (!res) throw std::runtime_error("failed surface"); | ||
Py_DECREF(plot_surface); | ||
|
@@ -728,19 +725,16 @@ void plot3(const std::vector<Numeric> &x, | |
|
||
PyObject *gca = PyObject_GetAttrString(fig, "gca"); | ||
if (!gca) throw std::runtime_error("No gca"); | ||
PyObject *axis = PyObject_Call( | ||
gca, detail::_interpreter::get().s_python_empty_tuple, gca_kwargs); | ||
|
||
if (!axis) throw std::runtime_error("No axis"); | ||
|
||
Py_DECREF(gca); | ||
Py_DECREF(gca_kwargs); | ||
|
||
PyObject *plot3 = PyObject_GetAttrString(axis, "plot"); | ||
if (!plot3) throw std::runtime_error("No 3D line plot"); | ||
PyObject *res = PyObject_Call(plot3, args, kwargs); | ||
if (!res) throw std::runtime_error("Failed 3D line plot"); | ||
Py_DECREF(plot3); | ||
|
@@ -1131,19 +1125,16 @@ bool scatter(const std::vector<NumericX>& x, | |
|
||
PyObject *gca = PyObject_GetAttrString(fig, "gca"); | ||
if (!gca) throw std::runtime_error("No gca"); | ||
PyObject *axis = PyObject_Call( | ||
gca, detail::_interpreter::get().s_python_empty_tuple, gca_kwargs); | ||
|
||
if (!axis) throw std::runtime_error("No axis"); | ||
|
||
Py_DECREF(gca); | ||
Py_DECREF(gca_kwargs); | ||
|
||
PyObject *plot3 = PyObject_GetAttrString(axis, "scatter"); | ||
if (!plot3) throw std::runtime_error("No 3D line plot"); | ||
PyObject *res = PyObject_Call(plot3, args, kwargs); | ||
if (!res) throw std::runtime_error("Failed 3D line plot"); | ||
Py_DECREF(plot3); | ||
|
@@ -1508,19 +1499,16 @@ bool quiver(const std::vector<NumericX>& x, const std::vector<NumericY>& y, cons | |
|
||
PyObject *gca = PyObject_GetAttrString(fig, "gca"); | ||
if (!gca) throw std::runtime_error("No gca"); | ||
PyObject *axis = PyObject_Call( | ||
gca, detail::_interpreter::get().s_python_empty_tuple, gca_kwargs); | ||
|
||
if (!axis) throw std::runtime_error("No axis"); | ||
Py_DECREF(gca); | ||
Py_DECREF(gca_kwargs); | ||
|
||
//plot our boys bravely, plot them strongly, plot them with a wink and clap | ||
PyObject *plot3 = PyObject_GetAttrString(axis, "quiver"); | ||
if (!plot3) throw std::runtime_error("No 3D line plot"); | ||
PyObject* res = PyObject_Call( | ||
plot3, plot_args, kwargs); | ||
if (!res) throw std::runtime_error("Failed 3D plot"); | ||
|
@@ -1982,11 +1970,9 @@ inline void set_aspect(Numeric ratio) | |
PyObject_CallObject(detail::_interpreter::get().s_python_function_gca, | ||
detail::_interpreter::get().s_python_empty_tuple); | ||
if (!ax) throw std::runtime_error("Call to gca() failed."); | ||
|
||
PyObject *set_aspect = PyObject_GetAttrString(ax, "set_aspect"); | ||
if (!set_aspect) throw std::runtime_error("Attribute set_aspect not found."); | ||
|
||
PyObject *res = PyObject_Call(set_aspect, args, kwargs); | ||
if (!res) throw std::runtime_error("Call to set_aspect() failed."); | ||
|
@@ -2010,14 +1996,13 @@ inline void set_aspect_equal() | |
PyObject_CallObject(detail::_interpreter::get().s_python_function_gca, | ||
detail::_interpreter::get().s_python_empty_tuple); | ||
if (!ax) throw std::runtime_error("Call to gca() failed."); | ||
|
||
PyObject *set_aspect = PyObject_GetAttrString(ax, "set_aspect"); | ||
if (!set_aspect) throw std::runtime_error("Attribute set_aspect not found."); | ||
|
||
PyObject *res = PyObject_Call(set_aspect, args, kwargs); | ||
if (!res) throw std::runtime_error("Call to set_aspect() failed."); | ||
Py_DECREF(res); | ||
Py_DECREF(set_aspect); | ||
|
||
Py_DECREF(ax); | ||
|
@@ -2506,11 +2491,9 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std:: | |
PyObject_CallObject(detail::_interpreter::get().s_python_function_gca, | ||
detail::_interpreter::get().s_python_empty_tuple); | ||
if (!ax) throw std::runtime_error("Call to gca() failed."); | ||
|
||
PyObject *zlabel = PyObject_GetAttrString(ax, "set_zlabel"); | ||
if (!zlabel) throw std::runtime_error("Attribute set_zlabel not found."); | ||
|
||
PyObject *res = PyObject_Call(zlabel, args, kwargs); | ||
if (!res) throw std::runtime_error("Call to set_zlabel() failed."); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.