8000 Make some C++ bool conversions explicit. · matplotlib/matplotlib@8e3d72c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e3d72c

Browse files
committed
Make some C++ bool conversions explicit.
1 parent c767826 commit 8e3d72c

File tree

8 files changed

+27
-22
lines changed

8 files changed

+27
-22
lines changed

src/_backend_agg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
10081008
gc.isaa = antialiaseds(i % Naa);
10091009

10101010
transformed_path_t tpath(path, trans);
1011-
nan_removed_t nan_removed(tpath, true, has_curves);
1011+
nan_removed_t nan_removed(tpath, true, has_curves != 0);
10121012
clipped_t clipped(nan_removed, do_clip && !has_curves, width, height);
10131013
snapped_t snapped(
10141014
clipped, gc.snap_mode, path.total_vertices(), points_to_pixels(gc.linewidth));
@@ -1022,7 +1022,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
10221022
gc.isaa = antialiaseds(i % Naa);
10231023

10241024
transformed_path_t tpath(path, trans);
1025-
nan_removed_t nan_removed(tpath, true, has_curves);
1025+
nan_removed_t nan_removed(tpath, true, has_curves != 0);
10261026
clipped_t clipped(nan_removed, do_clip, width, height);
10271027
if (has_curves) {
10281028
curve_t curve(clipped);

src/_backend_agg_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg
430430
offsets,
431431
offset_trans,
432432
facecolors,
433-
antialiased,
433+
antialiased != 0,
434434
edgecolors)));
435435

436436
Py_RETURN_NONE;

src/_contour.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,10 +1360,10 @@ bool QuadContourGenerator::is_edge_a_boundary(const QuadEdge& quad_edge) const
13601360
assert(quad_edge.edge != Edge_None && "Invalid edge");
13611361

13621362
switch (quad_edge.edge) {
1363-
case Edge_E: return BOUNDARY_E(quad_edge.quad);
1364-
case Edge_N: return BOUNDARY_N(quad_edge.quad);
1365-
case Edge_W: return BOUNDARY_W(quad_edge.quad);
1366-
case Edge_S: return BOUNDARY_S(quad_edge.quad);
1363+
case Edge_E: return BOUNDARY_E(quad_edge.quad) != 0;
1364+
case Edge_N: return BOUNDARY_N(quad_edge.quad) != 0;
1365+
case Edge_W: return BOUNDARY_W(quad_edge.quad) != 0;
1366+
case Edge_S: return BOUNDARY_S(quad_edge.quad) != 0;
13671367
case Edge_NE: return EXISTS_SW_CORNER(quad_edge.quad);
13681368
case Edge_NW: return EXISTS_SE_CORNER(quad_edge.quad);
13691369
case Edge_SW: return EXISTS_NE_CORNER(quad_edge.quad);
@@ -1750,7 +1750,7 @@ bool QuadContourGenerator::start_line(
17501750
ContourLine contour_line(false);
17511751
follow_interior(contour_line, quad_edge, 1, level, true, 0, 1, false);
17521752
append_contour_line_to_vertices(contour_line, vertices_list);
1753-
return VISITED(quad,1);
1753+
return VISITED(quad,1) != 0;
17541754
}
17551755

17561756
void QuadContourGenerator::write_cache(bool grid_only) const

src/_contour_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int PyQuadContourGenerator_init(PyQuadContourGenerator* self, PyObject* a
6565

6666
CALL_CPP_INIT("QuadContourGenerator",
6767
(self->ptr = new QuadContourGenerator(
68-
x, y, z, mask, corner_mask, chunk_size)));
68+
x, y, z, mask, corner_mask != 0, chunk_size)));
6969
return 0;
7070
}
7171

src/_path.h

Lines changed: 2 additions & 2 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

src/_path_wrapper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO
347347
transforms,
348348
offsets,
349349
offset_trans,
350-
filled,
350+
filled != 0,
351351
offset_position,
352352
result)));
353353
}
@@ -415,7 +415,7 @@ static PyObject *Py_clip_path_to_rect(PyObject *self, PyObject *args, PyObject *
415415
return NULL;
416416
}
417417

