From 9305a5808d2f552a6fd910a21e297fb2d3daed38 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 18 Oct 2024 23:05:28 +0200 Subject: [PATCH] codegen/builder: Assert the main thread is initalized Fixes https://github.com/gtk-rs/gir/issues/1590 --- src/codegen/object.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/codegen/object.rs b/src/codegen/object.rs index 697174607..e4cf3880b 100644 --- a/src/codegen/object.rs +++ b/src/codegen/object.rs @@ -14,12 +14,13 @@ use super::{ use crate::{ analysis::{ self, bounds::BoundType, object::has_builder_properties, record_type::RecordType, - ref_mode::RefMode, rust_type::RustType, + ref_mode::RefMode, rust_type::RustType, safety_assertion_mode::SafetyAssertionMode, }, env::Env, library::{self, Nullable}, nameutil, traits::IntoString, + writer::safety_assertion_mode_to_str, }; pub fn generate(w: &mut dyn Write, env: &Env, analysis: &analysis::object::Info) -> Result<()> { @@ -456,6 +457,11 @@ fn generate_builder(w: &mut dyn Write, env: &Env, analysis: &analysis::object::I pub fn build(self) -> {name} {{", name = analysis.name, )?; + writeln!( + w, + "{}", + safety_assertion_mode_to_str(SafetyAssertionMode::InMainThread) + )?; // The split allows us to not have clippy::let_and_return lint disabled if let Some(code) = analysis.builder_postprocess.as_ref() {