From e537b18e8efe0c4cc510e0e34392e94c7dda4cdc Mon Sep 17 00:00:00 2001 From: Tomislav Novak Date: Tue, 2 May 2023 14:35:29 -0700 Subject: [PATCH] hwui: Fix multiple definitions of NativeFamilyBuilder There are two _different_ definitions of the NativeFamilyBuilder class, one in jni/FontFamily.cpp and the other in jni/fonts/FontFamily.cpp, violating the one-definition rule. Make them local by moving to an anonymous namespace. This is an issue in non-optimized builds where ~NativeFamilyBuilder isn't inlined, so the wrong destructor ends up being called: ``` (gdb) bt [...] #3 0x0000007292c44a8c in std::__1::vector >::~vector () #4 0x0000007292c44a54 in android::NativeFamilyBuilder::~NativeFamilyBuilder () #8 0x0000007292c64cec in android::FontFamily_Builder_build () ``` (note that the struct used by FontFamily_Builder_build() doesn't have the vector field) Test: add "-O0" to hwui cflags and verify that system_server no longer hangs on startup Signed-off-by: Tomislav Novak Change-Id: Ic071a7c00a9b2f632b6f56877f54c6a58eb38965 --- libs/hwui/jni/FontFamily.cpp | 2 ++ libs/hwui/jni/fonts/FontFamily.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libs/hwui/jni/FontFamily.cpp b/libs/hwui/jni/FontFamily.cpp index ce5ac382aeff8..f632d093d9f33 100644 --- a/libs/hwui/jni/FontFamily.cpp +++ b/libs/hwui/jni/FontFamily.cpp @@ -44,6 +44,7 @@ namespace android { +namespace { struct NativeFamilyBuilder { NativeFamilyBuilder(uint32_t langId, int variant) : langId(langId), variant(static_cast(variant)) {} @@ -52,6 +53,7 @@ struct NativeFamilyBuilder { std::vector> fonts; std::vector axes; }; +} // namespace static inline NativeFamilyBuilder* toNativeBuilder(jlong ptr) { return reinterpret_cast(ptr); diff --git a/libs/hwui/jni/fonts/FontFamily.cpp b/libs/hwui/jni/fonts/FontFamily.cpp index b68213549938d..ac1c05ed6afe9 100644 --- a/libs/hwui/jni/fonts/FontFamily.cpp +++ b/libs/hwui/jni/fonts/FontFamily.cpp @@ -29,9 +29,11 @@ namespace android { +namespace { struct NativeFamilyBuilder { std::vector> fonts; }; +} // namespace static inline NativeFamilyBuilder* toBuilder(jlong ptr) { return reinterpret_cast(ptr);