From f493a3d4e2355c5c54dca289a0b9cd3a39ee0e2c Mon Sep 17 00:00:00 2001 From: Sundaram Ramaswamy Date: Thu, 5 Sep 2024 10:25:07 +0530 Subject: [PATCH 1/2] Fix MinGW build failure due to vasprintf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MinGW’s compiler (GCC 14.2.0) errors out compiling `synctex_parser.c`. ``` synctex_parser.c: In function '_synctex_updater_print_gz': synctex_parser.c:8448:13: error: implicit declaration of function 'vasprintf'; did you mean 'vsprintf'? 8448 | if (vasprintf(&buffer, format, va) < 0) { | ^~~~~~~~~ | vsprintf ``` `vasprintf` is a custom function (not the standard `vsprintf`) that’s defined in the same translation unit a few lines above. However its definition is wrapped within a `if defined(_MSC_VER)` i.e. it’s only enabled when compiled with MSVC compiler. This fix enables it also for MinGW compilers. --- server/synctex_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/synctex_parser.c b/server/synctex_parser.c index 27be6089..7ca5a6c2 100644 --- a/server/synctex_parser.c +++ b/server/synctex_parser.c @@ -8415,7 +8415,7 @@ static int _synctex_updater_print(synctex_updater_p updater, const char * format } return result; } -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) #include #include #include From 522e419acd145da61cc3ae4e7e96f7b73d1840f9 Mon Sep 17 00:00:00 2001 From: Sundaram Ramaswamy Date: Tue, 22 Oct 2024 12:58:48 +0530 Subject: [PATCH 2/2] Implement vasprintf for all compilers in WIN32 `vasprintf` is a function available on Linux and macOS but not in Windows. Instead of restricting it for MSVC and MinGW, enable it for all compilers using standard C library function `vsnprintf`. --- server/synctex_parser.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/synctex_parser.c b/server/synctex_parser.c index 7ca5a6c2..865c629e 100644 --- a/server/synctex_parser.c +++ b/server/synctex_parser.c @@ -8415,7 +8415,8 @@ static int _synctex_updater_print(synctex_updater_p updater, const char * format } return result; } -#if defined(_MSC_VER) || defined(__MINGW32__) +#if defined(_WIN32) +// define vasprintf as it’s available only on Linux and macOS. #include #include #include @@ -8424,17 +8425,14 @@ static int vasprintf(char **ret, const char *format, va_list ap) { - int len; - len = _vsnprintf(NULL, 0, format, ap); + int len = vsnprintf(NULL, 0, format, ap); if (len < 0) return -1; *ret = malloc(len + 1); if (!*ret) return -1; - _vsnprintf(*ret, len+1, format, ap); - (*ret)[len] = '\0'; - return len; + return vsnprintf(*ret, len + 1, format, ap); } -#endif +#endif // _WIN32 /** * gzvprintf is not available until OSX 10.10