{"thread":{"id":"36844","subject":"[PATCH] mingw: redefine the wrapper macro after the corresponding function","startedAt":"2014-06-05T08:05:19Z","lastAt":"2014-06-06T18:20:05Z","messageCount":11,"participants":["Stepan Kasal","Karsten Blees","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"243381","messageId":"20140605080519.GB28029@camelia.ucw.cz","threadId":"36844","inReplyTo":null,"subject":"[PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-05T08:05:19Z","receivedAt":"2014-06-05T08:05:19Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"mingw.c defines several wrapper functionsi, like mingw_unlink().\nThese wrappers are deployed by macros like this:\n\t#define unlink mingw_unlink\nThe function itself is preceded by #undef, leaving the wrapper out\nof the game for the rest of mingw.c.\n\nThis was not probably intentional; for example, there are three\ncalls to open() below the definition mingw_open() that probably\nhave no reason to circumvent the wrapper.\nOTOH, there is one call to gethostbyname() before it was undefined;\nprobably happy that it actually calls mingw_gethostbyname().\n\nThis patch adds back the #define after each wrapper definition.\n\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.c | 20 ++++++++++++++++++++\n 1 file changed, 20 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex a0e13bc..e7193c0 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)\n \t       ret = unlink(pathname);\n \treturn ret;\n }\n+#define unlink mingw_unlink\n \n static int is_dir_empty(const char *path)\n {\n@@ -279,6 +280,7 @@ int mingw_rmdir(const char *pathname)\n \t       ret = rmdir(pathname);\n \treturn ret;\n }\n+#define rmdir mingw_rmdir\n \n #undef open\n int mingw_open (const char *filename, int oflags, ...)\n@@ -303,6 +305,7 @@ int mingw_open (const char *filename, int oflags, ...)\n \t}\n \treturn fd;\n }\n+#define open mingw_open\n \n static BOOL WINAPI ctrl_ignore(DWORD type)\n {\n@@ -328,6 +331,7 @@ int mingw_fgetc(FILE *stream)\n \tSetConsoleCtrlHandler(ctrl_ignore, FALSE);\n \treturn ch;\n }\n+#define fgetc mingw_fgetc\n \n #undef fopen\n FILE *mingw_fopen (const char *filename, const char *otype)\n@@ -336,6 +340,7 @@ FILE *mingw_fopen (const char *filename, const char *otype)\n \t\tfilename = \"nul\";\n \treturn fopen(filename, otype);\n }\n+#define fopen mingw_fopen\n \n #undef freopen\n FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)\n@@ -344,6 +349,7 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)\n \t\tfilename = \"nul\";\n \treturn freopen(filename, otype, stream);\n }\n+#define freopen mingw_freopen\n \n #undef fflush\n int mingw_fflush(FILE *stream)\n@@ -366,6 +372,7 @@ int mingw_fflush(FILE *stream)\n \n \treturn ret;\n }\n+#define fflush mingw_fflush\n \n /*\n  * The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.\n@@ -629,6 +636,7 @@ char *mingw_getcwd(char *pointer, int len)\n \t\t\tpointer[i] = '/';\n \treturn ret;\n }\n+#define getcwd mingw_getcwd\n \n /*\n  * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx\n@@ -1183,6 +1191,7 @@ char *mingw_getenv(const char *name)\n \t}\n \treturn result;\n }\n+#define getenv mingw_getenv\n \n /*\n  * Note, this isn't a complete replacement for getaddrinfo. It assumes\n@@ -1366,6 +1375,7 @@ int mingw_gethostname(char *name, int namelen)\n     ensure_socket_initialization();\n     return gethostname(name, namelen);\n }\n+#define gethostname mingw_gethostname\n \n #undef gethostbyname\n struct hostent *mingw_gethostbyname(const char *host)\n@@ -1373,6 +1383,7 @@ struct hostent *mingw_gethostbyname(const char *host)\n \tensure_socket_initialization();\n \treturn gethostbyname(host);\n }\n+#define gethostbyname mingw_gethostbyname\n \n void mingw_freeaddrinfo(struct addrinfo *res)\n {\n@@ -1429,6 +1440,7 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn connect(s, sa, sz);\n }\n+#define connect mingw_connect\n \n #undef bind\n int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)\n@@ -1436,6 +1448,7 @@ int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn bind(s, sa, sz);\n }\n+#define bind mingw_bind\n \n #undef setsockopt\n int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)\n@@ -1443,6 +1456,7 @@ int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn setsockopt(s, lvl, optname, (const char*)optval, optlen);\n }\n+#define setsockopt mingw_setsockopt\n \n #undef shutdown\n int mingw_shutdown(int sockfd, int how)\n@@ -1450,6 +1464,7 @@ int mingw_shutdown(int sockfd, int how)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn shutdown(s, how);\n }\n+#define shutdown mingw_shutdown\n \n #undef listen\n int mingw_listen(int sockfd, int backlog)\n@@ -1457,6 +1472,7 @@ int mingw_listen(int sockfd, int backlog)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn listen(s, backlog);\n }\n+#define listen mingw_listen\n \n #undef accept\n int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)\n@@ -1475,6 +1491,7 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)\n \t}\n \treturn sockfd2;\n }\n+#define accept mingw_accept\n \n #undef rename\n int mingw_rename(const char *pold, const char *pnew)\n@@ -1530,6 +1547,7 @@ repeat:\n \terrno = EACCES;\n \treturn -1;\n }\n+#define rename mingw_rename\n \n /*\n  * Note that this doesn't return the actual pagesize, but\n@@ -1684,6 +1702,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)\n \n \treturn old;\n }\n+#define signal mingw_signal\n \n #undef raise\n int mingw_raise(int sig)\n@@ -1709,6 +1728,7 @@ int mingw_raise(int sig)\n \t\treturn raise(sig);\n \t}\n }\n+#define raise mingw_raise\n \n \n static const char *make_backslash_path(const char *path)\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243397","messageId":"539083FB.6040707@gmail.com","threadId":"36844","inReplyTo":"20140605080519.GB28029@camelia.ucw.cz","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-05T14:51:39Z","receivedAt":"2014-06-05T14:51:39Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 05.06.2014 10:05, schrieb Stepan Kasal:\n> mingw.c defines several wrapper functionsi, like mingw_unlink().\n> These wrappers are deployed by macros like this:\n> \t#define unlink mingw_unlink\n> The function itself is preceded by #undef, leaving the wrapper out\n> of the game for the rest of mingw.c.\n> \n\nIn the current msysgit HEAD, most of these #undef's can simply be removed or have already been removed (e.g. there's no '#undef mingw_unlink'). The reason is that the mingw_unlink implementation calls the unicode version _wunlink, so there's no name clash here.\n\nIf you apply this patch in msysgit, you'll most likely get compile errors due to redefining macros.\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243399","messageId":"20140605151338.GA29385@camelia.ucw.cz","threadId":"36844","inReplyTo":"539083FB.6040707@gmail.com","subject":"Re: [msysGit] Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-05T15:13:38Z","receivedAt":"2014-06-05T15:13:38Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hello Karsten,\n\nOn Thu, Jun 05, 2014 at 04:51:39PM +0200, Karsten Blees wrote:\n> In the current msysgit HEAD, most of these #undef's can simply be\n> removed or have already been removed [...]\n\nnot \"most of.\"  According to my quick count, 6 of 20 have been removed,\n2 more can be removed.  The remaining 12 do play their role.\n(The point you overlooked is that there are several socket related,\nlike bind().)\n\n> If you apply this patch in msysgit, you'll most likely get compile\n> errors due to redefining macros.\n\nIt would be warnings only.  But a quick test shows that redefining\nwith identical definition does not trigger the warning.\n\nStepan\n"},{"id":"243407","messageId":"5390A139.2090406@kdbg.org","threadId":"36844","inReplyTo":"20140605080519.GB28029@camelia.ucw.cz","subject":"Re: [msysGit] [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2014-06-05T16:56:25Z","receivedAt":"2014-06-05T16:56:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 05.06.2014 10:05, schrieb Stepan Kasal:\n> mingw.c defines several wrapper functionsi, like mingw_unlink().\n> These wrappers are deployed by macros like this:\n> \t#define unlink mingw_unlink\n> The function itself is preceded by #undef, leaving the wrapper out\n> of the game for the rest of mingw.c.\n> \n> This was not probably intentional; for example, there are three\n> calls to open() below the definition mingw_open() that probably\n> have no reason to circumvent the wrapper.\n> OTOH, there is one call to gethostbyname() before it was undefined;\n> probably happy that it actually calls mingw_gethostbyname().\n> \n> This patch adds back the #define after each wrapper definition.\n> \n> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n> ---\n>  compat/mingw.c | 20 ++++++++++++++++++++\n>  1 file changed, 20 insertions(+)\n> \n> diff --git a/compat/mingw.c b/compat/mingw.c\n> index a0e13bc..e7193c0 100644\n> --- a/compat/mingw.c\n> +++ b/compat/mingw.c\n> @@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)\n>  \t       ret = unlink(pathname);\n>  \treturn ret;\n>  }\n> +#define unlink mingw_unlink\n(etc...)\n\nI don't particularly like this approach: It robs the precise control of\nwhich function we can invoke from other places in mingw.c.\n\nWithin mingw.c, if some other function inside mingw.c wants to use\nmingw_unlink, then it should be written as 'mingw_unlink(foo)', not\n'unlink(foo)'.\n\nSo, IMO the macros should be #undef'ed at the top of the file, and all\nusers (like the open() and gethostbyname() invocations that you\nidentified) should be audited and changed to call the function they\nactually need (i.e., the system open vs. mingw_open).\n\n-- Hannes\n"},{"id":"243425","messageId":"5390E893.9060600@gmail.com","threadId":"36844","inReplyTo":"5390A139.2090406@kdbg.org","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-05T22:00:51Z","receivedAt":"2014-06-05T22:00:51Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 05.06.2014 18:56, schrieb Johannes Sixt:\n> Am 05.06.2014 10:05, schrieb Stepan Kasal:\n>> mingw.c defines several wrapper functionsi, like mingw_unlink().\n>> These wrappers are deployed by macros like this:\n>> \t#define unlink mingw_unlink\n>> The function itself is preceded by #undef, leaving the wrapper out\n>> of the game for the rest of mingw.c.\n>>\n>> This was not probably intentional; for example, there are three\n>> calls to open() below the definition mingw_open() that probably\n>> have no reason to circumvent the wrapper.\n>> OTOH, there is one call to gethostbyname() before it was undefined;\n>> probably happy that it actually calls mingw_gethostbyname().\n>>\n>> This patch adds back the #define after each wrapper definition.\n>>\n>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n>> ---\n>>  compat/mingw.c | 20 ++++++++++++++++++++\n>>  1 file changed, 20 insertions(+)\n>>\n>> diff --git a/compat/mingw.c b/compat/mingw.c\n>> index a0e13bc..e7193c0 100644\n>> --- a/compat/mingw.c\n>> +++ b/compat/mingw.c\n>> @@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)\n>>  \t       ret = unlink(pathname);\n>>  \treturn ret;\n>>  }\n>> +#define unlink mingw_unlink\n> (etc...)\n> \n> I don't particularly like this approach: It robs the precise control of\n> which function we can invoke from other places in mingw.c.\n> \n> Within mingw.c, if some other function inside mingw.c wants to use\n> mingw_unlink, then it should be written as 'mingw_unlink(foo)', not\n> 'unlink(foo)'.\n> \n\nI very much like this approach. In fact, we already do this for e.g. mingw_raise.\n\n> So, IMO the macros should be #undef'ed at the top of the file, and all\n> users (like the open() and gethostbyname() invocations that you\n> identified) should be audited and changed to call the function they\n> actually need (i.e., the system open vs. mingw_open).\n> \n\nI'm sceptical of moving all #undef's to the top. Other callers would typically want the wrapped version (i.e. mingw_*). At least I can't think of a scenario in which a higher level function would want to bypass the wrapper...\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243427","messageId":"5390EB3C.1070202@gmail.com","threadId":"36844","inReplyTo":"20140605151338.GA29385@camelia.ucw.cz","subject":"Re: Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-05T22:12:12Z","receivedAt":"2014-06-05T22:12:12Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 05.06.2014 17:13, schrieb Stepan Kasal:\n> Hello Karsten,\n> \n> On Thu, Jun 05, 2014 at 04:51:39PM +0200, Karsten Blees wrote:\n>> In the current msysgit HEAD, most of these #undef's can simply be\n>> removed or have already been removed [...]\n> \n> not \"most of.\"  According to my quick count, 6 of 20 have been removed,\n> 2 more can be removed.  The remaining 12 do play their role.\n> (The point you overlooked is that there are several socket related,\n> like bind().)\n> \n\nRight, premature generalization on my part from looking at the first two or so entries.\n\nHowever, I suspect some of the remaining 12 could be improved so that no #undef is necessary. E.g. gethostbyname could probably be implemented using GetAddrInfoW (supports non-ASCII names and IPv6).\n\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243449","messageId":"20140606083233.GB1303@camelia.ucw.cz","threadId":"36844","inReplyTo":"5390E893.9060600@gmail.com","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T08:32:33Z","receivedAt":"2014-06-06T08:32:33Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hello,\n\nOn Fri, Jun 06, 2014 at 12:00:51AM +0200, Karsten Blees wrote:\n> Am 05.06.2014 18:56, schrieb Johannes Sixt:\n> > Within mingw.c, if some other function inside mingw.c wants to use\n> > mingw_unlink, then it should be written as 'mingw_unlink(foo)', not\n> > 'unlink(foo)'.\n> I very much like this approach. In fact, we already do this for e.g. mingw_raise.\n\nHannes, this is consistent with your commit 06bc4b7.  Settled.\n\n> Other callers would typically want the wrapped version (i.e.\n> mingw_*).\n\nIf this assumption were true, then we have to keep the wrapper macros\ndefined, both above and below the wrapper function definition.\nYou are in fact advocating my patch.\n\nUpdated version follows.\n\nStepan\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243450","messageId":"20140606084122.GC1303@camelia.ucw.cz","threadId":"36844","inReplyTo":"20140606083233.GB1303@camelia.ucw.cz","subject":"[PATCH v2] mingw: redefine the wrapper macro after the corresponding function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T08:41:22Z","receivedAt":"2014-06-06T08:41:22Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":">From 624d15bd5d2d06035abc17415127a7cf37b5f981 Mon Sep 17 00:00:00 2001\nFrom: Stepan Kasal <kasal@ucw.cz>\nDate: Thu, 5 Jun 2014 09:17:17 +0200\n\nmingw.c defines several wrapper functions, e.g., mingw_unlink().\nThese wrappers are deployed by macros like this:\n\t#define unlink mingw_unlink\nThe mingw_foo() wrapper often calls the original function, so it has\nto be #undef'ed at that place.\n\nBut for the rest of mingw.c, if the function is used, the user probably\nmeant the fixed functionality.  So it is safer to redefine the macro\nback.\n\nNonetheless, it is preferable to call mingw_foo() explicitly throughout\nmingw.c itself.\n\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.c | 28 ++++++++++++++++++++++++----\n 1 file changed, 24 insertions(+), 4 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex a0e13bc..ee83211 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -224,6 +224,7 @@ int mingw_unlink(const char *pathname)\n \t       ret = unlink(pathname);\n \treturn ret;\n }\n+#define unlink mingw_unlink\n \n static int is_dir_empty(const char *path)\n {\n@@ -279,6 +280,7 @@ int mingw_rmdir(const char *pathname)\n \t       ret = rmdir(pathname);\n \treturn ret;\n }\n+#define rmdir mingw_rmdir\n \n #undef open\n int mingw_open (const char *filename, int oflags, ...)\n@@ -303,6 +305,7 @@ int mingw_open (const char *filename, int oflags, ...)\n \t}\n \treturn fd;\n }\n+#define open mingw_open\n \n static BOOL WINAPI ctrl_ignore(DWORD type)\n {\n@@ -328,6 +331,7 @@ int mingw_fgetc(FILE *stream)\n \tSetConsoleCtrlHandler(ctrl_ignore, FALSE);\n \treturn ch;\n }\n+#define fgetc mingw_fgetc\n \n #undef fopen\n FILE *mingw_fopen (const char *filename, const char *otype)\n@@ -336,6 +340,7 @@ FILE *mingw_fopen (const char *filename, const char *otype)\n \t\tfilename = \"nul\";\n \treturn fopen(filename, otype);\n }\n+#define fopen mingw_fopen\n \n #undef freopen\n FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)\n@@ -344,6 +349,7 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)\n \t\tfilename = \"nul\";\n \treturn freopen(filename, otype, stream);\n }\n+#define freopen mingw_freopen\n \n #undef fflush\n int mingw_fflush(FILE *stream)\n@@ -366,6 +372,7 @@ int mingw_fflush(FILE *stream)\n \n \treturn ret;\n }\n+#define fflush mingw_fflush\n \n /*\n  * The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.\n@@ -525,7 +532,7 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)\n \t\tSetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY);\n \t}\n \n-\tif ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) {\n+\tif ((fh = mingw_open(file_name, O_RDWR | O_BINARY)) < 0) {\n \t\trc = -1;\n \t\tgoto revert_attrs;\n \t}\n@@ -564,7 +571,7 @@ int mkstemp(char *template)\n \tchar *filename = mktemp(template);\n \tif (filename == NULL)\n \t\treturn -1;\n-\treturn open(filename, O_RDWR | O_CREAT, 0600);\n+\treturn mingw_open(filename, O_RDWR | O_CREAT, 0600);\n }\n \n int gettimeofday(struct timeval *tv, void *tz)\n@@ -629,6 +636,7 @@ char *mingw_getcwd(char *pointer, int len)\n \t\t\tpointer[i] = '/';\n \treturn ret;\n }\n+#define getcwd mingw_getcwd\n \n /*\n  * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx\n@@ -700,7 +708,7 @@ static const char *parse_interpreter(const char *cmd)\n \tif (n >= 4 && !strcasecmp(cmd+n-4, \".exe\"))\n \t\treturn NULL;\n \n-\tfd = open(cmd, O_RDONLY);\n+\tfd = mingw_open(cmd, O_RDONLY);\n \tif (fd < 0)\n \t\treturn NULL;\n \tn = read(fd, buf, sizeof(buf)-1);\n@@ -1183,6 +1191,7 @@ char *mingw_getenv(const char *name)\n \t}\n \treturn result;\n }\n+#define getenv mingw_getenv\n \n /*\n  * Note, this isn't a complete replacement for getaddrinfo. It assumes\n@@ -1199,7 +1208,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,\n \tstruct sockaddr_in *sin;\n \n \tif (node) {\n-\t\th = gethostbyname(node);\n+\t\th = mingw_gethostbyname(node);\n \t\tif (!h)\n \t\t\treturn WSAGetLastError();\n \t}\n@@ -1366,6 +1375,7 @@ int mingw_gethostname(char *name, int namelen)\n     ensure_socket_initialization();\n     return gethostname(name, namelen);\n }\n+#define gethostname mingw_gethostname\n \n #undef gethostbyname\n struct hostent *mingw_gethostbyname(const char *host)\n@@ -1373,6 +1383,7 @@ struct hostent *mingw_gethostbyname(const char *host)\n \tensure_socket_initialization();\n \treturn gethostbyname(host);\n }\n+#define gethostbyname mingw_gethostbyname\n \n void mingw_freeaddrinfo(struct addrinfo *res)\n {\n@@ -1429,6 +1440,7 @@ int mingw_connect(int sockfd, struct sockaddr *sa, size_t sz)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn connect(s, sa, sz);\n }\n+#define connect mingw_connect\n \n #undef bind\n int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)\n@@ -1436,6 +1448,7 @@ int mingw_bind(int sockfd, struct sockaddr *sa, size_t sz)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn bind(s, sa, sz);\n }\n+#define bind mingw_bind\n \n #undef setsockopt\n int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)\n@@ -1443,6 +1456,7 @@ int mingw_setsockopt(int sockfd, int lvl, int optname, void *optval, int optlen)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn setsockopt(s, lvl, optname, (const char*)optval, optlen);\n }\n+#define setsockopt mingw_setsockopt\n \n #undef shutdown\n int mingw_shutdown(int sockfd, int how)\n@@ -1450,6 +1464,7 @@ int mingw_shutdown(int sockfd, int how)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn shutdown(s, how);\n }\n+#define shutdown mingw_shutdown\n \n #undef listen\n int mingw_listen(int sockfd, int backlog)\n@@ -1457,6 +1472,7 @@ int mingw_listen(int sockfd, int backlog)\n \tSOCKET s = (SOCKET)_get_osfhandle(sockfd);\n \treturn listen(s, backlog);\n }\n+#define listen mingw_listen\n \n #undef accept\n int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)\n@@ -1475,6 +1491,7 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)\n \t}\n \treturn sockfd2;\n }\n+#define accept mingw_accept\n \n #undef rename\n int mingw_rename(const char *pold, const char *pnew)\n@@ -1530,6 +1547,7 @@ repeat:\n \terrno = EACCES;\n \treturn -1;\n }\n+#define rename mingw_rename\n \n /*\n  * Note that this doesn't return the actual pagesize, but\n@@ -1684,6 +1702,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)\n \n \treturn old;\n }\n+#define signal mingw_signal\n \n #undef raise\n int mingw_raise(int sig)\n@@ -1709,6 +1728,7 @@ int mingw_raise(int sig)\n \t\treturn raise(sig);\n \t}\n }\n+#define raise mingw_raise\n \n \n static const char *make_backslash_path(const char *path)\n-- \n2.0.0.9635.g0be03cb\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243453","messageId":"53918D27.7060604@gmail.com","threadId":"36844","inReplyTo":"20140606083233.GB1303@camelia.ucw.cz","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-06T09:43:03Z","receivedAt":"2014-06-06T09:43:03Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 06.06.2014 10:32, schrieb Stepan Kasal:\n> Hello,\n> \n> On Fri, Jun 06, 2014 at 12:00:51AM +0200, Karsten Blees wrote:\n>> Am 05.06.2014 18:56, schrieb Johannes Sixt:\n>>> Within mingw.c, if some other function inside mingw.c wants to use\n>>> mingw_unlink, then it should be written as 'mingw_unlink(foo)', not\n>>> 'unlink(foo)'.\n>> I very much like this approach. In fact, we already do this for e.g. mingw_raise.\n> \n> Hannes, this is consistent with your commit 06bc4b7.  Settled.\n> \n>> Other callers would typically want the wrapped version (i.e.\n>> mingw_*).\n> \n> If this assumption were true, then we have to keep the wrapper macros\n> defined, both above and below the wrapper function definition.\n\nThat's not what I meant. Assume all other callers are written 'mingw_foo', as suggested by Hannes, and no one except 'mingw_foo' has the need to call MSVCRT's 'foo' directly. Then its irrelevant whether the #undef is at the top or immediately before 'mingw_foo'. Having the #undef in close vicinity of the function definition helps removing it when its no longer needed.\n\nThinking about this some more, the best solution is probably to eliminate the problem altogether by adding inline-wrappers for required CRT-functions, e.g.:\n\nmingw.h:\n\nstatic inline int crt_gethostname(char *host, int namelen)\n{\n\treturn gethostname(host, namelen);\n}\nint mingw_gethostname(char *host, int namelen);\n#define gethostname mingw_gethostname\n\nmingw.c:\n\nint mingw_gethostname(char *name, int namelen)\n{\n    ensure_socket_initialization();\n    return crt_gethostname(name, namelen);\n}\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243455","messageId":"20140606111028.GA1909@camelia.ucw.cz","threadId":"36844","inReplyTo":"53918D27.7060604@gmail.com","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-06T11:10:28Z","receivedAt":"2014-06-06T11:10:28Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hi Karsten,\n\nOn Fri, Jun 06, 2014 at 11:43:03AM +0200, Karsten Blees wrote:\n> [...] Assume all other callers are written\n> 'mingw_foo', as suggested by Hannes, and no one except 'mingw_foo'\n> has the need to call MSVCRT's 'foo' directly. Then its irrelevant\n> whether the #undef is at the top or immediately before 'mingw_foo'.\n\nYet there is still danger that someone calls foo() by mistake.\nIt is still best to have a protection:\n#define foo choke_here_do_not_use_this\n\n> Thinking about this some more, the best solution is probably to\n> eliminate the problem altogether by adding inline-wrappers for\n> required CRT-functions, e.g.:\n\nYes, this is acceptable.  But I wouldn't pollute mingw.h.  You can do\nit on top of mingw.c like this:\n\n#undef gethostname\nstatic inline int crt_gethostname(char *host, int namelen)\n{\n\treturn gethostname(host, namelen);\n}\n#define gethostname please_call_the_mingw_or_crt_version\n\nThis would also be an acceptable solution, though I still prefer my\nsolution, because, as you put it:\n> Having the #undef in close vicinity of the function definition\n> helps removing it when it's no longer needed.\n\nStepan\n\nPS: Anyway, this is another patch which I can mark as \"too much\ndiscussion, try later.\"  Then I can proceed and submit your unicode\nbranch.\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"},{"id":"243509","messageId":"53920655.6070207@gmail.com","threadId":"36844","inReplyTo":"20140606111028.GA1909@camelia.ucw.cz","subject":"Re: [PATCH] mingw: redefine the wrapper macro after the corresponding function","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-06T18:20:05Z","receivedAt":"2014-06-06T18:20:05Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 06.06.2014 13:10, schrieb Stepan Kasal:\n> Hi Karsten,\n> \n> On Fri, Jun 06, 2014 at 11:43:03AM +0200, Karsten Blees wrote:\n>> Thinking about this some more, the best solution is probably to\n>> eliminate the problem altogether by adding inline-wrappers for\n>> required CRT-functions, e.g.:\n> \n> Yes, this is acceptable.  But I wouldn't pollute mingw.h.  You can do\n> it on top of mingw.c like this:\n\nBut having it in the .h file may come in handy if we want to split the overlong mingw.c into several compilation units...\n\n> \n> #undef gethostname\n> static inline int crt_gethostname(char *host, int namelen)\n> {\n> \treturn gethostname(host, namelen);\n> }\n> #define gethostname please_call_the_mingw_or_crt_version\n> \n\nNow you're mixing all three variants...note that with my suggestion to #define crt_foo in mingw.h, you don't need '#undef foo', nor redefine foo (your variant), nor rename other callers in mingw.c to 'mingw_foo' (Hannes' variant).\n\nCallers of foo() would simply write \"foo()\", no matter whether in mingw.c or anywhere else. In the special case that you really want the CRT version, you'd write crt_foo(). This works everywhere, even in core-git code wrapped in #ifdef GIT_WINDOWS_NATIVE.\n\n-- \n-- \n*** Please reply-to-all at all times ***\n*** (do not pretend to know who is subscribed and who is not) ***\n*** Please avoid top-posting. ***\nThe msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.\n\nYou received this message because you are subscribed to the Google\nGroups \"msysGit\" group.\nTo post to this group, send email to msysgit@googlegroups.com\nTo unsubscribe from this group, send email to\nmsysgit+unsubscribe@googlegroups.com\nFor more options, and view previous threads, visit this group at\nhttp://groups.google.com/group/msysgit?hl=en_US?hl=en\n\n--- \nYou received this message because you are subscribed to the Google Groups \"msysGit\" group.\nTo unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.\nFor more options, visit https://groups.google.com/d/optout.\n"}]}