Route debug() calls in Slint consistently through Platform's debug_log() (#5718)

This commit is contained in:
Simon Hausmann 2024-07-29 16:31:09 +02:00 committed by GitHub
parent d8e7226cd5
commit 8a7db55bb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 7 deletions

View file

@ -124,6 +124,11 @@ upgrade_item_weak(const cbindgen_private::ItemWeak &item_weak)
} }
} }
inline void debug(const SharedString &str)
{
cbindgen_private::slint_debug(&str);
}
} // namespace private_api } // namespace private_api
template<typename T> template<typename T>

View file

@ -152,6 +152,11 @@ pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32)
} }
} }
#[no_mangle]
pub extern "C" fn slint_debug(string: &SharedString) {
i_slint_core::debug_log!("{string}");
}
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod allocator { mod allocator {
use core::alloc::Layout; use core::alloc::Layout;

View file

@ -127,12 +127,7 @@ pub fn debug(s: SharedString) {
#[cfg(feature = "log")] #[cfg(feature = "log")]
log::debug!("{s}"); log::debug!("{s}");
#[cfg(not(feature = "log"))] #[cfg(not(feature = "log"))]
{ i_slint_core::debug_log!("{s}");
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
println!("{s}");
#[cfg(any(not(feature = "std"), target_arch = "wasm32"))]
i_slint_core::debug_log!("{s}");
}
} }
pub fn ensure_backend() -> Result<(), crate::PlatformError> { pub fn ensure_backend() -> Result<(), crate::PlatformError> {

View file

@ -3128,7 +3128,7 @@ fn compile_builtin_function_call(
BuiltinFunction::AnimationTick => "slint::cbindgen_private::slint_animation_tick()".into(), BuiltinFunction::AnimationTick => "slint::cbindgen_private::slint_animation_tick()".into(),
BuiltinFunction::Debug => { BuiltinFunction::Debug => {
ctx.generator_state.conditional_includes.iostream.set(true); ctx.generator_state.conditional_includes.iostream.set(true);
format!("std::cout << {} << std::endl;", a.join("<<")) format!("slint::private_api::debug({});", a.join(","))
} }
BuiltinFunction::Mod => { BuiltinFunction::Mod => {
ctx.generator_state.conditional_includes.cmath.set(true); ctx.generator_state.conditional_includes.cmath.set(true);