8000 Added hist and named_hist by Mandarancio · Pull Request #14 · lava/matplotlib-cpp · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Mandarancio
Copy link
Contributor

Hi I added hist and named_hist to your code ;)



Py_DECREF(ylist);
Py_DECREF(plot_args);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you double-check that the reference count of ylist (ylist->ob_refcnt) isn't negative after this? My understanding is that PyTuple_SetItem() does steal the reference and Py_DECREF(plot_args) should be enough dispose it.

Copy link
Contributor Author
@Mandarancio Mandarancio Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, but I will verify before removing Py_DECREF(ylist).
If you are right, all plot methods have to be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looks like it's working correctly like this, no negative values, and seems to be coherent with the doc: https://docs.python.org/2.7/c-api/refcounting.html#c.Py_DECREF

Copy link
Owner
@lava lava Oct 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you check it? Trying it myself in gdb gives me the following:

180         Py_DECREF(ylist);
(gdb) p ylist->ob_refcnt
$3 = 1
(gdb) n
181         Py_DECREF(plot_args);
(gdb) p ylist->ob_refcnt
$6 = 0
(gdb) n
182         Py_DECREF(kwargs);
(gdb) p ylist->ob_refcnt
$7 = -1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not checked after Py_DECREF(kwargs) , but why it affect ylist? the 2 objects are not linked right?

Copy link
Owner
@lava lava Oct 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an artifact of the gdb display, the line displayed is the next line that will be executed on command n. So the last line represents the state of the program after executing Py_DECREF(plot_args)

matplotlibcpp.h Outdated

inline void figure(){
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple);
if(!res) throw std::runtime_error("Call to legend() failed.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Call to figure() failed."

matplotlibcpp.h Outdated
PyObject* ylist = PyList_New(y.size());

PyObject* kwargs = PyDict_New();
PyDict_SetItemString(kwargs, "bins" ,PyFloat_FromDouble(bins));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be PyLong_FromLong(), running this gives me

/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py:600: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

Py_DECREF(res);
return arr;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I Added two methods to get x and y limits

@Mandarancio
Copy link
Contributor Author

On Wed, Oct 26, 2016 at 4:38 PM, Benno Evers notifications@github.com
wrote:

I think it should be PyLong_FromLong(), running this gives me

Yes! Thank you! I tried with PyInt_FromLong(..) but was crashing (this
function is not working actually), I pushed the changes ...

Martino Ferrari

@Mandarancio
Copy link
Contributor Author

On Wed, Oct 26, 2016 at 4:38 PM, Benno Evers notifications@github.com
wrote:

I think it should be PyLong_FromLong(), running this gives me

Yes! Thank you! I tried with PyInt_FromLong(..) but was crashing (this
function is not working actually), I will commit it later...

Martino Ferrari

@lava
Copy link
Owner
lava commented Nov 23, 2016

Nice, thanks for your contribution!

@lava lava merged commit be35f6a into lava:master Nov 23, 2016
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.

2 participants

0