Skip to content

Commit 04185aa

Browse files
committed
stdlib: correct declaration for malloc_usable_size on android
`malloc_usable_size` is provided on Android with API Level 17 or newer. However, the signature between bionic and glibc is slightly different, with android marking the parameter as `const`. This results in a type mismatch error when building the standard library for android. Adjust it to match the target system.
1 parent 4967393 commit 04185aa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ static inline __swift_size_t _swift_stdlib_malloc_size(const void *ptr) {
9999
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__ANDROID__) \
100100
|| defined(__HAIKU__) || defined(__FreeBSD__)
101101
static inline __swift_size_t _swift_stdlib_malloc_size(const void *ptr) {
102+
#if defined(__ANDROID__)
103+
#if __ANDROID_API__ >= 17
104+
extern __swift_size_t malloc_usable_size(const void *ptr);
105+
#endif
106+
#else
102107
extern __swift_size_t malloc_usable_size(void *ptr);
108+
#endif
103109
return malloc_usable_size(CONST_CAST(void *, ptr));
104110
}
105111
#elif defined(_WIN32)

0 commit comments

Comments
 (0)