threads / patch / 41864

patch, 2 partsMSVC: VS2013 comes with inttypes.h

Subject: [PATCH 2/2] MSVC: VS2013 comes with inttypes.h

## tl;dr

9 messages between Mar 29, 2016 and Mar 30, 2016. Diffs are folded; open one to read it.

replies: 8people: 4as markdown or json

Sven Strickroth· Mar 29, 2016, 16:27 UTC · lore
Reduce the number of defines which need to be managed within vanilal git.
Signed-off-by: Sven Strickroth <sven@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
Show changes to 2 files +3 −1

compat/mingw.h, compat/vcbuild/include/unistd.h

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..5d7f0dd 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) || !defined(_MSC_VER) || _MSC_VER < 1800
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b4b7b7c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,13 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1800
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1
Junio C Hamano· Mar 29, 2016, 16:47 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2] MSVC: VS2013 comes with inttypes.h

Sven Strickroth <sven@cs-ware.de> writes:
> Reduce the number of defines which need to be managed within vanilal git.
Hmph.
>
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>
> ---

I am not qualified to judge the correctness of the assertions this change makes:

 * MSVC at or newer than version 1800 have PRIuMAX and PRId64
 * MSVC at or newer than version 1800 have {UINT,INT}MAX_{MIN,MAX}
and will wait for Windows folks to Ack.
Thanks.
Show 35 quoted lines
>  compat/mingw.h                  | 2 +-
>  compat/vcbuild/include/unistd.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..5d7f0dd 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) || !defined(_MSC_VER) || _MSC_VER < 1800
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else
> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b4b7b7c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,13 @@ typedef unsigned long long uintmax_t;
>  
>  typedef int64_t off64_t;
>  
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>  #define INTMAX_MIN  _I64_MIN
>  #define INTMAX_MAX  _I64_MAX
>  #define UINTMAX_MAX _UI64_MAX
>  
>  #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#endif
>  
>  #define STDIN_FILENO  0
>  #define STDOUT_FILENO 1
Sven Strickroth· Mar 29, 2016, 17:23 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h

Signed-off-by: Sven Strickroth <email@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
Show changes to 2 files +5 −1

compat/mingw.h, compat/vcbuild/include/unistd.h

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..137f42e 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b7cc48c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1800
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include<inttypes.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1
Junio C Hamano· Mar 29, 2016, 17:35 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h

Sven Strickroth <sven@cs-ware.de> writes:
> Signed-off-by: Sven Strickroth <email@cs-ware.de>
> ---

Ah, I didn't finish the comment I started to write here for the first round. My "Hmph" was meant to be followed by something like "Compared to 1/2 which clearly described what got changed, this does not say much to summarize what it did to help readers".

Re-reading the patch text, I tend to agree with you that the title "comes with inttypes.h" may be sufficient for readers to reason about the change, and it would not be necessary to explain that we can lose fallback definitions by including it.

Show 33 quoted lines
>  compat/mingw.h                  | 2 +-
>  compat/vcbuild/include/unistd.h | 4 ++++
>  2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..137f42e 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else
> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b7cc48c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
>  
>  typedef int64_t off64_t;
>  
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>  #define INTMAX_MIN  _I64_MIN
>  #define INTMAX_MAX  _I64_MAX
>  #define UINTMAX_MAX _UI64_MAX
>  
>  #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#else
> +#include<inttypes.h>
Somebody lost a SP here, it seems.
> +#endif
>  
>  #define STDIN_FILENO  0
>  #define STDOUT_FILENO 1
Sebastian Schuberth· Mar 30, 2016, 08:52 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V2] MSVC: VS2013 comes with inttypes.h

On 3/29/2016 19:23, Sven Strickroth wrote:
Show 11 quoted lines
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>   extern void build_libgit_environment(void);
>   extern const char *program_data_config(void);
>   #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>   #define PRIuMAX "I64u"
>   #define PRId64 "I64d"
>   #else
ACK for this part. For reference see [1].
Show 17 quoted lines
> diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
> index c65c2cd..b7cc48c 100644
> --- a/compat/vcbuild/include/unistd.h
> +++ b/compat/vcbuild/include/unistd.h
> @@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
>   
>   typedef int64_t off64_t;
>   
> +#if !defined(_MSC_VER) || _MSC_VER < 1800
>   #define INTMAX_MIN  _I64_MIN
>   #define INTMAX_MAX  _I64_MAX
>   #define UINTMAX_MAX _UI64_MAX
>   
>   #define UINT32_MAX 0xffffffff  /* 4294967295U */
> +#else
> +#include<inttypes.h>
> +#endif
If we would do "#include <stdint.h>" here instead, we could lower the _MSC_VER requirement to at least 1700. According to the comment at [2] we could lower it even to 1600.
Also the original code is missing a single space after "#include".