418-
CALL_CPP("clip_path_to_rect", (clip_path_to_rect(path, rect, inside, result)));
418+
CALL_CPP("clip_path_to_rect", (clip_path_to_rect(path, rect, inside != 0, result)));
419419

420420
return convert_polygon_vector(result);
421421
}
@@ -545,7 +545,7 @@ static PyObject *Py_path_intersects_rectangle(PyObject *self, PyObject *args, Py
545545
return NULL;
546546
}
547547

548-
CALL_CPP("path_intersects_rectangle", (result = path_intersects_rectangle(path, rect_x1, rect_y1, rect_x2, rect_y2, filled)));
548+
CALL_CPP("path_intersects_rectangle", (result = path_intersects_rectangle(path, rect_x1, rect_y1, rect_x2, rect_y2, filled != 0)));
549549

550550
if (result) {
551551
Py_RETURN_TRUE;
@@ -636,13 +636,13 @@ static PyObject *Py_cleanup_path(PyObject *self, PyObject *args, PyObject *kwds)
636636
CALL_CPP("cleanup_path",
637637
(cleanup_path(path,
638638
trans,
639-
remove_nans,
639+
remove_nans != 0,
640640
do_clip,
641641
clip_rect,
642642
snap_mode,
643643
stroke_width,
644644
simplify,
645-
return_curves,
645+
return_curves != 0,
646646
sketch,
647647
vertices,
648648
codes)));
@@ -727,7 +727,7 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *
727727
CALL_CPP("convert_to_string",
728728
(status = convert_to_string(
729729
path, trans, cliprect, simplify, sketch,
730-
precision, codes, (bool)postfix, &buffer,
730+
precision, codes, postfix != 0, &buffer,
731731
&buffersize)));
732732

733733
if (status) {

src/ft2font_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ static PyObject *PyFT2Font_draw_glyphs_to_bitmap(PyFT2Font *self, PyObject *args
837837
return NULL;
838838
}
839839

840-
CALL_CPP("draw_glyphs_to_bitmap", (self->x->draw_glyphs_to_bitmap(antialiased)));
840+
CALL_CPP("draw_glyphs_to_bitmap", (self->x->draw_glyphs_to_bitmap(antialiased != 0)));
841841

842842
Py_RETURN_NONE;
843843
}
@@ -857,7 +857,7 @@ static PyObject *PyFT2Font_get_xys(PyFT2Font *self, PyObject *args, PyObject *kw
857857
return NULL;
858858
}
859859

860-
CALL_CPP("get_xys", (self->x->get_xys(antialiased, xys)));
860+
CALL_CPP("get_xys", (self->x->get_xys(antialiased != 0, xys)));
861861

862862
return convert_xys_to_array(xys);
863863
}
@@ -897,7 +897,7 @@ static PyObject *PyFT2Font_draw_glyph_to_bitmap(PyFT2Font *self, PyObject *args,
897897
}
898898

899899
CALL_CPP("draw_glyph_to_bitmap",
900-
self->x->draw_glyph_to_bitmap(*(image->x), xd, yd, glyph->glyphInd, antialiased));
900+
self->x->draw_glyph_to_bitmap(*(image->x), xd, yd, glyph->glyphInd, antialiased != 0));
901901

902902
Py_RETURN_NONE;
903903
}

src/py_converters.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ int convert_double(PyObject *obj, void *p)
109109
int convert_bool(PyObject *obj, void *p)
110110
{
111111
bool *val = (bool *)p;
112+
int ret;
112113

113-
*val = PyObject_IsTrue(obj);
114+
ret = PyObject_IsTrue(obj);
115+
if (ret == -1) {
116+
return 0;
117+
}
118+
*val = ret != 0;
114119

115120
return 1;
116121
}
@@ -387,7 +392,7 @@ int convert_path(PyObject *obj, void *pathp)
387392
if (should_simplify_obj == NULL) {
388393
goto exit;
389394
}
390-
should_simplify = PyObject_IsTrue(should_simplify_obj);
395+
should_simplify = PyObject_IsTrue(should_simplify_obj) != 0;
391396

392397
simplify_threshold_obj = PyObject_GetAttrString(obj, "simplify_threshold");
393398
if (simplify_threshold_obj == NULL) {

0 commit comments

Comments
 (0)
0