Skip to content

Commit 96c2876

Browse files
authored
Merge pull request #10383 from QuLogic/c-warnings
Fix some C++ warnings
2 parents e8a54b4 + abd5942 commit 96c2876

20 files changed

+100
-86
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
412412
t,
413413
_interpd_[self.get_interpolation()],
414414
self.get_resample(), 1.0,
415-
self.get_filternorm() or 0.0,
415+
self.get_filternorm(),
416416
self.get_filterrad() or 0.0)
417417

418418
# we are done with A_scaled now, remove from namespace
@@ -447,7 +447,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
447447
t,
448448
_interpd_[self.get_interpolation()],
449449
True, 1,
450-
self.get_filternorm() or 0.0,
450+
self.get_filternorm(),
451451
self.get_filterrad() or 0.0)
452452
# we are done with the mask, delete from namespace to be sure!
453453
del mask
@@ -481,7 +481,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
481481
_image.resample(
482482
A, output, t, _interpd_[self.get_interpolation()],
483483
self.get_resample(), alpha,
484-
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
484+
self.get_filternorm(), self.get_filterrad() or 0.0)
485485

486486
# at this point output is either a 2D array of normed data
487487
# (of int or float)

lib/matplotlib/tri/_tri.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,9 @@ PyObject* TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
629629
ContourLine::const_iterator point;
630630

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

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

13991399
// Add edges, one at a time, to tree.
1400-
unsigned int nedges = _edges.size();
1401-
for (unsigned int index = 2; index < nedges; ++index) {
1400+
size_t nedges = _edges.size();
1401+
for (size_t index = 2; index < nedges; ++index) {
14021402
if (!add_edge_to_tree(_edges[index]))
14031403
throw std::runtime_error("Triangulation is invalid");
14041404
_tree->assert_valid(index == nedges-1);

setupext.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,11 +1265,13 @@ def get_extension(self):
12651265
sources = [
12661266
'src/ft2font.cpp',
12671267
'src/ft2font_wrapper.cpp',
1268-
'src/mplutils.cpp'
1268+
'src/mplutils.cpp',
1269+
'src/py_converters.cpp',
12691270
]
12701271
ext = make_extension('matplotlib.ft2font', sources)
12711272
FreeType().add_flags(ext)
12721273
Numpy().add_flags(ext)
1274+
LibAgg().add_flags(ext, add_sources=False)
12731275
return ext
12741276

12751277

@@ -1394,9 +1396,11 @@ def get_extension(self):
13941396
sources = [
13951397
"src/_contour.cpp",
13961398
"src/_contour_wrapper.cpp",
1399+
'src/py_converters.cpp',
13971400
]
13981401
ext = make_extension('matplotlib._contour', sources)
13991402
Numpy().add_flags(ext)
1403+
LibAgg().add_flags(ext, add_sources=False)
14001404
return ext
14011405

14021406

src/_backend_agg.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ class RendererAgg
281281
DashesVector &linestyles,
282282
AntialiasedArray &antialiaseds,
283283
e_offset_position offset_position,
284-
int check_snap,
285-
int has_curves);
284+
bool check_snap,
285+
bool has_curves);
286286

287287
template <class PointArray, class ColorArray>
288288
void _draw_gouraud_triangle(PointArray &points,
@@ -915,8 +915,8 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
915915
DashesVector &linestyles,
916916
AntialiasedArray &antialiaseds,
917917
e_offset_position offset_position,
918-
int check_snap,
919-
int has_curves)
918+
bool check_snap,
919+
bool has_curves)
920920
{
921921
typedef agg::conv_transform<typename PathGenerator::path_iterator> transformed_path_t;
922922
typedef PathNanRemover<transformed_path_t> nan_removed_t;
@@ -1068,8 +1068,8 @@ inline void RendererAgg::draw_path_collection(GCAgg &gc,
10681068
linestyles,
10691069
antialiaseds,
10701070
offset_position,
1071-
1,
1072-
1);
1071+
true,
1072+
true);
10731073
}
10741074

10751075
template <class CoordinateArray>
@@ -1186,8 +1186,8 @@ inline void RendererAgg::draw_quad_mesh(GCAgg &gc,
11861186
linestyles,
11871187
antialiaseds,
11881188
OFFSET_POSITION_FIGURE,
1189-
0,
1190-
0);
1189+
false,
1190+
false);
11911191
}
11921192

11931193
template <class PointArray, class ColorArray>

src/_backend_agg_basic_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class GCAgg
115115

116116
bool has_hatchpath()
117117
{
118-
return hatchpath.total_vertices();
118+
return hatchpath.total_vertices() != 0;
119119
}
120120

121121
private:

src/_backend_agg_wrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
396396
numpy::array_view<const double, 2> offsets;
397397
agg::trans_affine offset_trans;
398398
numpy::array_view<const double, 2> facecolors;
399-
int antialiased;
399+
bool antialiased;
400400
numpy::array_view<const double, 2> edgecolors;
401401

