Skip to content

Conversation

@Sologala
Copy link

@Sologala Sologala commented Nov 8, 2023

Unproperly args converting in void subplot(long , long , long) may cause segment fault.

matplotlib-cpp/matplotlibcpp.h

Lines 2252 to 2267 in 2acb4d0

inline void subplot(long nrows, long ncols, long plot_number)
{
detail::_interpreter::get();
// construct positional args
PyObject* args = PyTuple_New(3);
PyTuple_SetItem(args, 0, PyLong_FromLong(nrows));
PyTuple_SetItem(args, 1, PyLong_FromLong(ncols));
PyTuple_SetItem(args, 2, PyLong_FromLong(plot_number));
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_subplot, args);
if(!res) throw std::runtime_error("Call to subplot() failed.");
Py_DECREF(args);
Py_DECREF(res);
}

@SirTwinkleberry
Copy link

The implicit conversion part is a duplicate of #333

@ArterioRodrigues
Copy link

Would double conversion also cause a seg fault? I am using this it seems to work.

 PyObject* args = PyTuple_New(3); 
     PyTuple_SetItem(args, 0, PyDouble_FromLong(nrows)); 
     PyTuple_SetItem(args, 1, PyDouble_FromLong(ncols)); 
     PyTuple_SetItem(args, 2, PyDouble_FromLong(plot_number)); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants