Tidy and document the inline/__inline/__inline__ situation.

We can (and should) use `inline` in C++ but not in C headers that
need to support ANSI/C89/C90. `__inline__` works everywhere, but
traditionally we've used the BSD `__inline` in public headers.

Change-Id: I920e0a1f5fcd01cf8ddd89240ef66b25c50378d7
This commit is contained in:
Elliott Hughes 2024-05-15 16:06:07 +00:00
parent 3c0173d988
commit 3469e7df9b
5 changed files with 14 additions and 11 deletions

View file

@ -71,7 +71,7 @@ char* GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbyte
bool LockToCPU(int cpu_to_lock);
static __inline __attribute__ ((__always_inline__)) void MakeAllocationResident(
static inline __attribute__((__always_inline__)) void MakeAllocationResident(
void* ptr, size_t nbytes, int pagesize) {
uint8_t* data = reinterpret_cast<uint8_t*>(ptr);
for (size_t i = 0; i < nbytes; i += pagesize) {

View file

@ -17,7 +17,7 @@
#include <sys/statfs.h>
#include <sys/statvfs.h>
static __inline void __bionic_statfs_to_statvfs(const struct statfs* src, struct statvfs* dst) {
static inline void __bionic_statfs_to_statvfs(const struct statfs* src, struct statvfs* dst) {
dst->f_bsize = src->f_bsize;
dst->f_frsize = src->f_frsize;
dst->f_blocks = src->f_blocks;

View file

@ -124,7 +124,7 @@ struct __bionic_thrd_data {
};
#pragma clang diagnostic pop
static inline void* _Nonnull __bionic_thrd_trampoline(void* _Nonnull __arg) {
static __inline void* _Nonnull __bionic_thrd_trampoline(void* _Nonnull __arg) {
struct __bionic_thrd_data __data =
*__BIONIC_CAST(static_cast, struct __bionic_thrd_data*, __arg);
free(__arg);

View file

@ -61,13 +61,13 @@ __BEGIN_DECLS
/** Deprecated. Use memmove() instead. */
#define bcopy(b1, b2, len) __bionic_bcopy((b1), (b2), (len))
static __inline__ __always_inline void __bionic_bcopy(const void* _Nonnull b1, void* _Nonnull b2, size_t len) {
static __inline __always_inline void __bionic_bcopy(const void* _Nonnull b1, void* _Nonnull b2, size_t len) {
__builtin_memmove(b2, b1, len);
}
/** Deprecated. Use memset() instead. */
#define bzero(b, len) __bionic_bzero((b), (len))
static __inline__ __always_inline void __bionic_bzero(void* _Nonnull b, size_t len) {
static __inline __always_inline void __bionic_bzero(void* _Nonnull b, size_t len) {
__builtin_memset(b, 0, len);
}

View file

@ -87,9 +87,12 @@
#define __STRING(x) #x
#define ___STRING(x) __STRING(x)
#if defined(__cplusplus)
#define __inline inline /* convert to C++ keyword */
#endif /* !__cplusplus */
// C++ has `inline` as a keyword, as does C99, but ANSI C (aka C89 aka C90)
// does not. Everything accepts the `__inline__` extension though. We could
// just use that directly in our own code, but there's historical precedent
// for `__inline` meaning it's still used in upstream BSD code (and potentially
// downstream in vendor or app code).
#define __inline __inline__
#define __always_inline __attribute__((__always_inline__))
#define __attribute_const__ __attribute__((__const__))
@ -260,7 +263,7 @@
* them available externally. FORTIFY'ed functions try to be as close to possible as 'invisible';
* having stack protectors detracts from that (b/182948263).
*/
# define __BIONIC_FORTIFY_INLINE static __inline__ __attribute__((__no_stack_protector__)) \
# define __BIONIC_FORTIFY_INLINE static __inline __attribute__((__no_stack_protector__)) \
__always_inline __VERSIONER_FORTIFY_INLINE
/*
* We should use __BIONIC_FORTIFY_VARIADIC instead of __BIONIC_FORTIFY_INLINE
@ -268,9 +271,9 @@
* The __always_inline attribute is useless, misleading, and could trigger
* clang compiler bug to incorrectly inline variadic functions.
*/
# define __BIONIC_FORTIFY_VARIADIC static __inline__
# define __BIONIC_FORTIFY_VARIADIC static __inline
/* Error functions don't have bodies, so they can just be static. */
# define __BIONIC_ERROR_FUNCTION_VISIBILITY static __attribute__((__unused__))
# define __BIONIC_ERROR_FUNCTION_VISIBILITY static __unused
#else
/* Further increase sharing for some inline functions */
# define __pass_object_size_n(n)