Avoid duplicate symbols when linking .o files

Mark some functions as inline to avoid generating symbols that would
produce duplicate errors when linking multiple .o files that include the
SixtyFPS headers.
This commit is contained in:
Simon Hausmann 2021-03-30 16:38:53 +02:00
parent 3f6bbaf53a
commit d4178e0935
4 changed files with 21 additions and 19 deletions

View file

@ -215,7 +215,7 @@ using cbindgen_private::MouseEvent;
using cbindgen_private::sixtyfps_visit_item_tree; using cbindgen_private::sixtyfps_visit_item_tree;
namespace private_api { namespace private_api {
void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout) inline void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout)
{ {
#ifdef __cpp_sized_deallocation #ifdef __cpp_sized_deallocation
::operator delete(reinterpret_cast<void *>(ptr), layout.size, ::operator delete(reinterpret_cast<void *>(ptr), layout.size,
@ -226,7 +226,7 @@ void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout)
} }
template<typename T> template<typename T>
vtable::Layout drop_in_place(ComponentRef component) inline vtable::Layout drop_in_place(ComponentRef component)
{ {
reinterpret_cast<T *>(component.instance)->~T(); reinterpret_cast<T *>(component.instance)->~T();
return vtable::Layout { sizeof(T), alignof(T) }; return vtable::Layout { sizeof(T), alignof(T) };
@ -646,13 +646,13 @@ NativeStyleMetrics::NativeStyleMetrics()
using cbindgen_private::StandardListViewItem; using cbindgen_private::StandardListViewItem;
namespace cbindgen_private { namespace cbindgen_private {
bool operator==(const StandardListViewItem &a, const StandardListViewItem &b) inline bool operator==(const StandardListViewItem &a, const StandardListViewItem &b)
{ {
static_assert(sizeof(StandardListViewItem) == sizeof(std::tuple<SharedString>), static_assert(sizeof(StandardListViewItem) == sizeof(std::tuple<SharedString>),
"must update to cover all fields"); "must update to cover all fields");
return a.text == b.text; return a.text == b.text;
} }
bool operator!=(const StandardListViewItem &a, const StandardListViewItem &b) inline bool operator!=(const StandardListViewItem &a, const StandardListViewItem &b)
{ {
return !(a == b); return !(a == b);
} }
@ -665,12 +665,12 @@ struct VersionCheckHelper
}; };
} }
void run_event_loop() inline void run_event_loop()
{ {
cbindgen_private::sixtyfps_run_event_loop(); cbindgen_private::sixtyfps_run_event_loop();
} }
void quit_event_loop() inline void quit_event_loop()
{ {
cbindgen_private::sixtyfps_quit_event_loop(); cbindgen_private::sixtyfps_quit_event_loop();
} }
@ -678,7 +678,7 @@ void quit_event_loop()
/// Registers a font by the specified path. The path must refer to an existing /// Registers a font by the specified path. The path must refer to an existing
/// TrueType font font. /// TrueType font font.
/// \returns an empty optional on success, otherwise an error string /// \returns an empty optional on success, otherwise an error string
std::optional<SharedString> register_font_from_path(const SharedString &path) inline std::optional<SharedString> register_font_from_path(const SharedString &path)
{ {
SharedString maybe_err; SharedString maybe_err;
cbindgen_private::sixtyfps_register_font_from_path(&path, &maybe_err); cbindgen_private::sixtyfps_register_font_from_path(&path, &maybe_err);

View file

@ -182,7 +182,7 @@ inline Color Color::darker(float factor) const
} }
template<> template<>
RgbaColor<uint8_t>::RgbaColor(const Color &color) inline RgbaColor<uint8_t>::RgbaColor(const Color &color)
{ {
red = color.red(); red = color.red();
green = color.green(); green = color.green();
@ -191,7 +191,7 @@ RgbaColor<uint8_t>::RgbaColor(const Color &color)
} }
template<> template<>
RgbaColor<float>::RgbaColor(const Color &color) inline RgbaColor<float>::RgbaColor(const Color &color)
{ {
red = float(color.red()) / 255.; red = float(color.red()) / 255.;
green = float(color.green()) / 255.; green = float(color.green()) / 255.;
@ -210,8 +210,9 @@ RgbaColor<float> Color::to_argb_float() const
} }
template<> template<>
void Property<Color>::set_animated_value( inline void
const Color &new_value, const cbindgen_private::PropertyAnimation &animation_data) const Property<Color>::set_animated_value(const Color &new_value,
const cbindgen_private::PropertyAnimation &animation_data) const
{ {
cbindgen_private::sixtyfps_property_set_animated_value_color(&inner, value, new_value, cbindgen_private::sixtyfps_property_set_animated_value_color(&inner, value, new_value,
&animation_data); &animation_data);

View file

@ -25,7 +25,7 @@ using cbindgen_private::StateInfo;
namespace private_api { namespace private_api {
void sixtyfps_property_set_animated_binding_helper( inline void sixtyfps_property_set_animated_binding_helper(
const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, int32_t *), const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, int32_t *),
void *user_data, void (*drop_user_data)(void *), void *user_data, void (*drop_user_data)(void *),
const cbindgen_private::PropertyAnimation *animation_data, const cbindgen_private::PropertyAnimation *animation_data,
@ -35,7 +35,7 @@ void sixtyfps_property_set_animated_binding_helper(
handle, binding, user_data, drop_user_data, animation_data, transition_data); handle, binding, user_data, drop_user_data, animation_data, transition_data);
} }
void sixtyfps_property_set_animated_binding_helper( inline void sixtyfps_property_set_animated_binding_helper(
const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, float *), const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, float *),
void *user_data, void (*drop_user_data)(void *), void *user_data, void (*drop_user_data)(void *),
const cbindgen_private::PropertyAnimation *animation_data, const cbindgen_private::PropertyAnimation *animation_data,
@ -45,7 +45,7 @@ void sixtyfps_property_set_animated_binding_helper(
handle, binding, user_data, drop_user_data, animation_data, transition_data); handle, binding, user_data, drop_user_data, animation_data, transition_data);
} }
void sixtyfps_property_set_animated_binding_helper( inline void sixtyfps_property_set_animated_binding_helper(
const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, Color *), const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, Color *),
void *user_data, void (*drop_user_data)(void *), void *user_data, void (*drop_user_data)(void *),
const cbindgen_private::PropertyAnimation *animation_data, const cbindgen_private::PropertyAnimation *animation_data,
@ -55,7 +55,7 @@ void sixtyfps_property_set_animated_binding_helper(
handle, binding, user_data, drop_user_data, animation_data, transition_data); handle, binding, user_data, drop_user_data, animation_data, transition_data);
} }
void sixtyfps_property_set_animated_binding_helper( inline void sixtyfps_property_set_animated_binding_helper(
const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, Brush *), const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, Brush *),
void *user_data, void (*drop_user_data)(void *), void *user_data, void (*drop_user_data)(void *),
const cbindgen_private::PropertyAnimation *animation_data, const cbindgen_private::PropertyAnimation *animation_data,
@ -198,7 +198,7 @@ private:
}; };
template<> template<>
void Property<int32_t>::set_animated_value( inline void Property<int32_t>::set_animated_value(
const int32_t &new_value, const cbindgen_private::PropertyAnimation &animation_data) const const int32_t &new_value, const cbindgen_private::PropertyAnimation &animation_data) const
{ {
cbindgen_private::sixtyfps_property_set_animated_value_int(&inner, value, new_value, cbindgen_private::sixtyfps_property_set_animated_value_int(&inner, value, new_value,
@ -206,8 +206,9 @@ void Property<int32_t>::set_animated_value(
} }
template<> template<>
void Property<float>::set_animated_value( inline void
const float &new_value, const cbindgen_private::PropertyAnimation &animation_data) const Property<float>::set_animated_value(const float &new_value,
const cbindgen_private::PropertyAnimation &animation_data) const
{ {
cbindgen_private::sixtyfps_property_set_animated_value_float(&inner, value, new_value, cbindgen_private::sixtyfps_property_set_animated_value_float(&inner, value, new_value,
&animation_data); &animation_data);

View file

@ -176,7 +176,7 @@ private:
}; };
namespace private_api { namespace private_api {
cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str) inline cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str)
{ {
return cbindgen_private::Slice<uint8_t> { return cbindgen_private::Slice<uint8_t> {
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())), str.size() const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())), str.size()