Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e537b18e authored by Tomislav Novak's avatar Tomislav Novak
Browse files

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<minikin::FontVariation,
         std::__1::allocator<minikin::FontVariation> >::~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<minikin::FontVariation> field)

Test: add "-O0" to hwui cflags and verify that system_server no longer
      hangs on startup
Signed-off-by: default avatarTomislav Novak <tnovak@meta.com>
Change-Id: Ic071a7c00a9b2f632b6f56877f54c6a58eb38965
parent c2fa03fc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@

namespace android {

namespace {
struct NativeFamilyBuilder {
    NativeFamilyBuilder(uint32_t langId, int variant)
        : langId(langId), variant(static_cast<minikin::FamilyVariant>(variant)) {}
@@ -52,6 +53,7 @@ struct NativeFamilyBuilder {
    std::vector<std::shared_ptr<minikin::Font>> fonts;
    std::vector<minikin::FontVariation> axes;
};
}  // namespace

static inline NativeFamilyBuilder* toNativeBuilder(jlong ptr) {
    return reinterpret_cast<NativeFamilyBuilder*>(ptr);
+2 −0
Original line number Diff line number Diff line
@@ -29,9 +29,11 @@

namespace android {

namespace {
struct NativeFamilyBuilder {
    std::vector<std::shared_ptr<minikin::Font>> fonts;
};
}  // namespace

static inline NativeFamilyBuilder* toBuilder(jlong ptr) {
    return reinterpret_cast<NativeFamilyBuilder*>(ptr);