git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] mingw: macro main(), const warnings
@ 2014-05-29 10:43 Stepan Kasal
  2014-05-29 10:45 ` [PATCH 1/2] Win32: move main macro to a function Stepan Kasal
  2014-05-29 10:47 ` [PATCH 2/2] mingw: avoid const warning Stepan Kasal
  0 siblings, 2 replies; 9+ messages in thread
From: Stepan Kasal @ 2014-05-29 10:43 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: Erik Faye-Lund, msysgit, Karsten Blees

Hello,

mingw.h defines a preprocessor macro main(), so that it can wrap the
original function and hoook into initialization.

The real main() function can have different types of its second
parameter (char**, const char**, char*[]).  It is not easy to match
the type and gcc issues a const warning.  My patch fixes that.

There were solutions for the same issue published ([1], [2]), but
none of them appeared in junio/pu.  This new solution should be more
future proof, as it modifies only compat/mingw.h; the *.c files can
have any of the types mentioned above.

I promise to take care of the integration into msysGit if this patch
gets accepted.  To make it easier, I'm submitting a patch that has
been part of msysGit for 3 years.

Karsten Blees (1):
  Win32: move main macro to a function

Stepan Kasal (1):
  mingw: avoid const warning

 compat/mingw.c | 15 +++++++++++++++
 compat/mingw.h | 17 ++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)

-- 
1.9.2.msysgit.0.496.g23aa553

[1] a hack to fix the warning, by Pat Thoyts, in msysGit since
1.8.5.2.msysgit.0 (Dec 2013):
https://github.com/msysgit/git/commit/6949537a

[2] more elgant fix:
From: Marat Radchenko <marat@slonopotamus.org>
Date: Tue, 29 Apr 2014 13:12:02 +0400
http://article.gmane.org/gmane.comp.version-control.git/247535

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] Win32: move main macro to a function
  2014-05-29 10:43 [PATCH 0/2] mingw: macro main(), const warnings Stepan Kasal
@ 2014-05-29 10:45 ` Stepan Kasal
  2014-05-29 10:47 ` [PATCH 2/2] mingw: avoid const warning Stepan Kasal
  1 sibling, 0 replies; 9+ messages in thread
From: Stepan Kasal @ 2014-05-29 10:45 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: Erik Faye-Lund, msysgit, Karsten Blees

From: Karsten Blees <blees@dcon.de>
Date: Fri, 7 Jan 2011 19:47:23 +0100

The code in the MinGW main macro is getting more and more complex, move to
a separate initialization function for readabiliy and extensibility.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 15 +++++++++++++++
 compat/mingw.h | 14 ++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..c03bafa 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)
 
 	return offset + is_dir_sep(path[offset]);
 }
+
+void mingw_startup()
+{
+	/* copy executable name to argv[0] */
+	__argv[0] = xstrdup(_pgmptr);
+
+	/* initialize critical section for waitpid pinfo_t list */
+	InitializeCriticalSection(&pinfo_cs);
+
+	/* set up default file mode and file modes for stdin/out/err */
+	_fmode = _O_BINARY;
+	_setmode(_fileno(stdin), _O_BINARY);
+	_setmode(_fileno(stdout), _O_BINARY);
+	_setmode(_fileno(stderr), _O_BINARY);
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 3eaf822..15f0c9d 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -363,22 +363,16 @@ void free_environ(char **env);
 extern CRITICAL_SECTION pinfo_cs;
 
 /*
- * A replacement of main() that ensures that argv[0] has a path
- * and that default fmode and std(in|out|err) are in binary mode
+ * A replacement of main() that adds win32 specific initialization.
  */
 
+void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
 static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
-	extern CRITICAL_SECTION pinfo_cs; \
-	_fmode = _O_BINARY; \
-	_setmode(_fileno(stdin), _O_BINARY); \
-	_setmode(_fileno(stdout), _O_BINARY); \
-	_setmode(_fileno(stderr), _O_BINARY); \
-	argv[0] = xstrdup(_pgmptr); \
-	InitializeCriticalSection(&pinfo_cs); \
-	return mingw_main(argc, argv); \
+	mingw_startup(); \
+	return mingw_main(__argc, __argv); \
 } \
 static int mingw_main(c,v)
 