402402
if (!PyArg_ParseTuple(args,
403-
"O&O&IIO&O&O&O&iO&:draw_quad_mesh",
403+
"O&O&IIO&O&O&O&O&O&:draw_quad_mesh",
404404
&convert_gcagg,
405405
&gc,
406406
&convert_trans_affine,
@@ -415,6 +415,7 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
415415
&offset_trans,
416416
&convert_colors,
417417
&facecolors,
418+
&convert_bool,
418419
&antialiased,
419420
&convert_colors,
420421
&edgecolors)) {

src/_contour.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@
6060
#define Z_NW Z_LEVEL(POINT_NW)
6161
#define Z_SE Z_LEVEL(POINT_SE)
6262
#define Z_SW Z_LEVEL(POINT_SW)
63-
#define VISITED(quad,li) (_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2))
64-
#define VISITED_S(quad) (_cache[quad] & MASK_VISITED_S)
65-
#define VISITED_W(quad) (_cache[quad] & MASK_VISITED_W)
66-
#define VISITED_CORNER(quad) (_cache[quad] & MASK_VISITED_CORNER)
67-
#define SADDLE(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2))
68-
#define SADDLE_LEFT(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2))
69-
#define SADDLE_START_SW(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2))
70-
#define BOUNDARY_S(quad) (_cache[quad] & MASK_BOUNDARY_S)
71-
#define BOUNDARY_W(quad) (_cache[quad] & MASK_BOUNDARY_W)
63+
#define VISITED(quad,li) ((_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2)) != 0)
64+
#define VISITED_S(quad) ((_cache[quad] & MASK_VISITED_S) != 0)
65+
#define VISITED_W(quad) ((_cache[quad] & MASK_VISITED_W) != 0)
66+
#define VISITED_CORNER(quad) ((_cache[quad] & MASK_VISITED_CORNER) != 0)
67+
#define SADDLE(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2)) != 0)
68+
#define SADDLE_LEFT(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2)) != 0)
69+
#define SADDLE_START_SW(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2)) != 0)
70+
#define BOUNDARY_S(quad) ((_cache[quad] & MASK_BOUNDARY_S) != 0)
71+
#define BOUNDARY_W(quad) ((_cache[quad] & MASK_BOUNDARY_W) != 0)
7272
#define BOUNDARY_N(quad) BOUNDARY_S(quad+_nx)
7373
#define BOUNDARY_E(quad) BOUNDARY_W(quad+1)
7474
#define EXISTS_QUAD(quad) ((_cache[quad] & MASK_EXISTS) == MASK_EXISTS_QUAD)
@@ -1773,12 +1773,12 @@ void QuadContourGenerator::write_cache_quad(long quad, bool grid_only) const
17731773
std::cout << " BNDY=" << (BOUNDARY_S(quad)>0) << (BOUNDARY_W(quad)>0);
17741774
if (!grid_only) {
17751775
std::cout << " Z=" << Z_LEVEL(quad)
1776-
<< " SAD=" << (SADDLE(quad,1)>0) << (SADDLE(quad,2)>0)
1777-
<< " LEFT=" << (SADDLE_LEFT(quad,1)>0) << (SADDLE_LEFT(quad,2)>0)
1778-
<< " NW=" << (SADDLE_START_SW(quad,1)>0) << (SADDLE_START_SW(quad,2)>0)
1779-
<< " VIS=" << (VISITED(quad,1)>0) << (VISITED(quad,2)>0)
1780-
<< (VISITED_S(quad)>0) << (VISITED_W(quad)>0)
1781-
<< (VISITED_CORNER(quad)>0);
1776+
<< " SAD=" << SADDLE(quad,1) << SADDLE(quad,2)
1777+
<< " LEFT=" << SADDLE_LEFT(quad,1) << SADDLE_LEFT(quad,2)
1778+
<< " NW=" << SADDLE_START_SW(quad,1) << SADDLE_START_SW(quad,2)
1779+
<< " VIS=" << VISITED(quad,1) << VISITED(quad,2)
1780+
<< VISITED_S(quad) << VISITED_W(quad)
1781+
<< VISITED_CORNER(quad);
17821782
}
17831783
std::cout << std::endl;
17841784
}

src/_contour_wrapper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "src/_contour.h"
22
#include "src/mplutils.h"
3+
#include "src/py_converters.h"
34
#include "src/py_exceptions.h"
45

