{"thread":{"id":"21930","subject":"[PATCH v3 2/2] MSVC: Fix an \"incompatible pointer types\" compiler warning","startedAt":"2009-12-10T19:03:13Z","lastAt":"2009-12-10T19:03:13Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"129703","messageId":"4B2145F1.8050205@ramsay1.demon.co.uk","threadId":"21930","inReplyTo":null,"subject":"[PATCH v3 2/2] MSVC: Fix an \"incompatible pointer types\" compiler warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2009-12-10T19:03:13Z","receivedAt":"2009-12-10T19:03:13Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIn particular, the following warning is issued while compiling\ncompat/msvc.c:\n\n    ...mingw.c(223) : warning C4133: 'function' : incompatible \\\ntypes - from '_stati64 *' to '_stat64 *'\n\nwhich relates to a call of _fstati64() in the mingw_fstat()\nfunction definition.\n\nThis is caused by various layers of macro magic and attempts to\navoid macro redefinition compiler warnings. For example, the call\nto _fstati64() mentioned above is actually a call to _fstat64(),\nand expects a pointer to a struct _stat64 rather than the struct\n_stati64 which is passed to mingw_fstat().\n\nThe definition of struct _stati64 given in compat/msvc.h had the\nsame \"shape\" as the definition of struct _stat64, so the call to\n_fstat64() does not actually cause any runtime errors, but the\nstructure types are indeed incompatible.\n\nIn order to avoid the compiler warning, we add declarations for the\nmingw_lstat() and mingw_fstat() functions and supporting macros to\nmsvc.h, suppressing the corresponding declarations in mingw.h, so\nthat we can use the appropriate structure type (and function) names\nfrom the msvc headers.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nChanges from v2:\n    - removed the #if conditionals and related code depending on\n      the _USE_32BIT_TIME_T macro being defined.\n    - re-worded the commit message to reflect the above.\n\nWe assume that git will never be compiled with -D_USE_32BIT_TIME_T,\notherwise this patch will introduce a breakage that the current code\ndoes not suffer.\n\n[Hmm, should the above paragraph (or one like it) be added to the\ncommit message?]\n\nNote that, if we wish to support 64-bit Windows, we would not be able\nto use this macro anyway (it elicits an #error message on WIN64).\n(ie. a time_t can only be 64-bits on WIN64)\n\nATB,\nRamsay Jones\n\n compat/mingw.h |    4 +++-\n compat/msvc.h  |   40 ++++++++++++++++------------------------\n 2 files changed, 19 insertions(+), 25 deletions(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex b3d299f..55fd7fa 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -209,13 +209,15 @@ int mingw_getpagesize(void);\n  * mingw_fstat() instead of fstat() on Windows.\n  */\n #define off_t off64_t\n-#define stat _stati64\n #define lseek _lseeki64\n+#ifndef ALREADY_DECLARED_STAT_FUNCS\n+#define stat _stati64\n int mingw_lstat(const char *file_name, struct stat *buf);\n int mingw_fstat(int fd, struct stat *buf);\n #define fstat mingw_fstat\n #define lstat mingw_lstat\n #define _stati64(x,y) mingw_lstat(x,y)\n+#endif\n \n int mingw_utime(const char *file_name, const struct utimbuf *times);\n #define utime mingw_utime\ndiff --git a/compat/msvc.h b/compat/msvc.h\nindex 9c753a5..023aba0 100644\n--- a/compat/msvc.h\n+++ b/compat/msvc.h\n@@ -21,30 +21,22 @@ static __inline int strcasecmp (const char *s1, const char *s2)\n }\n \n #undef ERROR\n-#undef stat\n-#undef _stati64\n-#include \"compat/mingw.h\"\n-#undef stat\n-#define stat _stati64\n+\n+/* Use mingw_lstat() instead of lstat()/stat() and mingw_fstat() instead\n+ * of fstat(). We add the declaration of these functions here, suppressing\n+ * the corresponding declarations in mingw.h, so that we can use the\n+ * appropriate structure type (and function) names from the msvc headers.\n+ */\n+#define stat _stat64\n+int mingw_lstat(const char *file_name, struct stat *buf);\n+int mingw_fstat(int fd, struct stat *buf);\n+#define fstat mingw_fstat\n+#define lstat mingw_lstat\n #define _stat64(x,y) mingw_lstat(x,y)\n+#define ALREADY_DECLARED_STAT_FUNCS\n+\n+#include \"compat/mingw.h\"\n+\n+#undef ALREADY_DECLARED_STAT_FUNCS\n \n-/*\n-   Even though _stati64 is normally just defined at _stat64\n-   on Windows, we specify it here as a proper struct to avoid\n-   compiler warnings about macro redefinition due to magic in\n-   mingw.h. Struct taken from ReactOS (GNU GPL license).\n-*/\n-struct _stati64 {\n-\t_dev_t  st_dev;\n-\t_ino_t  st_ino;\n-\tunsigned short st_mode;\n-\tshort   st_nlink;\n-\tshort   st_uid;\n-\tshort   st_gid;\n-\t_dev_t  st_rdev;\n-\t__int64 st_size;\n-\ttime_t  st_atime;\n-\ttime_t  st_mtime;\n-\ttime_t  st_ctime;\n-};\n #endif\n-- \n1.6.5\n"}]}