提交 28bd70d8 编写于 作者: J Jonathan Nieder 提交者: Junio C Hamano

unbreak and eliminate NO_C99_FORMAT

In the spirit of v1.5.0.2~21 (Check for PRIuMAX rather than
NO_C99_FORMAT in fast-import.c, 2007-02-20), use PRIuMAX from
git-compat-util.h on all platforms instead of C99-specific formats
like %zu with dangerous fallbacks to %u or %lu.

So now C99-challenged platforms can build git without provoking
warnings or errors from printf, even if pointers do not have the same
size as an int or long.

The need for a fallback PRIuMAX is detected in git-compat-util.h with
"#ifndef PRIuMAX".  So while at it, simplify the Makefile and configure
script by eliminating the NO_C99_FORMAT knob altogether.
Signed-off-by: NJonathan Nieder <jrnieder@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 31d713d0
...@@ -45,11 +45,6 @@ all:: ...@@ -45,11 +45,6 @@ all::
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks # Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7). # d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
# #
# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
# do not support the 'size specifiers' introduced by C99, namely ll, hh,
# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
# some C compilers supported these specifiers prior to C99 as an extension.
#
# Define NO_STRCASESTR if you don't have strcasestr. # Define NO_STRCASESTR if you don't have strcasestr.
# #
# Define NO_MEMMEM if you don't have memmem. # Define NO_MEMMEM if you don't have memmem.
...@@ -870,7 +865,6 @@ ifeq ($(uname_S),SunOS) ...@@ -870,7 +865,6 @@ ifeq ($(uname_S),SunOS)
NO_UNSETENV = YesPlease NO_UNSETENV = YesPlease
NO_SETENV = YesPlease NO_SETENV = YesPlease
NO_STRLCPY = YesPlease NO_STRLCPY = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
GIT_TEST_CMP = cmp GIT_TEST_CMP = cmp
endif endif
...@@ -881,21 +875,18 @@ ifeq ($(uname_S),SunOS) ...@@ -881,21 +875,18 @@ ifeq ($(uname_S),SunOS)
NO_UNSETENV = YesPlease NO_UNSETENV = YesPlease
NO_SETENV = YesPlease NO_SETENV = YesPlease
NO_STRLCPY = YesPlease NO_STRLCPY = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
GIT_TEST_CMP = cmp GIT_TEST_CMP = cmp
endif endif
ifeq ($(uname_R),5.8) ifeq ($(uname_R),5.8)
NO_UNSETENV = YesPlease NO_UNSETENV = YesPlease
NO_SETENV = YesPlease NO_SETENV = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
GIT_TEST_CMP = cmp GIT_TEST_CMP = cmp
endif endif
ifeq ($(uname_R),5.9) ifeq ($(uname_R),5.9)
NO_UNSETENV = YesPlease NO_UNSETENV = YesPlease
NO_SETENV = YesPlease NO_SETENV = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
GIT_TEST_CMP = cmp GIT_TEST_CMP = cmp
endif endif
...@@ -1074,7 +1065,6 @@ ifeq ($(uname_S),Windows) ...@@ -1074,7 +1065,6 @@ ifeq ($(uname_S),Windows)
NO_MEMMEM = YesPlease NO_MEMMEM = YesPlease
# NEEDS_LIBICONV = YesPlease # NEEDS_LIBICONV = YesPlease
NO_ICONV = YesPlease NO_ICONV = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
NO_STRTOULL = YesPlease NO_STRTOULL = YesPlease
NO_MKDTEMP = YesPlease NO_MKDTEMP = YesPlease
...@@ -1151,7 +1141,6 @@ ifneq (,$(findstring MINGW,$(uname_S))) ...@@ -1151,7 +1141,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
NO_MEMMEM = YesPlease NO_MEMMEM = YesPlease
NEEDS_LIBICONV = YesPlease NEEDS_LIBICONV = YesPlease
OLD_ICONV = YesPlease OLD_ICONV = YesPlease
NO_C99_FORMAT = YesPlease
NO_STRTOUMAX = YesPlease NO_STRTOUMAX = YesPlease
NO_MKDTEMP = YesPlease NO_MKDTEMP = YesPlease
NO_MKSTEMPS = YesPlease NO_MKSTEMPS = YesPlease
...@@ -1354,9 +1343,6 @@ endif ...@@ -1354,9 +1343,6 @@ endif
ifdef NO_NSEC ifdef NO_NSEC
BASIC_CFLAGS += -DNO_NSEC BASIC_CFLAGS += -DNO_NSEC
endif endif
ifdef NO_C99_FORMAT
BASIC_CFLAGS += -DNO_C99_FORMAT
endif
ifdef SNPRINTF_RETURNS_BOGUS ifdef SNPRINTF_RETURNS_BOGUS
COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
COMPAT_OBJS += compat/snprintf.o COMPAT_OBJS += compat/snprintf.o
......
...@@ -51,19 +51,12 @@ DEFINE_ALLOCATOR(commit, struct commit) ...@@ -51,19 +51,12 @@ DEFINE_ALLOCATOR(commit, struct commit)
DEFINE_ALLOCATOR(tag, struct tag) DEFINE_ALLOCATOR(tag, struct tag)
DEFINE_ALLOCATOR(object, union any_object) DEFINE_ALLOCATOR(object, union any_object)
#ifdef NO_C99_FORMAT
#define SZ_FMT "%u"
#else
#define SZ_FMT "%zu"
#endif
static void report(const char *name, unsigned int count, size_t size) static void report(const char *name, unsigned int count, size_t size)
{ {
fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size); fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
name, count, (uintmax_t) size);
} }
#undef SZ_FMT
#define REPORT(name) \ #define REPORT(name) \
report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10) report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
......
...@@ -43,7 +43,6 @@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@ ...@@ -43,7 +43,6 @@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@ NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@
NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@ NO_SOCKADDR_STORAGE=@NO_SOCKADDR_STORAGE@
NO_IPV6=@NO_IPV6@ NO_IPV6=@NO_IPV6@
NO_C99_FORMAT=@NO_C99_FORMAT@
NO_HSTRERROR=@NO_HSTRERROR@ NO_HSTRERROR=@NO_HSTRERROR@
NO_STRCASESTR=@NO_STRCASESTR@ NO_STRCASESTR=@NO_STRCASESTR@
NO_STRTOK_R=@NO_STRTOK_R@ NO_STRTOK_R=@NO_STRTOK_R@
......
...@@ -686,30 +686,6 @@ AC_CHECK_TYPE([struct addrinfo],[ ...@@ -686,30 +686,6 @@ AC_CHECK_TYPE([struct addrinfo],[
]) ])
AC_SUBST(NO_IPV6) AC_SUBST(NO_IPV6)
# #
# Define NO_C99_FORMAT if your formatted IO functions (printf/scanf et.al.)
# do not support the 'size specifiers' introduced by C99, namely ll, hh,
# j, z, t. (representing long long int, char, intmax_t, size_t, ptrdiff_t).
# some C compilers supported these specifiers prior to C99 as an extension.
AC_CACHE_CHECK([whether formatted IO functions support C99 size specifiers],
[ac_cv_c_c99_format],
[# Actually git uses only %z (%zu) in alloc.c, and %t (%td) in mktag.c
AC_RUN_IFELSE(
[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
[[char buf[64];
if (sprintf(buf, "%lld%hhd%jd%zd%td", (long long int)1, (char)2, (intmax_t)3, (size_t)4, (ptrdiff_t)5) != 5)
return 1;
else if (strcmp(buf, "12345"))
return 2;]])],
[ac_cv_c_c99_format=yes],
[ac_cv_c_c99_format=no])
])
if test $ac_cv_c_c99_format = no; then
NO_C99_FORMAT=YesPlease
else
NO_C99_FORMAT=
fi
AC_SUBST(NO_C99_FORMAT)
#
# Define NO_REGEX if you have no or inferior regex support in your C library. # Define NO_REGEX if you have no or inferior regex support in your C library.
AC_CACHE_CHECK([whether the platform regex can handle null bytes], AC_CACHE_CHECK([whether the platform regex can handle null bytes],
[ac_cv_c_excellent_regex], [ [ac_cv_c_excellent_regex], [
......
...@@ -25,13 +25,8 @@ ...@@ -25,13 +25,8 @@
#endif #endif
#endif #endif
#ifdef NO_C99_FORMAT #define SZ_FMT PRIuMAX
#define SZ_FMT "lu" static inline uintmax_t sz_fmt(size_t s) { return s; }
static unsigned long sz_fmt(size_t s) { return (unsigned long)s; }
#else
#define SZ_FMT "zu"
static size_t sz_fmt(size_t s) { return s; }
#endif
const unsigned char null_sha1[20]; const unsigned char null_sha1[20];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册