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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
t,
_interpd_[self.get_interpolation()],
self.get_resample(), 1.0,
self.get_filternorm() or 0.0,
self.get_filternorm(),
self.get_filterrad() or 0.0)

# we are done with A_scaled now, remove from namespace
Expand Down Expand Up @@ -447,7 +447,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
t,
_interpd_[self.get_interpolation()],
True, 1,
self.get_filternorm() or 0.0,
self.get_filternorm(),
self.get_filterrad() or 0.0)
# we are done with the mask, delete from namespace to be sure!
del mask
Expand Down Expand Up @@ -481,7 +481,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
self.get_filternorm(), self.get_filterrad() or 0.0)

# at this point output is either a 2D array of normed data
# (of int or float)
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/tri/_tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,9 @@ PyObject* TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
ContourLine::const_iterator point;

// Find total number of points in all contour lines.
int n_points = 0;
npy_intp n_points = 0;
for (line = contour.begin(); line != contour.end(); ++line)
n_points += line->size();
n_points += (npy_intp)line->size();

// Create segs array for point coordinates.
npy_intp segs_dims[2] = {n_points, 2};
Expand Down Expand Up @@ -1021,8 +1021,8 @@ TrapezoidMapTriFinder::add_edge_to_tree(const Edge& edge)
// Iterate through trapezoids intersecting edge from left to right.
// Replace each old trapezoid with 2+ new trapezoids, and replace its
// corresponding nodes in the search tree with new nodes.
unsigned int ntraps = trapezoids.size();
for (unsigned int i = 0; i < ntraps; ++i) {
size_t ntraps = trapezoids.size();
for (size_t i = 0; i < ntraps; ++i) {
Trapezoid* old = trapezoids[i]; // old trapezoid to replace.
bool start_trap = (i == 0);
bool end_trap = (i == ntraps-1);
Expand Down Expand Up @@ -1397,8 +1397,8 @@ TrapezoidMapTriFinder::initialize()
std::random_shuffle(_edges.begin()+2, _edges.end(), rng);

// Add edges, one at a time, to tree.
unsigned int nedges = _edges.size();
for (unsigned int index = 2; index < nedges; ++index) {
size_t nedges = _edges.size();
for (size_t index = 2; index < nedges; ++index) {
if (!add_edge_to_tree(_edges[index]))
throw std::runtime_error("Triangulation is invalid");
_tree->assert_valid(index == nedges-1);
Expand Down
6 changes: 5 additions & 1 deletion setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,13 @@ def get_extension(self):
sources = [
'src/ft2font.cpp',
'src/ft2font_wrapper.cpp',
'src/mplutils.cpp'
'src/mplutils.cpp',
'src/py_converters.cpp',
]
ext = make_extension('matplotlib.ft2font', sources)
FreeType().add_flags(ext)
Numpy().add_flags(ext)
LibAgg().add_flags(ext, add_sources=False)
return ext


Expand Down Expand Up @@ -1394,9 +1396,11 @@ def get_extension(self):
sources = [
"src/_contour.cpp",
"src/_contour_wrapper.cpp",
'src/py_converters.cpp',
]
ext = make_extension('matplotlib._contour', sources)
Numpy().add_flags(ext)
LibAgg().add_flags(ext, add_sources=False)
return ext


Expand Down
16 changes: 8 additions & 8 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ class RendererAgg
DashesVector &linestyles,
AntialiasedArray &antialiaseds,
e_offset_position offset_position,
int check_snap,
int has_curves);
bool check_snap,
bool has_curves);

template <class PointArray, class ColorArray>
void _draw_gouraud_triangle(PointArray &points,
Expand Down Expand Up @@ -915,8 +915,8 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
DashesVector &linestyles,
AntialiasedArray &antialiaseds,
e_offset_position offset_position,
int check_snap,
int has_curves)
bool check_snap,
bool has_curves)
{
typedef agg::conv_transform<typename PathGenerator::path_iterator> transformed_path_t;
typedef PathNanRemover<transformed_path_t> nan_removed_t;
Expand Down Expand Up @@ -1068,8 +1068,8 @@ inline void RendererAgg::draw_path_collection(GCAgg &gc,
linestyles,
antialiaseds,
offset_position,
1,
1);
true,
true);
}

template <class CoordinateArray>
Expand Down Expand Up @@ -1186,8 +1186,8 @@ inline void RendererAgg::draw_quad_mesh(GCAgg &gc,
linestyles,
antialiaseds,
OFFSET_POSITION_FIGURE,
0,
0);
false,
false);
}

template <class PointArray, class ColorArray>
Expand Down
2 changes: 1 addition & 1 deletion src/_backend_agg_basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GCAgg

bool has_hatchpath()
{
return hatchpath.total_vertices();
return hatchpath.total_vertices() != 0;
}

