Skip to content

Fix subplot args convert - #355

Open
Sologala wants to merge 2 commits into
lava:masterfrom
Sologala:fix_py3_subplot
Open

Fix subplot args convert#355
Sologala wants to merge 2 commits into
lava:masterfrom
Sologala:fix_py3_subplot

Conversation

@Sologala

@SologalaSologala commented Nov 8, 2023

Copy link
Copy Markdown

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

inlinevoidsubplot(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) throwstd::runtime_error("Call to subplot() failed.");
Py_DECREF(args);
Py_DECREF(res);
}

@SirTwinkleberry

Copy link
Copy Markdown

The implicit conversion part is a duplicate of #333

@ArterioRodrigues

Copy link
Copy Markdown

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 freeto 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

@Sologala@SirTwinkleberry@ArterioRodrigues