[1] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/ [2] https://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio#comment4620359_126279

Regards, Sebastian

Sven Strickroth· Mar 30, 2016, 11:37 UTC · re: Sebastian Schuberth · lore

Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions

VS2010 comes with stdint.h [1] VS2013 comes with inttypes.h [2]

[1] https://stackoverflow.com/a/2628014/3906760 [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/

Signed-off-by: Sven Strickroth <sven@cs-ware.de>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
Show changes to 2 files +5 −1

compat/mingw.h, compat/vcbuild/include/unistd.h

diff --git a/compat/mingw.h b/compat/mingw.h
index 6b6d695..137f42e 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
 extern void build_libgit_environment(void);
 extern const char *program_data_config(void);
 #define git_program_data_config program_data_config
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..b7cc48c 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1600
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include <stdint.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.7.4.windows.1
Sebastian Schuberth· Mar 30, 2016, 11:40 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions

On 3/30/2016 13:37, Sven Strickroth wrote:
Show 7 quoted lines
> VS2010 comes with stdint.h [1]
> VS2013 comes with inttypes.h [2]
>
> [1] https://stackoverflow.com/a/2628014/3906760
> [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
>
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>
ACK.

Regards, Sebastian

Johannes Schindelin· Mar 30, 2016, 11:42 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions

Hi Sven,
On Wed, 30 Mar 2016, Sven Strickroth wrote:
Show 7 quoted lines
> VS2010 comes with stdint.h [1]
> VS2013 comes with inttypes.h [2]
> 
> [1] https://stackoverflow.com/a/2628014/3906760
> [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
> 
> Signed-off-by: Sven Strickroth <sven@cs-ware.de>

Much, much, much better commit message (even if there is still room for a more pleasant read).

ACK Dscho

Junio C Hamano· Mar 30, 2016, 18:19 UTC · re: Sven Strickroth · lore

Re: [PATCH 2/2 V3] MSVC: Use shipped headers instead of fallback definitions

Sven Strickroth <sven@cs-ware.de> writes:
Show 13 quoted lines
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 6b6d695..137f42e 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> @@ -415,7 +415,7 @@ int mingw_offset_1st_component(const char *path);
>  extern void build_libgit_environment(void);
>  extern const char *program_data_config(void);
>  #define git_program_data_config program_data_config
> -#ifndef __MINGW64_VERSION_MAJOR
> +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
>  #define PRIuMAX "I64u"
>  #define PRId64 "I64d"
>  #else

I'll wiggle this in, but you seem to be building on top of some unrelated work (please avoid sending such a patch in the future).

Thanks, all of you.
-- >8 --
From: Sven Strickroth <sven@cs-ware.de>
Date: Wed, 30 Mar 2016 13:37:36 +0200
Subject: [PATCH] MSVC: use shipped headers instead of fallback definitions

VS2010 comes with stdint.h [1] VS2013 comes with inttypes.h [2]

[1] https://stackoverflow.com/a/2628014/3906760 [2] https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/

Signed-off-by: Sven Strickroth <sven@cs-ware.de>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 compat/mingw.h                  | 2 +-
 compat/vcbuild/include/unistd.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
Show changes to 2 files +5 −1

compat/mingw.h, compat/vcbuild/include/unistd.h

diff --git a/compat/mingw.h b/compat/mingw.h
index c008694..1de70ff 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -406,7 +406,7 @@ static inline void convert_slashes(char *path)
 int mingw_offset_1st_component(const char *path);
 #define offset_1st_component mingw_offset_1st_component
 #define PATH_SEP ';'
-#ifndef __MINGW64_VERSION_MAJOR
+#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800)
 #define PRIuMAX "I64u"
 #define PRId64 "I64d"
 #else
diff --git a/compat/vcbuild/include/unistd.h b/compat/vcbuild/include/unistd.h
index c65c2cd..3a959d1 100644
--- a/compat/vcbuild/include/unistd.h
+++ b/compat/vcbuild/include/unistd.h
@@ -45,11 +45,15 @@ typedef unsigned long long uintmax_t;
 
 typedef int64_t off64_t;
 
+#if !defined(_MSC_VER) || _MSC_VER < 1600
 #define INTMAX_MIN  _I64_MIN
 #define INTMAX_MAX  _I64_MAX
 #define UINTMAX_MAX _UI64_MAX
 
 #define UINT32_MAX 0xffffffff  /* 4294967295U */
+#else
+#include <stdint.h>
+#endif
 
 #define STDIN_FILENO  0
 #define STDOUT_FILENO 1
-- 
2.8.0-215-gd29a7d9

← back to recent threads