From 382717d7f11ef756d4c574bf97bc1e3b0233c8e9 Mon Sep 17 00:00:00 2001 From: Evgeny Grin Date: Thu, 11 Apr 2024 23:44:38 +0200 Subject: [PATCH] curl_setup.h: detect 'inline' support Closes #13355 --- configure.ac | 3 --- lib/curl_config.h.cmake | 6 ------ lib/curl_setup.h | 22 ++++++++++++++++++++++ lib/curl_sha512_256.c | 22 +++------------------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 21a3debbdc05a8..430b7dba34e719 100644 --- a/configure.ac +++ b/configure.ac @@ -497,9 +497,6 @@ fi AC_SUBST(REQUIRE_LIB_DEPS) AM_CONDITIONAL(USE_EXPLICIT_LIB_DEPS, test x$REQUIRE_LIB_DEPS = xyes) -dnl check if there's a way to force code inline -AC_C_INLINE - dnl ********************************************************************** dnl platform/compiler/architecture specific checks/flags dnl ********************************************************************** diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 5d394675d24663..3a46c64902021b 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -776,12 +776,6 @@ ${SIZEOF_TIME_T_CODE} /* Type to use in place of in_addr_t when system does not provide it. */ #cmakedefine in_addr_t ${in_addr_t} -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#undef inline -#endif - /* Define to `unsigned int' if does not define. */ #cmakedefine size_t ${size_t} diff --git a/lib/curl_setup.h b/lib/curl_setup.h index 5dd94b3c79a0d1..a4b8ba3b6629b8 100644 --- a/lib/curl_setup.h +++ b/lib/curl_setup.h @@ -891,4 +891,26 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, #define OPENSSL_SUPPRESS_DEPRECATED #endif +#if defined(inline) + /* 'inline' is defined as macro and assumed to be correct */ + /* No need for 'inline' replacement */ +#elif defined(__cplusplus) + /* The code is compiled with C++ compiler. + C++ always supports 'inline'. */ + /* No need for 'inline' replacement */ +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 + /* C99 (and later) supports 'inline' keyword */ + /* No need for 'inline' replacement */ +#elif defined(__GNUC__) && __GNUC__ >= 3 + /* GCC supports '__inline__' as an extension */ +# define inline __inline__ +#elif defined(_MSC_VER) && _MSC_VER >= 1400 + /* MSC supports '__inline' from VS 2005 (or even earlier) */ +# define inline __inline +#else + /* Probably 'inline' is not supported by compiler. + Define to the empty string to be on the safe side. */ +# define inline /* empty */ +#endif + #endif /* HEADER_CURL_SETUP_H */ diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index 8303222b43e61a..5f2e99517acef0 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -286,29 +286,13 @@ Curl_sha512_256_finish(unsigned char *digest, defined(_MSC_VER) && !defined(__GNUC__) && !defined(__clang__) # if _MSC_VER >= 1400 # define MHDX_INLINE __forceinline -# else -# define MHDX_INLINE /* empty */ # endif #endif #if !defined(MHDX_INLINE) -# if defined(inline) - /* Assume that 'inline' macro was already defined correctly by - * the build system. */ -# define MHDX_INLINE inline -# elif defined(__cplusplus) - /* The code is compiled with C++ compiler. - * C++ always supports 'inline'. */ -# define MHDX_INLINE inline -# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901 - /* C99 (and later) supports 'inline' keyword */ -# define MHDX_INLINE inline -# elif defined(__GNUC__) && __GNUC__ >= 3 - /* GCC supports '__inline__' as an extension */ -# define MHDX_INLINE __inline__ -# else -# define MHDX_INLINE /* empty */ -# endif + /* Assume that 'inline' keyword works or the + * macro was already defined correctly. */ +# define MHDX_INLINE inline #endif /* Bits manipulation macros and functions.