Skip to content

Fix some C++ warnings #10383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 17, 2018
Merged

Fix some C++ warnings #10383

merged 8 commits into from
Feb 17, 2018

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Feb 6, 2018

PR Summary

This fixes various minor type conversion and other casting warnings. It is not completely clean now, but saves about 100 lines of warnings in every AppVeyor build.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • [N/A] Documentation is sphinx and numpydoc compliant
  • [N/A] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • [N/A] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@@ -109,8 +109,13 @@ int convert_double(PyObject *obj, void *p)
int convert_bool(PyObject *obj, void *p)
{
bool *val = (bool *)p;
int ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

just change the signature of convert_bool to int convert_bool(PyObject *obj, bool *p)?

Copy link
Member Author

Choose a reason for hiding this comment

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

All of the convert functions use void*.

Copy link
Contributor

Choose a reason for hiding this comment

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

not convinced that they should but I guess that's another project...

@@ -387,7 +392,7 @@ int convert_path(PyObject *obj, void *pathp)
if (should_simplify_obj == NULL) {
goto exit;
}
should_simplify = PyObject_IsTrue(should_simplify_obj);
should_simplify = PyObject_IsTrue(should_simplify_obj) != 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps use convert_bool? dunno

@@ -430,7 +430,7 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
offsets,
offset_trans,
facecolors,
antialiased,
antialiased != 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it be simpler (throughout) to make antialiased a bool?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, mostly.

@@ -1008,7 +1008,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
gc.isaa = antialiaseds(i % Naa);

transformed_path_t tpath(path, trans);
nan_removed_t nan_removed(tpath, true, has_curves);
nan_removed_t nan_removed(tpath, true, has_curves != 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

make has_curves a bool?

src/_contour.cpp Outdated
case Edge_N: return BOUNDARY_N(quad_edge.quad);
case Edge_W: return BOUNDARY_W(quad_edge.quad);
case Edge_S: return BOUNDARY_S(quad_edge.quad);
case Edge_E: return BOUNDARY_E(quad_edge.quad) != 0;
Copy link
Contributor

@anntzer anntzer Feb 6, 2018

Choose a reason for hiding this comment

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

modify the macro accordingly?
(same comment applies more or less throughout)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

"norm : float, optional\n"
" The norm for the interpolation function. Default is 0.\n\n"
"norm : bool, optional\n"
" Whether to norm the interpolation function. Default is 0.\n\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

default is false

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

few more comments left to be addressed (make macros return bools, etc) but already an improvement.

@QuLogic QuLogic force-pushed the c-warnings branch 3 times, most recently from cd50cd3 to fa5e2a3 Compare February 6, 2018 09:30
@dopplershift
Copy link
Contributor

Test failure doesn't look spurious.

@QuLogic
Copy link
Member Author

QuLogic commented Feb 6, 2018

It is; that one fails sporadically due to some filename re-use. I've been meaning to look into it...

@tacaswell
Copy link
Member

Do we want to hold off on this until we get a 2.2 rc tagged?

@tacaswell tacaswell added this to the v3.0 milestone Feb 7, 2018
@dopplershift
Copy link
Contributor

I don't think it needs to wait--but your asking gives me pause on clicking the button now...

@QuLogic
Copy link
Member Author

QuLogic commented Feb 12, 2018

BTW, in Python 3.3, PyArg_ParseTupleAndKeywords now supports a p type which returns a boolean value as an int. However, then we'd have to do a != 0 thing to avoid the warnings again. Not sure if that's better or worse than the converter function we have now.

@anntzer
Copy link
Contributor

anntzer commented Feb 13, 2018

btw do you really have a warning on implicitly casting a number to a bool? (dunno, just asking)

@QuLogic
Copy link
Member Author

QuLogic commented Feb 13, 2018

@QuLogic
Copy link
Member Author

QuLogic commented Feb 15, 2018

Can merge now?

setupext.py Outdated
]
ext = make_extension('matplotlib.ft2font', sources)
FreeType().add_flags(ext)
Numpy().add_flags(ext)
LibAgg().add_flags(ext)
Copy link
Contributor

Choose a reason for hiding this comment

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

so libagg became a "dep" of ft2font via py_converters? probably not a big deal but yuck... now that we're py3 only we may as well use the p converter flag instead of convert_bool, if that avoids the additional internal dep.

Copy link
Member Author

Choose a reason for hiding this comment

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

py_converters has Agg stuff in it so includes its headers, and then we need to add its flags... I think I can split them up so that this isn't necessary.

Using p will still produce an int which caused the warnings on AppVeyor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though maybe I'd wait for #10426 so I don't have to worry about the old backends.

Copy link
Contributor

Choose a reason for hiding this comment

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

but we can just do the cast of the result of p ourselves?
I don't want to force you to overengineer this, the addition of agg as a dependency only somewhat annoys me.

Copy link
Member Author

Choose a reason for hiding this comment

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

But then we'd need all the != 0 that you didn't like, no? Because MSVC didn't like (bool)var either...

Copy link
Contributor

Choose a reason for hiding this comment

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

if an explicit typecast triggers a warning that seems a bit too much but can't do anything about it :/ I guess that sort of forces towards using != 0 (or !!x) then...

Copy link
Member Author

Choose a reason for hiding this comment

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

If it helps you feel a little better, I also stopped it adding Agg sources to these extensions, which was unnecessary.

This prevents a bunch of repeated warnings since these headers are
included multiple times.
This prevents a warning casting from double to float if the variable is
not double.
It only accepts a boolean on the Python side, but this is not enforced
on the C++ side. This causes many casting warnings since it's used
multiple times calling various filters that only take a `bool`.
No need to cast the int before dividing, because the divisor is a
double. It is necessary to cast the entire expression though, since the
storage variable is only a float.
@QuLogic
Copy link
Member Author

QuLogic commented Feb 17, 2018

Rebased and tweaked setup a little so Agg sources don't get built into the new ones.

@anntzer
Copy link
Contributor

anntzer commented Feb 17, 2018

good to go once appveyor passes

@anntzer anntzer merged commit 96c2876 into matplotlib:master Feb 17, 2018
@QuLogic QuLogic deleted the c-warnings branch February 17, 2018 20:45
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.

4 participants