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

Skip to content

MNT: Fix types in C-code to reduce warnings #22604

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 1 commit into from
Mar 6, 2022
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
12 changes: 4 additions & 8 deletions src/_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ inline bool segments_intersect(const double &x1,

// If den == 0 we have two possibilities:
if (isclose(den, 0.0)) {
float t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2);
double t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2);
// 1 - If the area of the triangle made by the 3 first points (2 from the first segment
// plus one from the second) is zero, they are collinear
if (isclose(t_area, 0.0)) {
Expand All @@ -852,7 +852,6 @@ inline bool segments_intersect(const double &x1,
else {
return (fmin(x1, x2) <= fmin(x3, x4) && fmin(x3, x4) <= fmax(x1, x2)) ||
(fmin(x3, x4) <= fmin(x1, x2) && fmin(x1, x2) <= fmax(x3, x4));

}
}
// 2 - If t_area is not zero, the segments are parallel, but not collinear
Expand All @@ -876,7 +875,6 @@ inline bool segments_intersect(const double &x1,
template <class PathIterator1, class PathIterator2>
bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2)
{

typedef PathNanRemover<py::PathIterator> no_nans_t;
typedef agg::conv_curve<no_nans_t> curve_t;

Expand All @@ -901,7 +899,6 @@ bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2)
}
c2.rewind(0);
c2.vertex(&x21, &y21);


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

int size = 0;
unsigned code;

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

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

for (int i = 0; i < size; ++i) {
for (size_t i = 0; i < size; ++i) {
__add_number(x[i], format_code, precision, buffer);
buffer += ' ';
__add_number(y[i], format_code, precision, buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ void FT2Font::get_bitmap_offset(long *x, long *y)

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

image.resize(width, height);

Expand Down
6 changes: 3 additions & 3 deletions src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static unsigned long read_from_file_callback(FT_Stream stream,
return 1; // Non-zero signals error, when count == 0.
}
}
return n_read;
return PyLong_AsUnsignedLong(PyLong_FromSsize_t(n_read));
Copy link
Member

Choose a reason for hiding this comment

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

This change is new from after I reviewed; it leaks the PyLong you just created. Anyway, I don't know why you need a PyLong and can't just cast it in C++?

}

static void close_file_callback(FT_Stream stream)
Expand Down Expand Up @@ -589,7 +589,7 @@ const char *PyFT2Font_get_num_glyphs__doc__ =

static PyObject *PyFT2Font_get_num_glyphs(PyFT2Font *self, PyObject *args)
{
return PyLong_FromLong(self->x->get_num_glyphs());
return PyLong_FromSize_t(self->x->get_num_glyphs());
}

const char *PyFT2Font_load_char__doc__ =
Expand Down Expand Up @@ -1545,7 +1545,7 @@ PyMODINIT_FUNC PyInit_ft2font(void)
FT_Int major, minor, patch;
char version_string[64];
FT_Library_Version(_ft2Library, &major, &minor, &patch);
sprintf(version_string, "%d.%d.%d", major, minor, patch);
snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor, patch);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could have been PyOS_snprintf for consistency with the rest of the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK! It still complains, so can change it.


PyObject *m = PyModule_Create(&moduledef);
if (!m ||
Expand Down