56
/* QuadContourGenerator */
@@ -29,15 +30,15 @@ static int PyQuadContourGenerator_init(PyQuadContourGenerator* self, PyObject* a
2930
{
3031
QuadContourGenerator::CoordinateArray x, y, z;
3132
QuadContourGenerator::MaskArray mask;
32-
int corner_mask;
33+
bool corner_mask;
3334
long chunk_size;
3435

35-
if (!PyArg_ParseTuple(args, "O&O&O&O&il",
36+
if (!PyArg_ParseTuple(args, "O&O&O&O&O&l",
3637
&x.converter_contiguous, &x,
3738
&y.converter_contiguous, &y,
3839
&z.converter_contiguous, &z,
3940
&mask.converter_contiguous, &mask,
40-
&corner_mask,
41+
&convert_bool, &corner_mask,
4142
&chunk_size)) {
4243
return -1;
4344
}

src/_image.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void _bin_indices_middle(
1212
unsigned int *rowstart = irows;
1313
const float *ys2 = ys1 + 1;
1414
const float *yl = ys1 + ny;
15-
float yo = y_min + dy / 2.0;
15+
float yo = y_min + dy / 2.0f;
1616
float ym = 0.5f * (*ys1 + *ys2);
1717
// y/rows
1818
j = 0;
@@ -126,7 +126,7 @@ void _bin_indices_linear(
126126
int iilast = (int)ny - 1;
127127
int iy0 = (int)floor(sc * (y[ii] - offs));
128128
int iy1 = (int)floor(sc * (y[ii + 1] - offs));
129-
float invgap = 1.0 / (iy1 - iy0);
129+
float invgap = 1.0f / (iy1 - iy0);
130130
for (i = 0; i < nrows && i < iy0; i++) {
131131
irows[i] = -1;
132132
}
@@ -135,7 +135,7 @@ void _bin_indices_linear(
135135
ii++;
136136
iy0 = iy1;
137137
iy1 = (int)floor(sc * (y[ii + 1] - offs));
138-
invgap = 1.0 / (iy1 - iy0);
138+
invgap = 1.0f / (iy1 - iy0);
139139
}
140140
if (i >= iy0 && i <= iy1) {
141141
irows[i] = ii;
@@ -151,7 +151,7 @@ void _bin_indices_linear(
151151
int ii = iilast;
152152
int iy0 = (int)floor(sc * (y[ii] - offs));
153153
int iy1 = (int)floor(sc * (y[ii - 1] - offs));
154-
float invgap = 1.0 / (iy1 - iy0);
154+
float invgap = 1.0f / (iy1 - iy0);
155155
for (i = 0; i < nrows && i < iy0; i++) {
156156
irows[i] = -1;
157157
}
@@ -160,7 +160,7 @@ void _bin_indices_linear(
160160
ii--;
161161
iy0 = iy1;
162162
iy1 = (int)floor(sc * (y[ii - 1] - offs));
163-
invgap = 1.0 / (iy1 - iy0);
163+
invgap = 1.0f / (iy1 - iy0);
164164
}
165165
if (i >= iy0 && i <= iy1) {
166166
irows[i] = ii - 1;

src/_image_resample.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ struct resample_params_t {
800800
agg::trans_affine affine;
801801
const double *transform_mesh;
802802
bool resample;
803-
double norm;
803+
bool norm;
804804
double radius;
805805
double alpha;
806806
};

src/_image_wrapper.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* */
1515

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

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

51-
"norm : float, optional\n"
52-
" The norm for the interpolation function. Default is 0.\n\n"
51+
"norm : bool, optional\n"
52+
" Whether to norm the interpolation function. Default is `False`.\n\n"
5353

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

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

134133
if (!PyArg_ParseTupleAndKeywords(
135-
args, kwargs, "OOO|iiddd:resample", (char **)kwlist,
134+
args, kwargs, "OOO|iO&dO&d:resample", (char **)kwlist,
136135
&py_input_array, &py_output_array, &py_transform,
137-
&params.interpolation, &resample_, &params.alpha, &params.norm,
138-
&params.radius)) {
136+
&params.interpolation, &convert_bool, &params.resample,
137+
&params.alpha, &convert_bool, &params.norm, &params.radius)) {
139138
return NULL;
140139
}
141140

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

148-
params.resample = (resample_ != 0);
149-
150147
input_array = (PyArrayObject *)PyArray_FromAny(
151148
py_input_array, NULL, 2, 3, NPY_ARRAY_C_CONTIGUOUS, NULL);
152149
if (input_array == NULL) {

src/_path.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ inline bool point_in_path(
278278

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

281-
return (bool)result[0];
281+
return result[0] != 0;
282282
}
283283

284284
template <class PathIterator, class PointArray, class ResultArray>
@@ -320,7 +320,7 @@ inline bool point_on_path(
320320

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

323-
return (bool)result[0];
323+
return result[0] != 0;
324324
}
325325

326326
struct extent_limits
@@ -1229,7 +1229,7 @@ int convert_to_string(PathIterator &path,
12291229
}
12301230

12311231
if (sketch_params.scale != 0.0) {
1232-
*buffersize *= 10.0;
1232+
*buffersize *= 10;
12331233
}
12341234

12351235
*buffer = (char *)malloc(*buffersize);

0 commit comments

Comments
 (0)