private:
Expand Down
5 changes: 3 additions & 2 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
numpy::array_view<const double, 2> offsets;
agg::trans_affine offset_trans;
numpy::array_view<const double, 2> facecolors;
int antialiased;
bool antialiased;
numpy::array_view<const double, 2> edgecolors;

if (!PyArg_ParseTuple(args,
"O&O&IIO&O&O&O&iO&:draw_quad_mesh",
"O&O&IIO&O&O&O&O&O&:draw_quad_mesh",
&convert_gcagg,
&gc,
&convert_trans_affine,
Expand All @@ -415,6 +415,7 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
&offset_trans,
&convert_colors,
&facecolors,
&convert_bool,
&antialiased,
&convert_colors,
&edgecolors)) {
Expand Down
30 changes: 15 additions & 15 deletions src/_contour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
#define Z_NW Z_LEVEL(POINT_NW)
#define Z_SE Z_LEVEL(POINT_SE)
#define Z_SW Z_LEVEL(POINT_SW)
#define VISITED(quad,li) (_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2))
#define VISITED_S(quad) (_cache[quad] & MASK_VISITED_S)
#define VISITED_W(quad) (_cache[quad] & MASK_VISITED_W)
#define VISITED_CORNER(quad) (_cache[quad] & MASK_VISITED_CORNER)
#define SADDLE(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2))
#define SADDLE_LEFT(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2))
#define SADDLE_START_SW(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2))
#define BOUNDARY_S(quad) (_cache[quad] & MASK_BOUNDARY_S)
#define BOUNDARY_W(quad) (_cache[quad] & MASK_BOUNDARY_W)
#define VISITED(quad,li) ((_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2)) != 0)
#define VISITED_S(quad) ((_cache[quad] & MASK_VISITED_S) != 0)
#define VISITED_W(quad) ((_cache[quad] & MASK_VISITED_W) != 0)
#define VISITED_CORNER(quad) ((_cache[quad] & MASK_VISITED_CORNER) != 0)
#define SADDLE(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2)) != 0)
#define SADDLE_LEFT(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2)) != 0)
#define SADDLE_START_SW(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2)) != 0)
#define BOUNDARY_S(quad) ((_cache[quad] & MASK_BOUNDARY_S) != 0)
#define BOUNDARY_W(quad) ((_cache[quad] & MASK_BOUNDARY_W) != 0)
#define BOUNDARY_N(quad) BOUNDARY_S(quad+_nx)
#define BOUNDARY_E(quad) BOUNDARY_W(quad+1)
#define EXISTS_QUAD(quad) ((_cache[quad] & MASK_EXISTS) == MASK_EXISTS_QUAD)
Expand Down Expand Up @@ -1773,12 +1773,12 @@ void QuadContourGenerator::write_cache_quad(long quad, bool grid_only) const
std::cout << " BNDY=" << (BOUNDARY_S(quad)>0) << (BOUNDARY_W(quad)>0);
if (!grid_only) {
std::cout << " Z=" << Z_LEVEL(quad)
<< " SAD=" << (SADDLE(quad,1)>0) << (SADDLE(quad,2)>0)
<< " LEFT=" << (SADDLE_LEFT(quad,1)>0) << (SADDLE_LEFT(quad,2)>0)
<< " NW=" << (SADDLE_START_SW(quad,1)>0) << (SADDLE_START_SW(quad,2)>0)
<< " VIS=" << (VISITED(quad,1)>0) << (VISITED(quad,2)>0)
<< (VISITED_S(quad)>0) << (VISITED_W(quad)>0)
<< (VISITED_CORNER(quad)>0);
<< " SAD=" << SADDLE(quad,1) << SADDLE(quad,2)
<< " LEFT=" << SADDLE_LEFT(quad,1) << SADDLE_LEFT(quad,2)
<< " NW=" << SADDLE_START_SW(quad,1) << SADDLE_START_SW(quad,2)
<< " VIS=" << VISITED(quad,1) << VISITED(quad,2)
<< VISITED_S(quad) << VISITED_W(quad)
<< VISITED_CORNER(quad);
}
std::cout << std::endl;
}
7 changes: 4 additions & 3 deletions src/_contour_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "src/_contour.h"
#include "src/mplutils.h"
#include "src/py_converters.h"
#include "src/py_exceptions.h"

