{"thread":{"id":"36782","subject":"[PATCH 0/2] mingw: macro main(), const warnings","startedAt":"2014-05-29T10:43:29Z","lastAt":"2014-06-07T06:46:41Z","messageCount":9,"participants":["Stepan Kasal","Karsten Blees","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"242929","messageId":"20140529104329.GA24021@camelia.ucw.cz","threadId":"36782","inReplyTo":null,"subject":"[PATCH 0/2] mingw: macro main(), const warnings","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-05-29T10:43:29Z","receivedAt":"2014-05-29T10:43:29Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hello,\n\nmingw.h defines a preprocessor macro main(), so that it can wrap the\noriginal function and hoook into initialization.\n\nThe real main() function can have different types of its second\nparameter (char**, const char**, char*[]).  It is not easy to match\nthe type and gcc issues a const warning.  My patch fixes that.\n\nThere were solutions for the same issue published ([1], [2]), but\nnone of them appeared in junio/pu.  This new solution should be more\nfuture proof, as it modifies only compat/mingw.h; the *.c files can\nhave any of the types mentioned above.\n\nI promise to take care of the integration into msysGit if this patch\ngets accepted.  To make it easier, I'm submitting a patch that has\nbeen part of msysGit for 3 years.\n\nKarsten Blees (1):\n  Win32: move main macro to a function\n\nStepan Kasal (1):\n  mingw: avoid const warning\n\n compat/mingw.c | 15 +++++++++++++++\n compat/mingw.h | 17 ++++++-----------\n 2 files changed, 21 insertions(+), 11 deletions(-)\n\n-- \n1.9.2.msysgit.0.496.g23aa553\n\n[1] a hack to fix the warning, by Pat Thoyts, in msysGit since\n1.8.5.2.msysgit.0 (Dec 2013):\nhttps://github.com/msysgit/git/commit/6949537a\n\n[2] more elgant fix:\nFrom: Marat Radchenko <marat@slonopotamus.org>\nDate: Tue, 29 Apr 2014 13:12:02 +0400\nhttp://article.gmane.org/gmane.comp.version-control.git/247535\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":"242930","messageId":"20140529104552.GB24021@camelia.ucw.cz","threadId":"36782","inReplyTo":"20140529104329.GA24021@camelia.ucw.cz","subject":"[PATCH 1/2] Win32: move main macro to a function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-05-29T10:45:52Z","receivedAt":"2014-05-29T10:45:52Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 19:47:23 +0100\n\nThe code in the MinGW main macro is getting more and more complex, move to\na separate initialization function for readabiliy and extensibility.\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.c | 15 +++++++++++++++\n compat/mingw.h | 14 ++++----------\n 2 files changed, 19 insertions(+), 10 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex a0e13bc..c03bafa 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)\n \n \treturn offset + is_dir_sep(path[offset]);\n }\n+\n+void mingw_startup()\n+{\n+\t/* copy executable name to argv[0] */\n+\t__argv[0] = xstrdup(_pgmptr);\n+\n+\t/* initialize critical section for waitpid pinfo_t list */\n+\tInitializeCriticalSection(&pinfo_cs);\n+\n+\t/* set up default file mode and file modes for stdin/out/err */\n+\t_fmode = _O_BINARY;\n+\t_setmode(_fileno(stdin), _O_BINARY);\n+\t_setmode(_fileno(stdout), _O_BINARY);\n+\t_setmode(_fileno(stderr), _O_BINARY);\n+}\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 3eaf822..15f0c9d 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -363,22 +363,16 @@ void free_environ(char **env);\n extern CRITICAL_SECTION pinfo_cs;\n \n /*\n- * A replacement of main() that ensures that argv[0] has a path\n- * and that default fmode and std(in|out|err) are in binary mode\n+ * A replacement of main() that adds win32 specific initialization.\n  */\n \n+void mingw_startup();\n #define main(c,v) dummy_decl_mingw_main(); \\\n static int mingw_main(c,v); \\\n int main(int argc, char **argv) \\\n { \\\n-\textern CRITICAL_SECTION pinfo_cs; \\\n-\t_fmode = _O_BINARY; \\\n-\t_setmode(_fileno(stdin), _O_BINARY); \\\n-\t_setmode(_fileno(stdout), _O_BINARY); \\\n-\t_setmode(_fileno(stderr), _O_BINARY); \\\n-\targv[0] = xstrdup(_pgmptr); \\\n-\tInitializeCriticalSection(&pinfo_cs); \\\n-\treturn mingw_main(argc, argv); \\\n+\tmingw_startup(); \\\n+\treturn mingw_main(__argc, __argv); \\\n } \\\n static int mingw_main(c,v)\n \n-- \n1.9.2.msysgit.0.496.g23aa553\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":"242931","messageId":"20140529104716.GC24021@camelia.ucw.cz","threadId":"36782","inReplyTo":"20140529104329.GA24021@camelia.ucw.cz","subject":"[PATCH 2/2] mingw: avoid const warning","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-05-29T10:47:16Z","receivedAt":"2014-05-29T10:47:16Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Fix const warnings in http-fetch.c and remote-curl.c main() where is\nargv declared as const.\n\nThe fix should work for all future declarations of main, no matter\nwhether the second parameter's type is \"char**\", \"const char**\", or\n\"char *[]\".\n\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.h | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 15f0c9d..8745d19 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;\n void mingw_startup();\n #define main(c,v) dummy_decl_mingw_main(); \\\n static int mingw_main(c,v); \\\n-int main(int argc, char **argv) \\\n+int main(c, char **main_argv_not_used) \\\n { \\\n+\ttypedef v, **argv_type; \\\n \tmingw_startup(); \\\n-\treturn mingw_main(__argc, __argv); \\\n+\treturn mingw_main(__argc, (argv_type)__argv); \\\n } \\\n static int mingw_main(c,v)\n \n-- \n1.9.2.msysgit.0.496.g23aa553\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":"243495","messageId":"5391D956.7050903@gmail.com","threadId":"36782","inReplyTo":"20140529104716.GC24021@camelia.ucw.cz","subject":"Re: [PATCH 2/2] mingw: avoid const warning","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-06T15:08:06Z","receivedAt":"2014-06-06T15:08:06Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 29.05.2014 12:47, schrieb Stepan Kasal:\n> Fix const warnings in http-fetch.c and remote-curl.c main() where is\n> argv declared as const.\n> \n> The fix should work for all future declarations of main, no matter\n> whether the second parameter's type is \"char**\", \"const char**\", or\n> \"char *[]\".\n\nI'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.\n\n> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n> ---\n>  compat/mingw.h | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/compat/mingw.h b/compat/mingw.h\n> index 15f0c9d..8745d19 100644\n> --- a/compat/mingw.h\n> +++ b/compat/mingw.h\n> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;\n>  void mingw_startup();\n>  #define main(c,v) dummy_decl_mingw_main(); \\\n>  static int mingw_main(c,v); \\\n> -int main(int argc, char **argv) \\\n> +int main(c, char **main_argv_not_used) \\\n>  { \\\n> +\ttypedef v, **argv_type; \\\n>  \tmingw_startup(); \\\n> -\treturn mingw_main(__argc, __argv); \\\n> +\treturn mingw_main(__argc, (argv_type)__argv); \\\n>  } \\\n>  static int mingw_main(c,v)\n>  \n\nI have to admit I had trouble understanding what 'typedef v, **arv_type;' does (looks invalid at first glance), and why you would need main_argv_not_used instead of just main(c,v).\n\nSo, I'd like to award +10 points for cleverness, but -10 for obscurity ;-) Probably deserves a comment or an explanation in the commit message.\n\nA simpler solution that works with all definitions of main() is to cast to void* (tell the compiler all responsibility is on us). I.e.:\n\nvoid mingw_startup();\n#define main(c,v) dummy_decl_mingw_main(); \\\nstatic int mingw_main(c,v); \\\nint main(c,v) \\\n{ \\\n\tmingw_startup(); \\\n\treturn mingw_main(__argc, (void *) __argv); \\\n} \\\nstatic int mingw_main(c,v)\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":"243512","messageId":"xmqq1tv1rguh.fsf@gitster.dls.corp.google.com","threadId":"36782","inReplyTo":"5391D956.7050903@gmail.com","subject":"Re: [PATCH 2/2] mingw: avoid const warning","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-06-06T19:13:58Z","receivedAt":"2014-06-06T19:13:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Karsten Blees <karsten.blees@gmail.com> writes:\n\n> Am 29.05.2014 12:47, schrieb Stepan Kasal:\n>> Fix const warnings in http-fetch.c and remote-curl.c main() where is\n>> argv declared as const.\n>> \n>> The fix should work for all future declarations of main, no matter\n>> whether the second parameter's type is \"char**\", \"const char**\", or\n>> \"char *[]\".\n>\n> I'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.\n>\n>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n>> ---\n>>  compat/mingw.h | 5 +++--\n>>  1 file changed, 3 insertions(+), 2 deletions(-)\n>> \n>> diff --git a/compat/mingw.h b/compat/mingw.h\n>> index 15f0c9d..8745d19 100644\n>> --- a/compat/mingw.h\n>> +++ b/compat/mingw.h\n>> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;\n>>  void mingw_startup();\n>>  #define main(c,v) dummy_decl_mingw_main(); \\\n>>  static int mingw_main(c,v); \\\n>> -int main(int argc, char **argv) \\\n>> +int main(c, char **main_argv_not_used) \\\n>>  { \\\n>> +\ttypedef v, **argv_type; \\\n>>  \tmingw_startup(); \\\n>> -\treturn mingw_main(__argc, __argv); \\\n>> +\treturn mingw_main(__argc, (argv_type)__argv); \\\n>>  } \\\n>>  static int mingw_main(c,v)\n>>  \n>\n> I have to admit I had trouble understanding what 'typedef v,\n> **arv_type;' does (looks invalid at first glance), and why you\n> would need main_argv_not_used instead of just main(c,v).\n>\n> So, I'd like to award +10 points for cleverness, but -10 for\n> obscurity ;-) Probably deserves a comment or an explanation in the\n> commit message.\n\nAgreed.  The \"typedef\" one is a cute hack.\n\nI am wondering why the solution is not a more obvious \"drop const\nthat is not ANSI C\", though.  I only have a ready-access to N1570\ndraft but in it I find:\n\n    5.1.2.2.1 Program startup\n\n    The function called at program startup is named main. The\n    implementation declares no prototype for this function. It shall\n    be deﬁned with a return type of int and with no parameters:\n\n    int main(void) { /* ... */ }\n\n    or with two parameters (referred to here as argc and argv,\n    though any names may be used, as they are local to the function\n    in which they are declared):\n\n    int main(int argc, char *argv[]) { /* ... */ }\n\n    or equivalent;10) or in some other implementation-deﬁned manner.\n\n    ---\n    10) Thus, int can be replaced by a typedef name deﬁned as int,\n    or the type of argv can be written as char ** argv, and so on.\n\n> A simpler solution that works with all definitions of main() is to\n> cast to void* (tell the compiler all responsibility is on\n> us).\n\nCan you cast away the constness that way, though?\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":"243523","messageId":"53922F58.80509@gmail.com","threadId":"36782","inReplyTo":"xmqq1tv1rguh.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 2/2] mingw: avoid const warning","fromName":"Karsten Blees","fromEmail":"karsten.blees@gmail.com","sentAt":"2014-06-06T21:15:04Z","receivedAt":"2014-06-06T21:15:04Z","isPatch":true,"sender":{"key":"karsten.blees@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1111200?v=4"},"body":"Am 06.06.2014 21:13, schrieb Junio C Hamano:\n> Karsten Blees <karsten.blees@gmail.com> writes:\n> \n>> Am 29.05.2014 12:47, schrieb Stepan Kasal:\n>>> Fix const warnings in http-fetch.c and remote-curl.c main() where is\n>>> argv declared as const.\n>>>\n>>> The fix should work for all future declarations of main, no matter\n>>> whether the second parameter's type is \"char**\", \"const char**\", or\n>>> \"char *[]\".\n>>\n>> I'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.\n>>\n>>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>\n>>> ---\n>>>  compat/mingw.h | 5 +++--\n>>>  1 file changed, 3 insertions(+), 2 deletions(-)\n>>>\n>>> diff --git a/compat/mingw.h b/compat/mingw.h\n>>> index 15f0c9d..8745d19 100644\n>>> --- a/compat/mingw.h\n>>> +++ b/compat/mingw.h\n>>> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;\n>>>  void mingw_startup();\n>>>  #define main(c,v) dummy_decl_mingw_main(); \\\n>>>  static int mingw_main(c,v); \\\n>>> -int main(int argc, char **argv) \\\n>>> +int main(c, char **main_argv_not_used) \\\n>>>  { \\\n>>> +\ttypedef v, **argv_type; \\\n>>>  \tmingw_startup(); \\\n>>> -\treturn mingw_main(__argc, __argv); \\\n>>> +\treturn mingw_main(__argc, (argv_type)__argv); \\\n>>>  } \\\n>>>  static int mingw_main(c,v)\n>>>  \n>>\n>> I have to admit I had trouble understanding what 'typedef v,\n>> **arv_type;' does (looks invalid at first glance), and why you\n>> would need main_argv_not_used instead of just main(c,v).\n>>\n>> So, I'd like to award +10 points for cleverness, but -10 for\n>> obscurity ;-) Probably deserves a comment or an explanation in the\n>> commit message.\n> \n> Agreed.  The \"typedef\" one is a cute hack.\n> \n> I am wondering why the solution is not a more obvious \"drop const\n> that is not ANSI C\", though.  I only have a ready-access to N1570\n> draft but in it I find:\n> \n\nActually, that was the original solution ($gmane/247535). I just complained because it was slightly different from what we had in msysgit for quite some time [1], causing merge conflicts.\n\nI guess compilers probably won't complain if you declare argv const, even if the standard is more strict. After all, you aren't supposed to modify argv.\n\n> \n>> A simpler solution that works with all definitions of main() is to\n>> cast to void* (tell the compiler all responsibility is on\n>> us).\n> \n> Can you cast away the constness that way, though?\n> \n\nNot 'away'. This passes a non-const value to a const parameter, which is typically not a problem. Its just 'char**' to 'const char**' that produces the warning, because 'const char' hides behind a non-const pointer, see [2]. 'void*' to 'const char**' works, though.\n\n[1] https://github.com/msysgit/git/commit/6949537a\n[2] http://c-faq.com/ansi/constmismatch.html\n"},{"id":"243578","messageId":"1402123601-26312-1-git-send-email-kasal@ucw.cz","threadId":"36782","inReplyTo":"53922F58.80509@gmail.com","subject":"[PATCH v2 0/2] mingw: macro main(), const warnings","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-07T06:46:39Z","receivedAt":"2014-06-07T06:46:39Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Hi,\n\nOn Fri, Jun 06, 2014 at 11:15:04PM +0200, Karsten Blees wrote:\n> Am 06.06.2014 21:13, schrieb Junio C Hamano:\n> > I am wondering why the solution is not a more obvious \"drop const\n> > that is not ANSI C\", though.  I only have a ready-access to N1570\n> > draft but in it I find:\n> >\n>\n> Actually, that was the original solution ($gmane/247535).\n\n> > Karsten Blees <karsten.blees@gmail.com> writes:\n> >> A simpler solution that works with all definitions of main() is to\n> >> cast to void* (tell the compiler all responsibility is on\n> >> us).\n\nIndeed, verified.  Re-submitting.\nCheers,\n\tStepan\n\nKarsten Blees (1):\n  Win32: move main macro to a function\n\nStepan Kasal (1):\n  mingw: avoid const warning\n\n compat/mingw.c | 15 +++++++++++++++\n compat/mingw.h | 14 ++++----------\n 2 files changed, 19 insertions(+), 10 deletions(-)\n\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":"243579","messageId":"1402123601-26312-2-git-send-email-kasal@ucw.cz","threadId":"36782","inReplyTo":"1402123601-26312-1-git-send-email-kasal@ucw.cz","subject":"[PATCH v2 1/2] Win32: move main macro to a function","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-07T06:46:40Z","receivedAt":"2014-06-07T06:46:40Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"From: Karsten Blees <blees@dcon.de>\nDate: Fri, 7 Jan 2011 19:47:23 +0100\n\nThe code in the MinGW main macro is getting more and more complex, move to\na separate initialization function for readabiliy and extensibility.\n\nSigned-off-by: Karsten Blees <blees@dcon.de>\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.c | 15 +++++++++++++++\n compat/mingw.h | 14 ++++----------\n 2 files changed, 19 insertions(+), 10 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex a0e13bc..c03bafa 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)\n \n \treturn offset + is_dir_sep(path[offset]);\n }\n+\n+void mingw_startup()\n+{\n+\t/* copy executable name to argv[0] */\n+\t__argv[0] = xstrdup(_pgmptr);\n+\n+\t/* initialize critical section for waitpid pinfo_t list */\n+\tInitializeCriticalSection(&pinfo_cs);\n+\n+\t/* set up default file mode and file modes for stdin/out/err */\n+\t_fmode = _O_BINARY;\n+\t_setmode(_fileno(stdin), _O_BINARY);\n+\t_setmode(_fileno(stdout), _O_BINARY);\n+\t_setmode(_fileno(stderr), _O_BINARY);\n+}\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 3eaf822..15f0c9d 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -363,22 +363,16 @@ void free_environ(char **env);\n extern CRITICAL_SECTION pinfo_cs;\n \n /*\n- * A replacement of main() that ensures that argv[0] has a path\n- * and that default fmode and std(in|out|err) are in binary mode\n+ * A replacement of main() that adds win32 specific initialization.\n  */\n \n+void mingw_startup();\n #define main(c,v) dummy_decl_mingw_main(); \\\n static int mingw_main(c,v); \\\n int main(int argc, char **argv) \\\n { \\\n-\textern CRITICAL_SECTION pinfo_cs; \\\n-\t_fmode = _O_BINARY; \\\n-\t_setmode(_fileno(stdin), _O_BINARY); \\\n-\t_setmode(_fileno(stdout), _O_BINARY); \\\n-\t_setmode(_fileno(stderr), _O_BINARY); \\\n-\targv[0] = xstrdup(_pgmptr); \\\n-\tInitializeCriticalSection(&pinfo_cs); \\\n-\treturn mingw_main(argc, argv); \\\n+\tmingw_startup(); \\\n+\treturn mingw_main(__argc, __argv); \\\n } \\\n static int mingw_main(c,v)\n \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":"243580","messageId":"1402123601-26312-3-git-send-email-kasal@ucw.cz","threadId":"36782","inReplyTo":"1402123601-26312-1-git-send-email-kasal@ucw.cz","subject":"[PATCH v2 2/2] mingw: avoid const warning","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-06-07T06:46:41Z","receivedAt":"2014-06-07T06:46:41Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Fix const warnings in http-fetch.c and remote-curl.c main() where is\nargv declared as const.\n\nThe fix should work for all future declarations of main, no matter\nwhether the second parameter's type is \"char**\", \"const char**\", or\n\"char *[]\".\n\nSigned-off-by: Stepan Kasal <kasal@ucw.cz>\n---\n compat/mingw.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 15f0c9d..6dc8b1a 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -372,7 +372,7 @@ static int mingw_main(c,v); \\\n int main(int argc, char **argv) \\\n { \\\n \tmingw_startup(); \\\n-\treturn mingw_main(__argc, __argv); \\\n+\treturn mingw_main(__argc, (void *)__argv); \\\n } \\\n static int mingw_main(c,v)\n \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"}]}