From 5aee083f0f9daafe5b1807e584624d874dfcf348 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Tue, 27 May 2025 17:23:45 +0300 Subject: [PATCH 1/2] remove unused char* getline(char*& _lineptr, FILE* _stream), add couple of fixes M_PI --- .../libezgl/include/ezgl/graphics.hpp | 3 + libs/libvtrutil/src/vtr_util.cpp | 61 ------------------- vpr/src/draw/draw_basic.cpp | 3 + 3 files changed, 6 insertions(+), 61 deletions(-) diff --git a/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp b/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp index 7b7250baa5c..1c8898ba056 100644 --- a/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp +++ b/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp @@ -39,6 +39,9 @@ #include #include #include +#ifdef _WIN32 +#define _USE_MATH_DEFINES // ensure (non-standard) value of M_PI is brought in from math.h +#endif #include #include #include diff --git a/libs/libvtrutil/src/vtr_util.cpp b/libs/libvtrutil/src/vtr_util.cpp index eca51b05e90..4b1a1e7be82 100644 --- a/libs/libvtrutil/src/vtr_util.cpp +++ b/libs/libvtrutil/src/vtr_util.cpp @@ -375,67 +375,6 @@ char* fgets(char* buf, int max_size, FILE* fp) { return nullptr; } -/** - * @brief to get an arbitrary long input line and cut off any - * comment part - * - * the getline function is exaly like the __get_delim function - * in GNU with '\n' delimiter. As a result, to make the function - * behaviour identical for Windows (\r\n) and Linux (\n) compiler - * macros for checking operating systems have been used. - * - * @note user need to take care of the given pointer, - * which will be dynamically allocated by getdelim - */ -char* getline(char*& _lineptr, FILE* _stream) { - int i; - int ch; - size_t _n = 0; - ssize_t nread; - -#if defined(__unix__) - nread = getdelim(&_lineptr, &_n, '\n', _stream); -#elif defined(_WIN32) -#define __WIN_NLTK "\r\n" - nread = getdelim(&_lineptr, &_n, __WIN_NLTK, _stream); -#endif - - if (nread == -1) { - int errsv = errno; - std::string error_msg; - - if (errsv == EINVAL) - error_msg = string_fmt("[%s] Bad arguments (_lineptr is NULL, or _stream is not valid).", strerror(errsv)); - else if (errsv == ENOMEM) - error_msg = string_fmt("[%s] Allocation or reallocation of the line buffer failed.", strerror(errsv)); - else - /* end of file so it will return null */ - return nullptr; - - /* getline was unsuccessful, so error */ - throw VtrError(string_fmt("Error -- %s\n", - error_msg.c_str()), - __FILE__, __LINE__); - return nullptr; - } - - cont = 0; /* line continued? */ - file_line_number++; /* global variable */ - - for (i = 0; i < nread; i++) { /* Keep going until the line finishes */ - - ch = _lineptr[i]; - - if (ch == '#') { /* comment */ - _lineptr[i] = '\0'; - /* skip the rest of the line */ - break; - } - } - - return (_lineptr); -} - ///@brief Returns line number of last opened and read file int get_file_line_number_of_last_opened_file() { return file_line_number; diff --git a/vpr/src/draw/draw_basic.cpp b/vpr/src/draw/draw_basic.cpp index 04eed08fcbd..58321714826 100644 --- a/vpr/src/draw/draw_basic.cpp +++ b/vpr/src/draw/draw_basic.cpp @@ -4,6 +4,9 @@ #ifndef NO_GRAPHICS #include +#ifdef _WIN32 +#define _USE_MATH_DEFINES // ensure (non-standard) value of M_PI is brought in from math.h +#endif #include #include #include From da502c75fb5afa6c0380a70c08d3c086dee312e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Date: Thu, 12 Jun 2025 16:16:20 +0300 Subject: [PATCH 2/2] draw_basic.cpp uses std::numbers::pi instead of M_PI, undo changes for ezgl/graphics.hpp subtree --- libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp | 3 --- vpr/src/draw/draw_basic.cpp | 10 ++++------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp b/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp index 1c8898ba056..7b7250baa5c 100644 --- a/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp +++ b/libs/EXTERNAL/libezgl/include/ezgl/graphics.hpp @@ -39,9 +39,6 @@ #include #include #include -#ifdef _WIN32 -#define _USE_MATH_DEFINES // ensure (non-standard) value of M_PI is brought in from math.h -#endif #include #include #include diff --git a/vpr/src/draw/draw_basic.cpp b/vpr/src/draw/draw_basic.cpp index 58321714826..a163f62bfe2 100644 --- a/vpr/src/draw/draw_basic.cpp +++ b/vpr/src/draw/draw_basic.cpp @@ -4,9 +4,7 @@ #ifndef NO_GRAPHICS #include -#ifdef _WIN32 -#define _USE_MATH_DEFINES // ensure (non-standard) value of M_PI is brought in from math.h -#endif +#include #include #include #include @@ -1229,7 +1227,7 @@ void draw_flyline_timing_edge(ezgl::point2d start, ezgl::point2d end, float incr std::string incr_delay_str = ss.str(); // Get the angle of line, to rotate the text - float text_angle = (180 / M_PI) + float text_angle = (180 / std::numbers::pi) * atan((end.y - start.y) / (end.x - start.x)); // Get the screen coordinates for text drawing @@ -1244,9 +1242,9 @@ void draw_flyline_timing_edge(ezgl::point2d start, ezgl::point2d end, float incr // Find an offset so it is sitting on top/below of the line float x_offset = screen_coords.center().x - - 8 * sin(text_angle * (M_PI / 180)); + - 8 * sin(text_angle * (std::numbers::pi / 180)); float y_offset = screen_coords.center().y - - 8 * cos(text_angle * (M_PI / 180)); + - 8 * cos(text_angle * (std::numbers::pi / 180)); ezgl::point2d offset_text_bbox(x_offset, y_offset); g->draw_text(offset_text_bbox, incr_delay_str.c_str(),