-- 
1.9.2.msysgit.0.496.g23aa553

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] mingw: avoid const warning
  2014-05-29 10:43 [PATCH 0/2] mingw: macro main(), const warnings Stepan Kasal
  2014-05-29 10:45 ` [PATCH 1/2] Win32: move main macro to a function Stepan Kasal
@ 2014-05-29 10:47 ` Stepan Kasal
  2014-06-06 15:08   ` Karsten Blees
  1 sibling, 1 reply; 9+ messages in thread
From: Stepan Kasal @ 2014-05-29 10:47 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: Erik Faye-Lund, msysgit, Karsten Blees

Fix const warnings in http-fetch.c and remote-curl.c main() where is
argv declared as const.

The fix should work for all future declarations of main, no matter
whether the second parameter's type is "char**", "const char**", or
"char *[]".

Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 15f0c9d..8745d19 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;
 void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
 static int mingw_main(c,v); \
-int main(int argc, char **argv) \
+int main(c, char **main_argv_not_used) \
 { \
+	typedef v, **argv_type; \
 	mingw_startup(); \
-	return mingw_main(__argc, __argv); \
+	return mingw_main(__argc, (argv_type)__argv); \
 } \
 static int mingw_main(c,v)
 
-- 
1.9.2.msysgit.0.496.g23aa553

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mingw: avoid const warning
  2014-05-29 10:47 ` [PATCH 2/2] mingw: avoid const warning Stepan Kasal
@ 2014-06-06 15:08   ` Karsten Blees
  2014-06-06 19:13     ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Karsten Blees @ 2014-06-06 15:08 UTC (permalink / raw
  To: Stepan Kasal, GIT Mailing-list; +Cc: Erik Faye-Lund, msysgit

Am 29.05.2014 12:47, schrieb Stepan Kasal:
> Fix const warnings in http-fetch.c and remote-curl.c main() where is
> argv declared as const.
> 
> The fix should work for all future declarations of main, no matter
> whether the second parameter's type is "char**", "const char**", or
> "char *[]".

I'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.

> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
> ---
>  compat/mingw.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 15f0c9d..8745d19 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;
>  void mingw_startup();
>  #define main(c,v) dummy_decl_mingw_main(); \
>  static int mingw_main(c,v); \
> -int main(int argc, char **argv) \
> +int main(c, char **main_argv_not_used) \
>  { \
> +	typedef v, **argv_type; \
>  	mingw_startup(); \
> -	return mingw_main(__argc, __argv); \
> +	return mingw_main(__argc, (argv_type)__argv); \
>  } \
>  static int mingw_main(c,v)
>  

I 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).

So, I'd like to award +10 points for cleverness, but -10 for obscurity ;-) Probably deserves a comment or an explanation in the commit message.

A simpler solution that works with all definitions of main() is to cast to void* (tell the compiler all responsibility is on us). I.e.:

void mingw_startup();
#define main(c,v) dummy_decl_mingw_main(); \
static int mingw_main(c,v); \
int main(c,v) \
{ \
	mingw_startup(); \
	return mingw_main(__argc, (void *) __argv); \
} \
static int mingw_main(c,v)

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mingw: avoid const warning
  2014-06-06 15:08   ` Karsten Blees
@ 2014-06-06 19:13     ` Junio C Hamano
  2014-06-06 21:15       ` Karsten Blees
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2014-06-06 19:13 UTC (permalink / raw
  To: Karsten Blees; +Cc: Stepan Kasal, GIT Mailing-list, Erik Faye-Lund, msysgit

Karsten Blees <karsten.blees@gmail.com> writes:

> Am 29.05.2014 12:47, schrieb Stepan Kasal:
>> Fix const warnings in http-fetch.c and remote-curl.c main() where is
>> argv declared as const.
>> 
>> The fix should work for all future declarations of main, no matter
>> whether the second parameter's type is "char**", "const char**", or
>> "char *[]".
>
> I'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.
>
>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
>> ---
>>  compat/mingw.h | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>> 
>> diff --git a/compat/mingw.h b/compat/mingw.h
>> index 15f0c9d..8745d19 100644
>> --- a/compat/mingw.h
>> +++ b/compat/mingw.h
>> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;
>>  void mingw_startup();
>>  #define main(c,v) dummy_decl_mingw_main(); \
>>  static int mingw_main(c,v); \
>> -int main(int argc, char **argv) \
>> +int main(c, char **main_argv_not_used) \
>>  { \
>> +	typedef v, **argv_type; \
>>  	mingw_startup(); \
>> -	return mingw_main(__argc, __argv); \
>> +	return mingw_main(__argc, (argv_type)__argv); \
>>  } \
>>  static int mingw_main(c,v)
>>  
>
> I 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).
>
> So, I'd like to award +10 points for cleverness, but -10 for
> obscurity ;-) Probably deserves a comment or an explanation in the
> commit message.

Agreed.  The "typedef" one is a cute hack.

