0001-git-compat-util-avoid-redefining-system-function-nam.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. From 86aeac96d04ae5381085c0f93acb12d3bfd06969 Mon Sep 17 00:00:00 2001
  2. From: Jeff King <peff@peff.net>
  3. Date: Wed, 30 Nov 2022 16:15:14 -0500
  4. Subject: [PATCH] git-compat-util: avoid redefining system function names
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Our git-compat-util header defines a few noop wrappers for system
  9. functions if they are not available. This was originally done with a
  10. macro, but in 15b52a44e0 (compat-util: type-check parameters of no-op
  11. replacement functions, 2020-08-06) we switched to inline functions,
  12. because it gives us basic type-checking.
  13. This can cause compilation failures when the system _does_ declare those
  14. functions but we choose not to use them, since the compiler will
  15. complain about the redeclaration. This was seen in the real world when
  16. compiling against certain builds of uclibc, which may leave
  17. _POSIX_THREAD_SAFE_FUNCTIONS unset, but still declare flockfile() and
  18. funlockfile().
  19. It can also be seen on any platform that has setitimer() if you choose
  20. to compile without it (which plausibly could happen if the system
  21. implementation is buggy). E.g., on Linux:
  22. $ make NO_SETITIMER=IWouldPreferNotTo git.o
  23. CC git.o
  24. In file included from builtin.h:4,
  25. from git.c:1:
  26. git-compat-util.h:344:19: error: conflicting types for ‘setitimer’; have ‘int(int, const struct itimerval *, struct itimerval *)’
  27. 344 | static inline int setitimer(int which UNUSED,
  28. | ^~~~~~~~~
  29. In file included from git-compat-util.h:234:
  30. /usr/include/x86_64-linux-gnu/sys/time.h:155:12: note: previous declaration of ‘setitimer’ with type ‘int(__itimer_which_t, const struct itimerval * restrict, struct itimerval * restrict)’
  31. 155 | extern int setitimer (__itimer_which_t __which,
  32. | ^~~~~~~~~
  33. make: *** [Makefile:2714: git.o] Error 1
  34. Here I think the compiler is complaining about the lack of "restrict"
  35. annotations in our version, but even if we matched it completely (and
  36. there is no way to match all platforms anyway), it would still complain
  37. about a static declaration following a non-static one. Using macros
  38. doesn't have this problem, because the C preprocessor rewrites the name
  39. in our code before we hit this level of compilation.
  40. One way to fix this would just be to revert most of 15b52a44e0. What we
  41. really cared about there was catching build problems with
  42. precompose_argv(), which most platforms _don't_ build, and which is our
  43. custom function. So we could just switch the system wrappers back to
  44. macros; most people build the real versions anyway, and they don't
  45. change. So the extra type-checking isn't likely to catch bugs.
  46. But with a little work, we can have our cake and eat it, too. If we
  47. define the type-checking wrappers with a unique name, and then redirect
  48. the system names to them with macros, we still get our type checking,
  49. but without redeclaring the system function names.
  50. Signed-off-by: Jeff King <peff@peff.net>
  51. Signed-off-by: Junio C Hamano <gitster@pobox.com>
  52. [Bagas: cherry-picked from e0c08a4f738b3dea7a4e8fe3511c323cf1f41942 on next branch]
  53. Signed-off-by: Bagas Sanjaya <bagasdotme@gmail.com>
  54. ---
  55. git-compat-util.h | 13 ++++++++-----
  56. 1 file changed, 8 insertions(+), 5 deletions(-)
  57. diff --git a/git-compat-util.h b/git-compat-util.h
  58. index af05077560..f6882b9b50 100644
  59. --- a/git-compat-util.h
  60. +++ b/git-compat-util.h
  61. @@ -341,11 +341,12 @@ struct itimerval {
  62. #endif
  63. #ifdef NO_SETITIMER
  64. -static inline int setitimer(int which UNUSED,
  65. - const struct itimerval *value UNUSED,
  66. - struct itimerval *newvalue UNUSED) {
  67. +static inline int git_setitimer(int which,
  68. + const struct itimerval *value,
  69. + struct itimerval *newvalue) {
  70. return 0; /* pretend success */
  71. }
  72. +#define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue)
  73. #endif
  74. #ifndef NO_LIBGEN_H
  75. @@ -1479,14 +1480,16 @@ int open_nofollow(const char *path, int flags);
  76. #endif
  77. #ifndef _POSIX_THREAD_SAFE_FUNCTIONS
  78. -static inline void flockfile(FILE *fh UNUSED)
  79. +static inline void git_flockfile(FILE *fh)
  80. {
  81. ; /* nothing */
  82. }
  83. -static inline void funlockfile(FILE *fh UNUSED)
  84. +static inline void git_funlockfile(FILE *fh)
  85. {
  86. ; /* nothing */
  87. }
  88. +#define flockfile(fh) git_flockfile(fh)
  89. +#define funlockfile(fh) git_funlockfile(fh)
  90. #define getc_unlocked(fh) getc(fh)
  91. #endif
  92. base-commit: cbf04937d5b9fcf0a76c28f69e6294e9e3ecd7e6
  93. --
  94. An old man doll... just what I always wanted! - Clara