Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 921e9ac

Browse files
authored
Merge pull request #22604 from oscargus/pathtypefix
MNT: Fix types in C-code to reduce warnings
2 parents cf5db83 + fcc6837 commit 921e9ac

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/_path.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ inline bool segments_intersect(const double &x1,
840840

841841
// If den == 0 we have two possibilities:
842842
if (isclose(den, 0.0)) {
843-
float t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2);
843+
double t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2);
844844
// 1 - If the area of the triangle made by the 3 first points (2 from the first segment
845845
// plus one from the second) is zero, they are collinear
846846
if (isclose(t_area, 0.0)) {
@@ -852,7 +852,6 @@ inline bool segments_intersect(const double &x1,
852852
else {
853853
return (fmin(x1, x2) <= fmin(x3, x4) && fmin(x3, x4) <= fmax(x1, x2)) ||
854854
(fmin(x3, x4) <= fmin(x1, x2) && fmin(x1, x2) <= fmax(x3, x4));
855-
856855
}
857856
}
858857
// 2 - If t_area is not zero, the segments are parallel, but not collinear
@@ -876,7 +875,6 @@ inline bool segments_intersect(const double &x1,
876875
template <class PathIterator1, class PathIterator2>
877876
bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2)
878877
{
879-
880878
typedef PathNanRemover<py::PathIterator> no_nans_t;
881879
typedef agg::conv_curve<no_nans_t> curve_t;
882880

@@ -901,7 +899,6 @@ bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2)
901899
}
902900
c2.rewind(0);
903901
c2.vertex(&x21, &y21);
904-
905902

906903
while (c2.vertex(&x22, &y22) != agg::path_cmd_stop) {
907904
// if the segment in path 2 is (almost) 0 length, skip to next vertex
@@ -1147,16 +1144,15 @@ bool __convert_to_string(PathIterator &path,
11471144
double last_x = 0.0;
11481145
double last_y = 0.0;
11491146

1150-
int size = 0;
11511147
unsigned code;
11521148

11531149
while ((code = path.vertex(&x[0], &y[0])) != agg::path_cmd_stop) {
11541150
if (code == CLOSEPOLY) {
11551151
buffer += codes[4];
11561152
} else if (code < 5) {
1157-
size = NUM_VERTICES[code];
1153+
size_t size = NUM_VERTICES[code];
11581154

1159-
for (int i = 1; i < size; ++i) {
1155+
for (size_t i = 1; i < size; ++i) {
11601156
unsigned subcode = path.vertex(&x[i], &y[i]);
11611157
if (subcode != code) {
11621158
return false;
@@ -1176,7 +1172,7 @@ bool __convert_to_string(PathIterator &path,
11761172
buffer += ' ';
11771173
}
11781174

1179-
for (int i = 0; i < size; ++i) {
1175+
for (size_t i = 0; i < size; ++i) {
11801176
__add_number(x[i], format_code, precision, buffer);
11811177
buffer += ' ';
11821178
__add_number(y[i], format_code, precision, buffer);

src/ft2font.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@ void FT2Font::get_bitmap_offset(long *x, long *y)
551551

552552
void FT2Font::draw_glyphs_to_bitmap(bool antialiased)
553553
{
554-
size_t width = (bbox.xMax - bbox.xMin) / 64 + 2;
555-
size_t height = (bbox.yMax - bbox.yMin) / 64 + 2;
554+
long width = (bbox.xMax - bbox.xMin) / 64 + 2;
555+
long height = (bbox.yMax - bbox.yMin) / 64 + 2;
556556

557557
image.resize(width, height);
558558

src/ft2font_wrapper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static unsigned long read_from_file_callback(FT_Stream stream,
291291
return 1; // Non-zero signals error, when count == 0.
292292
}
293293
}
294-
return n_read;
294+
return PyLong_AsUnsignedLong(PyLong_FromSsize_t(n_read));
295295
}
296296

297297
static void close_file_callback(FT_Stream stream)
@@ -589,7 +589,7 @@ const char *PyFT2Font_get_num_glyphs__doc__ =
589589

590590
static PyObject *PyFT2Font_get_num_glyphs(PyFT2Font *self, PyObject *args)
591591
{
592-
return PyLong_FromLong(self->x->get_num_glyphs());
592+
return PyLong_FromSize_t(self->x->get_num_glyphs());
593593
}
594594

595595
const char *PyFT2Font_load_char__doc__ =
@@ -1545,7 +1545,7 @@ PyMODINIT_FUNC PyInit_ft2font(void)
15451545
FT_Int major, minor, patch;
15461546
char version_string[64];
15471547
FT_Library_Version(_ft2Library, &major, &minor, &patch);
1548-
sprintf(version_string, "%d.%d.%d", major, minor, patch);
1548+
snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor, patch);
15491549

15501550
PyObject *m = PyModule_Create(&moduledef);
15511551
if (!m ||

0 commit comments

Comments
 (0)