I am wondering why the solution is not a more obvious "drop const
that is not ANSI C", though.  I only have a ready-access to N1570
draft but in it I find:

    5.1.2.2.1 Program startup

    The function called at program startup is named main. The
    implementation declares no prototype for this function. It shall
    be defined with a return type of int and with no parameters:

    int main(void) { /* ... */ }

    or with two parameters (referred to here as argc and argv,
    though any names may be used, as they are local to the function
    in which they are declared):

    int main(int argc, char *argv[]) { /* ... */ }

    or equivalent;10) or in some other implementation-defined manner.

    ---
    10) Thus, int can be replaced by a typedef name defined as int,
    or the type of argv can be written as char ** argv, and so on.

> A simpler solution that works with all definitions of main() is to
> cast to void* (tell the compiler all responsibility is on
> us).

Can you cast away the constness that way, though?

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] mingw: avoid const warning
  2014-06-06 19:13     ` Junio C Hamano
@ 2014-06-06 21:15       ` Karsten Blees
  2014-06-07  6:46         ` [PATCH v2 0/2] mingw: macro main(), const warnings Stepan Kasal
  0 siblings, 1 reply; 9+ messages in thread
From: Karsten Blees @ 2014-06-06 21:15 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Stepan Kasal, GIT Mailing-list, Erik Faye-Lund, msysgit

Am 06.06.2014 21:13, schrieb Junio C Hamano:
> Karsten Blees <karsten.blees@gmail.com> writes:
> 
>> Am 29.05.2014 12:47, schrieb Stepan Kasal:
>>> Fix const warnings in http-fetch.c and remote-curl.c main() where is
>>> argv declared as const.
>>>
>>> The fix should work for all future declarations of main, no matter
>>> whether the second parameter's type is "char**", "const char**", or
>>> "char *[]".
>>
>> I'm 100% in favor of a solution that doesn't restrict main to non-const char**! Thanks.
>>
>>> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
>>> ---
>>>  compat/mingw.h | 5 +++--
>>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/compat/mingw.h b/compat/mingw.h
>>> index 15f0c9d..8745d19 100644
>>> --- a/compat/mingw.h
>>> +++ b/compat/mingw.h
>>> @@ -369,10 +369,11 @@ extern CRITICAL_SECTION pinfo_cs;
>>>  void mingw_startup();
>>>  #define main(c,v) dummy_decl_mingw_main(); \
>>>  static int mingw_main(c,v); \
>>> -int main(int argc, char **argv) \
>>> +int main(c, char **main_argv_not_used) \
>>>  { \
>>> +	typedef v, **argv_type; \
>>>  	mingw_startup(); \
>>> -	return mingw_main(__argc, __argv); \
>>> +	return mingw_main(__argc, (argv_type)__argv); \
>>>  } \
>>>  static int mingw_main(c,v)
>>>  
>>
>> I 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).
>>
>> So, I'd like to award +10 points for cleverness, but -10 for
>> obscurity ;-) Probably deserves a comment or an explanation in the
>> commit message.
> 
> Agreed.  The "typedef" one is a cute hack.
> 
> I am wondering why the solution is not a more obvious "drop const
> that is not ANSI C", though.  I only have a ready-access to N1570
> draft but in it I find:
> 

Actually, 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.

I 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.

> 
>> A simpler solution that works with all definitions of main() is to
>> cast to void* (tell the compiler all responsibility is on
>> us).
> 
> Can you cast away the constness that way, though?
> 

Not '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.

[1] https://github.com/msysgit/git/commit/6949537a
[2] http://c-faq.com/ansi/constmismatch.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 0/2] mingw: macro main(), const warnings
  2014-06-06 21:15       ` Karsten Blees
@ 2014-06-07  6:46         ` Stepan Kasal
  2014-06-07  6:46           ` [PATCH v2 1/2] Win32: move main macro to a function Stepan Kasal
  2014-06-07  6:46           ` [PATCH v2 2/2] mingw: avoid const warning Stepan Kasal
  0 siblings, 2 replies; 9+ messages in thread
From: Stepan Kasal @ 2014-06-07  6:46 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: msysGit, Stepan Kasal

Hi,

On Fri, Jun 06, 2014 at 11:15:04PM +0200, Karsten Blees wrote:
> Am 06.06.2014 21:13, schrieb Junio C Hamano:
> > I am wondering why the solution is not a more obvious "drop const
> > that is not ANSI C", though.  I only have a ready-access to N1570
> > draft but in it I find:
> >
>
> Actually, that was the original solution ($gmane/247535).

> > Karsten Blees <karsten.blees@gmail.com> writes:
> >> A simpler solution that works with all definitions of main() is to
> >> cast to void* (tell the compiler all responsibility is on
> >> us).

Indeed, verified.  Re-submitting.
Cheers,
	Stepan

Karsten Blees (1):
  Win32: move main macro to a function

Stepan Kasal (1):
  mingw: avoid const warning

 compat/mingw.c | 15 +++++++++++++++
 compat/mingw.h | 14 ++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/2] Win32: move main macro to a function
  2014-06-07  6:46         ` [PATCH v2 0/2] mingw: macro main(), const warnings Stepan Kasal