/* QuadContourGenerator */
Expand Down Expand Up @@ -29,15 +30,15 @@ static int PyQuadContourGenerator_init(PyQuadContourGenerator* self, PyObject* a
{
QuadContourGenerator::CoordinateArray x, y, z;
QuadContourGenerator::MaskArray mask;
int corner_mask;
bool corner_mask;
long chunk_size;

if (!PyArg_ParseTuple(args, "O&O&O&O&il",
if (!PyArg_ParseTuple(args, "O&O&O&O&O&l",
&x.converter_contiguous, &x,
&y.converter_contiguous, &y,
&z.converter_contiguous, &z,
&mask.converter_contiguous, &mask,
&corner_mask,
&convert_bool, &corner_mask,
&chunk_size)) {
return -1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void _bin_indices_middle(
unsigned int *rowstart = irows;
const float *ys2 = ys1 + 1;
const float *yl = ys1 + ny;
float yo = y_min + dy / 2.0;
float yo = y_min + dy / 2.0f;
float ym = 0.5f * (*ys1 + *ys2);
// y/rows
j = 0;
Expand Down Expand Up @@ -126,7 +126,7 @@ void _bin_indices_linear(
int iilast = (int)ny - 1;
int iy0 = (int)floor(sc * (y[ii] - offs));
int iy1 = (int)floor(sc * (y[ii + 1] - offs));
float invgap = 1.0 / (iy1 - iy0);
float invgap = 1.0f / (iy1 - iy0);
for (i = 0; i < nrows && i < iy0; i++) {
irows[i] = -1;
}
Expand All @@ -135,7 +135,7 @@ void _bin_indices_linear(
ii++;
iy0 = iy1;
iy1 = (int)floor(sc * (y[ii + 1] - offs));
invgap = 1.0 / (iy1 - iy0);
invgap = 1.0f / (iy1 - iy0);
}
if (i >= iy0 && i <= iy1) {
irows[i] = ii;
Expand All @@ -151,7 +151,7 @@ void _bin_indices_linear(
int ii = iilast;
int iy0 = (int)floor(sc * (y[ii] - offs));
int iy1 = (int)floor(sc * (y[ii - 1] - offs));
float invgap = 1.0 / (iy1 - iy0);
float invgap = 1.0f / (iy1 - iy0);
for (i = 0; i < nrows && i < iy0; i++) {
irows[i] = -1;
}
Expand All @@ -160,7 +160,7 @@ void _bin_indices_linear(
ii--;
iy0 = iy1;
iy1 = (int)floor(sc * (y[ii - 1] - offs));
invgap = 1.0 / (iy1 - iy0);
invgap = 1.0f / (iy1 - iy0);
}
if (i >= iy0 && i <= iy1) {
irows[i] = ii - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/_image_resample.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ struct resample_params_t {
agg::trans_affine affine;
const double *transform_mesh;
bool resample;
double norm;
bool norm;
double radius;
double alpha;
};
Expand Down
15 changes: 6 additions & 9 deletions src/_image_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* */

const char* image_resample__doc__ =
"resample(input_array, output_array, matrix, interpolation=NEAREST, alpha=1.0, norm=0, radius=1)\n\n"
"resample(input_array, output_array, matrix, interpolation=NEAREST, alpha=1.0, norm=False, radius=1)\n\n"

"Resample input_array, blending it in-place into output_array, using an\n"
"affine transformation.\n\n"
Expand Down Expand Up @@ -48,8 +48,8 @@ const char* image_resample__doc__ =
" The level of transparency to apply. 1.0 is completely opaque.\n"
" 0.0 is completely transparent.\n\n"

"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 `False`.\n\n"

"radius: float, optional\n"
" The radius of the kernel, if method is SINC, LANCZOS or BLACKMAN.\n"
Expand Down Expand Up @@ -119,7 +119,6 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
PyObject *py_output_array = NULL;
PyObject *py_transform = NULL;
resample_params_t params;
int resample_;

PyArrayObject *input_array = NULL;
PyArrayObject *output_array = NULL;
Expand All @@ -132,10 +131,10 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
"resample", "alpha", "norm", "radius", NULL };

if (!PyArg_ParseTupleAndKeywords(
args, kwargs, "OOO|iiddd:resample", (char **)kwlist,
args, kwargs, "OOO|iO&dO&d:resample", (char **)kwlist,
&py_input_array, &py_output_array, &py_transform,
&params.interpolation, &resample_, &params.alpha, &params.norm,
&params.radius)) {
&params.interpolation, &convert_bool, &params.resample,
&params.alpha, &convert_bool, &params.norm, &params.radius)) {
return NULL;
}

Expand All @@ -145,8 +144,6 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
goto error;
}

params.resample = (resample_ != 0);

input_array = (PyArrayObject *)PyArray_FromAny(
py_input_array, NULL, 2, 3, NPY_ARRAY_C_CONTIGUOUS, NULL);
if (input_array == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ inline bool point_in_path(

points_in_path(points, r, path, trans, result);

return (bool)result[0];
return result[0] != 0;
}

template <class PathIterator, class PointArray, class ResultArray>
Expand Down Expand Up @@ -320,7 +320,7 @@ inline bool point_on_path(

points_on_path(points, r, path, trans, result);

return (bool)result[0];
return result[0] != 0;
}

struct extent_limits
Expand Down Expand Up @@ -1229,7 +1229,7 @@ int convert_to_string(PathIterator &path,
}

if (sketch_params.scale != 0.0) {
*buffersize *= 10.0;
*buffersize *= 10;
}

*buffer = (char *)malloc(*buffersize);
Expand Down
Loading