@ 2014-06-07  6:46           ` Stepan Kasal
  2014-06-07  6:46           ` [PATCH v2 2/2] mingw: avoid const warning Stepan Kasal
  1 sibling, 0 replies; 9+ messages in thread
From: Stepan Kasal @ 2014-06-07  6:46 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: msysGit, Karsten Blees, Erik Faye-Lund, Stepan Kasal

From: Karsten Blees <blees@dcon.de>
Date: Fri, 7 Jan 2011 19:47:23 +0100

The code in the MinGW main macro is getting more and more complex, move to
a separate initialization function for readabiliy and extensibility.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 15 +++++++++++++++
 compat/mingw.h | 14 ++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index a0e13bc..c03bafa 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1847,3 +1847,18 @@ int mingw_offset_1st_component(const char *path)
 
 	return offset + is_dir_sep(path[offset]);
 }
+
+void mingw_startup()
+{
+	/* copy executable name to argv[0] */
+	__argv[0] = xstrdup(_pgmptr);
+
+	/* initialize critical section for waitpid pinfo_t list */
+	InitializeCriticalSection(&pinfo_cs);
+
+	/* set up default file mode and file modes for stdin/out/err */
+	_fmode = _O_BINARY;
+	_setmode(_fileno(stdin), _O_BINARY);
+	_setmode(_fileno(stdout), _O_BINARY);
+	_setmode(_fileno(stderr), _O_BINARY);
+}
diff --git a/compat/mingw.h b/compat/mingw.h
index 3eaf822..15f0c9d 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -363,22 +363,16 @@ void free_environ(char **env);
 extern CRITICAL_SECTION pinfo_cs;
 
 /*
- * A replacement of main() that ensures that argv[0] has a path
- * and that default fmode and std(in|out|err) are in binary mode
+ * A replacement of main() that adds win32 specific initialization.
  */
 
+void mingw_startup();
 #define main(c,v) dummy_decl_mingw_main(); \
 static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
-	extern CRITICAL_SECTION pinfo_cs; \
-	_fmode = _O_BINARY; \
-	_setmode(_fileno(stdin), _O_BINARY); \
-	_setmode(_fileno(stdout), _O_BINARY); \
-	_setmode(_fileno(stderr), _O_BINARY); \
-	argv[0] = xstrdup(_pgmptr); \
-	InitializeCriticalSection(&pinfo_cs); \
-	return mingw_main(argc, argv); \
+	mingw_startup(); \
+	return mingw_main(__argc, __argv); \
 } \
 static int mingw_main(c,v)
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/2] mingw: avoid const warning
  2014-06-07  6:46         ` [PATCH v2 0/2] mingw: macro main(), const warnings Stepan Kasal
  2014-06-07  6:46           ` [PATCH v2 1/2] Win32: move main macro to a function Stepan Kasal
@ 2014-06-07  6:46           ` Stepan Kasal
  1 sibling, 0 replies; 9+ messages in thread
From: Stepan Kasal @ 2014-06-07  6:46 UTC (permalink / raw
  To: GIT Mailing-list; +Cc: msysGit, Stepan Kasal

Fix const warnings in http-fetch.c and remote-curl.c main() where is
argv declared as const.

The fix should work for all future declarations of main, no matter
whether the second parameter's type is "char**", "const char**", or
"char *[]".

Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/mingw.h b/compat/mingw.h
index 15f0c9d..6dc8b1a 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -372,7 +372,7 @@ static int mingw_main(c,v); \
 int main(int argc, char **argv) \
 { \
 	mingw_startup(); \
-	return mingw_main(__argc, __argv); \
+	return mingw_main(__argc, (void *)__argv); \
 } \
 static int mingw_main(c,v)
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-06-07  6:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-29 10:43 [PATCH 0/2] mingw: macro main(), const warnings Stepan Kasal
2014-05-29 10:45 ` [PATCH 1/2] Win32: move main macro to a function Stepan Kasal
2014-05-29 10:47 ` [PATCH 2/2] mingw: avoid const warning Stepan Kasal
2014-06-06 15:08   ` Karsten Blees
2014-06-06 19:13     ` Junio C Hamano
2014-06-06 21:15       ` Karsten Blees
2014-06-07  6:46         ` [PATCH v2 0/2] mingw: macro main(), const warnings Stepan Kasal
2014-06-07  6:46           ` [PATCH v2 1/2] Win32: move main macro to a function Stepan Kasal
2014-06-07  6:46           ` [PATCH v2 2/2] mingw: avoid const warning Stepan Kasal

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).