From 42fd4778987ea92b73894c6acbaf9db1c9bfc3f2 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 27 Jan 2024 08:59:08 +0100 Subject: [PATCH 1/3] Update gir/gir-files submodules --- gir | 2 +- gir-files | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gir b/gir index 1c7a6b57a5fc..8d78966cf108 160000 --- a/gir +++ b/gir @@ -1 +1 @@ -Subproject commit 1c7a6b57a5fcc4d87cb82e0535dc49d14babb76b +Subproject commit 8d78966cf108b917e0c29a5427f81548d84b98af diff --git a/gir-files b/gir-files index 21b29d0e0c1a..07e73e69e824 160000 --- a/gir-files +++ b/gir-files @@ -1 +1 @@ -Subproject commit 21b29d0e0c1afee88313b1e23bb5b73d7755c068 +Subproject commit 07e73e69e824dbd3c42b5534a58403ddfaa3b047 From 097a24bf21277808977600298b2966a826115052 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 27 Jan 2024 09:00:21 +0100 Subject: [PATCH 2/3] Regenerate with latest gir/gir-files --- gdk4-wayland/src/auto/versions.txt | 4 ++-- gdk4-wayland/sys/versions.txt | 4 ++-- gdk4-win32/src/auto/versions.txt | 4 ++-- gdk4-win32/sys/versions.txt | 4 ++-- gdk4-x11/src/auto/versions.txt | 4 ++-- gdk4-x11/sys/versions.txt | 4 ++-- gdk4/src/auto/versions.txt | 4 ++-- gdk4/sys/versions.txt | 4 ++-- gsk4/src/auto/versions.txt | 4 ++-- gsk4/sys/versions.txt | 4 ++-- gtk4/src/auto/versions.txt | 4 ++-- gtk4/sys/versions.txt | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gdk4-wayland/src/auto/versions.txt b/gdk4-wayland/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-wayland/src/auto/versions.txt +++ b/gdk4-wayland/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4-wayland/sys/versions.txt b/gdk4-wayland/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-wayland/sys/versions.txt +++ b/gdk4-wayland/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4-win32/src/auto/versions.txt b/gdk4-win32/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-win32/src/auto/versions.txt +++ b/gdk4-win32/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4-win32/sys/versions.txt b/gdk4-win32/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-win32/sys/versions.txt +++ b/gdk4-win32/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4-x11/src/auto/versions.txt b/gdk4-x11/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-x11/src/auto/versions.txt +++ b/gdk4-x11/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4-x11/sys/versions.txt b/gdk4-x11/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4-x11/sys/versions.txt +++ b/gdk4-x11/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4/src/auto/versions.txt b/gdk4/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4/src/auto/versions.txt +++ b/gdk4/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gdk4/sys/versions.txt b/gdk4/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gdk4/sys/versions.txt +++ b/gdk4/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gsk4/src/auto/versions.txt b/gsk4/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gsk4/src/auto/versions.txt +++ b/gsk4/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gsk4/sys/versions.txt b/gsk4/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gsk4/sys/versions.txt +++ b/gsk4/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gtk4/src/auto/versions.txt b/gtk4/src/auto/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gtk4/src/auto/versions.txt +++ b/gtk4/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) diff --git a/gtk4/sys/versions.txt b/gtk4/sys/versions.txt index 2b08b0af6393..b9e6209efa05 100644 --- a/gtk4/sys/versions.txt +++ b/gtk4/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ 1c7a6b57a5fc) -from gir-files (https://github.com/gtk-rs/gir-files @ 21b29d0e0c1a) +Generated by gir (https://github.com/gtk-rs/gir @ 8d78966cf108) +from gir-files (https://github.com/gtk-rs/gir-files @ 07e73e69e824) From 0cdb8735c8c27e0d63037cd6f67bff3ec055eceb Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 27 Jan 2024 09:25:20 +0100 Subject: [PATCH 3/3] Replace Lazy with OnceLock Removes once_cell dependency --- examples/custom_editable/custom_tag/imp.rs | 13 ++++++---- examples/expressions/note/imp.rs | 7 ++--- gdk4-wayland/src/wayland_display.rs | 17 ++++++------ gtk4/src/builder_rust_scope.rs | 9 +++---- gtk4/src/functions.rs | 23 +++++++++-------- gtk4/src/lib.rs | 30 ++++++++++------------ gtk4/src/subclass/buildable.rs | 11 +++++--- gtk4/src/subclass/cell_layout.rs | 12 ++++----- gtk4/src/subclass/editable.rs | 17 +++++------- gtk4/src/subclass/entry_buffer.rs | 12 +++++---- gtk4/src/subclass/font_chooser.rs | 20 +++++++++------ 11 files changed, 87 insertions(+), 84 deletions(-) diff --git a/examples/custom_editable/custom_tag/imp.rs b/examples/custom_editable/custom_tag/imp.rs index 71e3ceda27d5..17b509ea1fc8 100644 --- a/examples/custom_editable/custom_tag/imp.rs +++ b/examples/custom_editable/custom_tag/imp.rs @@ -1,6 +1,9 @@ -use std::cell::{Cell, RefCell}; +use std::{ + cell::{Cell, RefCell}, + sync::OnceLock, +}; -use glib::{clone, once_cell::sync::Lazy, subclass::Signal}; +use glib::{clone, subclass::Signal}; use gtk::{glib, prelude::*, subclass::prelude::*}; #[derive(Debug, glib::Properties)] @@ -39,13 +42,13 @@ impl ObjectSubclass for CustomTag { #[glib::derived_properties] impl ObjectImpl for CustomTag { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: OnceLock> = OnceLock::new(); + SIGNALS.get_or_init(|| { vec![ Signal::builder("closed").build(), Signal::builder("clicked").build(), ] - }); - SIGNALS.as_ref() + }) } fn constructed(&self) { diff --git a/examples/expressions/note/imp.rs b/examples/expressions/note/imp.rs index c4c3d53f0f02..b8ff04dc63da 100644 --- a/examples/expressions/note/imp.rs +++ b/examples/expressions/note/imp.rs @@ -1,8 +1,5 @@ -use gtk::{ - glib::{self, once_cell::unsync::OnceCell}, - prelude::*, - subclass::prelude::*, -}; +use gtk::{glib, prelude::*, subclass::prelude::*}; +use std::cell::OnceCell; use super::Metadata; diff --git a/gdk4-wayland/src/wayland_display.rs b/gdk4-wayland/src/wayland_display.rs index 3d3903dcf02b..34d1db0d82e6 100644 --- a/gdk4-wayland/src/wayland_display.rs +++ b/gdk4-wayland/src/wayland_display.rs @@ -2,7 +2,7 @@ #[cfg(feature = "wayland_crate")] #[cfg_attr(docsrs, doc(cfg(feature = "wayland_crate")))] -use glib::{once_cell::sync::Lazy, prelude::*, translate::*, Quark}; +use glib::{prelude::*, translate::*, Quark}; #[cfg(all(feature = "v4_4", feature = "egl"))] #[cfg_attr(docsrs, doc(cfg(all(feature = "v4_4", feature = "egl"))))] use khronos_egl as egl; @@ -16,10 +16,6 @@ use wayland_client::{ use crate::WaylandDisplay; -#[cfg(feature = "wayland_crate")] -static WAYLAND_DISPLAY_CONNECTION_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk-rs-wayland-display-connection-quark")); - impl WaylandDisplay { #[cfg(all(feature = "v4_4", feature = "egl"))] #[cfg_attr(docsrs, doc(cfg(all(feature = "v4_4", feature = "egl"))))] @@ -75,10 +71,13 @@ impl WaylandDisplay { #[cfg(feature = "wayland_crate")] pub(crate) fn connection(&self) -> wayland_client::Connection { + use std::sync::OnceLock; + static QUARK: OnceLock = OnceLock::new(); + let quark = + *QUARK.get_or_init(|| Quark::from_str("gtk-rs-wayland-display-connection-quark")); + unsafe { - match self - .qdata::>(*WAYLAND_DISPLAY_CONNECTION_QUARK) - { + match self.qdata::>(quark) { Some(conn) => conn.as_ref().clone().unwrap(), None => { let display_ptr = @@ -87,7 +86,7 @@ impl WaylandDisplay { display_ptr as *mut _, ); let conn = wayland_client::Connection::from_backend(backend); - self.set_qdata(*WAYLAND_DISPLAY_CONNECTION_QUARK, conn.clone()); + self.set_qdata(quark, conn.clone()); conn } diff --git a/gtk4/src/builder_rust_scope.rs b/gtk4/src/builder_rust_scope.rs index 573ab3b43a1d..3217cba4fcbd 100644 --- a/gtk4/src/builder_rust_scope.rs +++ b/gtk4/src/builder_rust_scope.rs @@ -305,10 +305,10 @@ mod tests { #[crate::test] fn test_rust_builder_scope_object_during_dispose() { + use glib::subclass::Signal; + use std::sync::OnceLock; use std::{cell::Cell, rc::Rc}; - use glib::{once_cell::sync::Lazy, subclass::Signal}; - #[derive(Debug, Default)] pub struct MyObjectPrivate { counter: Rc>, @@ -320,9 +320,8 @@ mod tests { } impl ObjectImpl for MyObjectPrivate { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("destroyed").build()]); - SIGNALS.as_ref() + static SIGNALS: OnceLock> = OnceLock::new(); + SIGNALS.get_or_init(|| vec![Signal::builder("destroyed").build()]) } fn dispose(&self) { self.obj().emit_by_name::<()>("destroyed", &[]); diff --git a/gtk4/src/functions.rs b/gtk4/src/functions.rs index a87d0f60e3f7..3ffcd01cfb28 100644 --- a/gtk4/src/functions.rs +++ b/gtk4/src/functions.rs @@ -1,8 +1,8 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::{boxed::Box as Box_, mem, pin::Pin, ptr}; +use std::{boxed::Box as Box_, pin::Pin, sync::OnceLock}; -use glib::{once_cell::sync::Lazy, translate::*, IntoGStr, Quark, Slice, ToValue}; +use glib::{translate::*, IntoGStr, Quark, Slice, ToValue}; pub use crate::auto::functions::*; use crate::{prelude::*, AboutDialog, StyleProvider, Window}; @@ -87,8 +87,8 @@ pub fn accelerator_parse(accelerator: impl IntoGStr) -> Option<(gdk::Key, gdk::M assert_initialized_main_thread!(); unsafe { accelerator.run_with_gstr(|accelerator| { - let mut accelerator_key = mem::MaybeUninit::uninit(); - let mut accelerator_mods = mem::MaybeUninit::uninit(); + let mut accelerator_key = std::mem::MaybeUninit::uninit(); + let mut accelerator_mods = std::mem::MaybeUninit::uninit(); let ret = from_glib(ffi::gtk_accelerator_parse( accelerator.as_ptr(), accelerator_key.as_mut_ptr(), @@ -115,7 +115,7 @@ pub fn accelerator_parse_with_keycode( unsafe { accelerator.run_with_gstr(|accelerator| { let mut accelerator_key = std::mem::MaybeUninit::uninit(); - let mut accelerator_codes_ptr = ptr::null_mut(); + let mut accelerator_codes_ptr = std::ptr::null_mut(); let mut accelerator_mods = std::mem::MaybeUninit::uninit(); let success = from_glib(ffi::gtk_accelerator_parse_with_keycode( accelerator.as_ptr(), @@ -127,7 +127,7 @@ pub fn accelerator_parse_with_keycode( if success { let mut len = 0; if !accelerator_codes_ptr.is_null() { - while ptr::read(accelerator_codes_ptr.add(len)) != 0 { + while std::ptr::read(accelerator_codes_ptr.add(len)) != 0 { len += 1; } } @@ -173,7 +173,7 @@ pub fn show_uri_full) + 'static>( res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer, ) { - let mut error = ptr::null_mut(); + let mut error = std::ptr::null_mut(); let _ = ffi::gtk_show_uri_full_finish(parent_ptr as *mut ffi::GtkWindow, res, &mut error); let result = if error.is_null() { Ok(()) @@ -221,13 +221,14 @@ pub fn show_uri_full_future( })) } -static SHOW_ABOUT_DIALOG_QUARK: Lazy = Lazy::new(|| Quark::from_str("gtk-rs-about-dialog")); - #[doc(alias = "gtk_show_about_dialog")] pub fn show_about_dialog>(parent: Option<&P>, properties: &[(&str, &dyn ToValue)]) { assert_initialized_main_thread!(); + static QUARK: OnceLock = OnceLock::new(); + let quark = *QUARK.get_or_init(|| Quark::from_str("gtk-rs-about-dialog")); + unsafe { - if let Some(d) = parent.and_then(|p| p.qdata::(*SHOW_ABOUT_DIALOG_QUARK)) { + if let Some(d) = parent.and_then(|p| p.qdata::(quark)) { d.as_ref().show(); } else { let mut builder = glib::Object::builder::(); @@ -241,7 +242,7 @@ pub fn show_about_dialog>(parent: Option<&P>, properties: &[(&str // cache the dialog if a parent is set if let Some(dialog_parent) = parent { - dialog_parent.set_qdata(*SHOW_ABOUT_DIALOG_QUARK, about_dialog.clone()); + dialog_parent.set_qdata(quark, about_dialog.clone()); } about_dialog.show(); }; diff --git a/gtk4/src/lib.rs b/gtk4/src/lib.rs index 32644cdf823b..9cfd638c183c 100644 --- a/gtk4/src/lib.rs +++ b/gtk4/src/lib.rs @@ -62,31 +62,29 @@ where R: Send + 'static, { skip_assert_initialized!(); + static TEST_THREAD_WORKER: std::sync::OnceLock = std::sync::OnceLock::new(); + let pool = TEST_THREAD_WORKER.get_or_init(|| { + let pool = glib::ThreadPool::exclusive(1).unwrap(); + pool.push(move || { + crate::init().expect("Tests failed to initialize gtk"); + }) + .expect("Failed to schedule a test call"); + pool + }); use std::{panic, sync::mpsc}; let (tx, rx) = mpsc::sync_channel(1); - TEST_THREAD_WORKER - .push(move || { - tx.send(panic::catch_unwind(function)) - .unwrap_or_else(|_| panic!("Failed to return result from thread pool")); - }) - .expect("Failed to schedule a test call"); + pool.push(move || { + tx.send(panic::catch_unwind(function)) + .unwrap_or_else(|_| panic!("Failed to return result from thread pool")); + }) + .expect("Failed to schedule a test call"); rx.recv() .expect("Failed to receive result from thread pool") .unwrap_or_else(|e| std::panic::resume_unwind(e)) } -static TEST_THREAD_WORKER: glib::once_cell::sync::Lazy = - glib::once_cell::sync::Lazy::new(|| { - let pool = glib::ThreadPool::exclusive(1).unwrap(); - pool.push(move || { - crate::init().expect("Tests failed to initialize gtk"); - }) - .expect("Failed to schedule a test call"); - pool - }); - #[allow(clippy::derived_hash_with_manual_eq)] #[allow(clippy::too_many_arguments)] #[allow(clippy::type_complexity)] diff --git a/gtk4/src/subclass/buildable.rs b/gtk4/src/subclass/buildable.rs index bc5c73fe7980..237b82583155 100644 --- a/gtk4/src/subclass/buildable.rs +++ b/gtk4/src/subclass/buildable.rs @@ -3,8 +3,9 @@ // rustdoc-stripper-ignore-next //! Traits intended for implementing the [`Buildable`](crate::Buildable) //! interface. +use std::sync::OnceLock; -use glib::{once_cell::sync::Lazy, translate::*, GString, Object, Quark, Value}; +use glib::{translate::*, GString, Object, Quark, Value}; use super::PtrHolder; use crate::{prelude::*, subclass::prelude::*, Buildable, Builder}; @@ -286,8 +287,6 @@ unsafe extern "C" fn buildable_parser_finished( imp.parser_finished(&from_glib_borrow(builderptr)) } -static BUILDABLE_GET_INTERNAL_CHILD_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk4-rs-subclass-buildable-get-internal-child")); unsafe extern "C" fn buildable_get_internal_child( buildable: *mut ffi::GtkBuildable, builderptr: *mut ffi::GtkBuilder, @@ -299,11 +298,15 @@ unsafe extern "C" fn buildable_get_internal_child( let ret = imp.internal_child(&from_glib_borrow(builderptr), &name); + static QUARK: OnceLock = OnceLock::new(); + let quark = + *QUARK.get_or_init(|| Quark::from_str("gtk4-rs-subclass-buildable-get-internal-child")); + // transfer none: ensure the internal child stays alive for as long as the // object building it let ret = ret.into_glib_ptr(); imp.obj().set_qdata( - *BUILDABLE_GET_INTERNAL_CHILD_QUARK, + quark, PtrHolder(ret, |ptr| { glib::gobject_ffi::g_object_unref(ptr as *mut _); }), diff --git a/gtk4/src/subclass/cell_layout.rs b/gtk4/src/subclass/cell_layout.rs index 030e7a2d0cb4..ed40e3b5d1dd 100644 --- a/gtk4/src/subclass/cell_layout.rs +++ b/gtk4/src/subclass/cell_layout.rs @@ -3,8 +3,9 @@ // rustdoc-stripper-ignore-next //! Traits intended for implementing the [`CellLayout`](crate::CellLayout) //! interface. +use std::sync::OnceLock; -use glib::{once_cell::sync::Lazy, translate::*, Quark}; +use glib::{translate::*, Quark}; use crate::{ prelude::*, subclass::prelude::*, CellArea, CellLayout, CellRenderer, TreeIter, TreeModel, @@ -388,9 +389,6 @@ unsafe extern "C" fn cell_layout_set_cell_data_func( imp.set_cell_data_func(&*cell, callback) } -static CELL_LAYOUT_GET_CELLS_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk-rs-subclass-cell-layout-get-cells")); - unsafe extern "C" fn cell_layout_get_cells( cell_layout: *mut ffi::GtkCellLayout, ) -> *mut glib::ffi::GList { @@ -399,9 +397,11 @@ unsafe extern "C" fn cell_layout_get_cells( let cells = imp.cells(); + static QUARK: OnceLock = OnceLock::new(); + let quark = *QUARK.get_or_init(|| Quark::from_str("gtk-rs-subclass-cell-layout-get-cells")); + // transfer container: list owned by the caller by not the actual content // so we need to keep the cells around and return a ptr of the list - imp.obj() - .set_qdata(*CELL_LAYOUT_GET_CELLS_QUARK, cells.clone()); + imp.obj().set_qdata(quark, cells.clone()); cells.to_glib_container().0 } diff --git a/gtk4/src/subclass/editable.rs b/gtk4/src/subclass/editable.rs index 8a6022020487..a3744f169dd2 100644 --- a/gtk4/src/subclass/editable.rs +++ b/gtk4/src/subclass/editable.rs @@ -3,8 +3,9 @@ // rustdoc-stripper-ignore-next //! Traits intended for implementing the [`Editable`](crate::Editable) //! interface. +use std::sync::OnceLock; -use glib::{once_cell::sync::Lazy, translate::*, GString, Quark}; +use glib::{translate::*, GString, Quark}; use libc::{c_char, c_int}; use crate::{prelude::*, subclass::prelude::*, Editable}; @@ -319,9 +320,6 @@ unsafe extern "C" fn editable_get_text( imp.text().into_glib_ptr() } -static EDITABLE_GET_DELEGATE_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk-rs-subclass-editable-get-delegate")); - unsafe extern "C" fn editable_get_delegate( editable: *mut ffi::GtkEditable, ) -> *mut ffi::GtkEditable { @@ -330,10 +328,10 @@ unsafe extern "C" fn editable_get_delegate( let delegate = imp.delegate(); - match imp - .obj() - .qdata::>(*EDITABLE_GET_DELEGATE_QUARK) - { + static QUARK: OnceLock = OnceLock::new(); + let quark = *QUARK.get_or_init(|| Quark::from_str("gtk-rs-subclass-editable-get-delegate")); + + match imp.obj().qdata::>(quark) { Some(delegate_data) => { assert_eq!( delegate_data.as_ref(), @@ -342,8 +340,7 @@ unsafe extern "C" fn editable_get_delegate( ); } None => { - imp.obj() - .set_qdata(*EDITABLE_GET_DELEGATE_QUARK, delegate.clone()); + imp.obj().set_qdata(quark, delegate.clone()); } }; delegate.to_glib_none().0 diff --git a/gtk4/src/subclass/entry_buffer.rs b/gtk4/src/subclass/entry_buffer.rs index b4cffba39255..48f513e21eda 100644 --- a/gtk4/src/subclass/entry_buffer.rs +++ b/gtk4/src/subclass/entry_buffer.rs @@ -2,8 +2,9 @@ // rustdoc-stripper-ignore-next //! Traits intended for subclassing [`EntryBuffer`](crate::EntryBuffer). +use std::sync::OnceLock; -use glib::{once_cell::sync::Lazy, translate::*, GString}; +use glib::{translate::*, GString}; use super::PtrHolder; use crate::{prelude::*, subclass::prelude::*, EntryBuffer}; @@ -182,9 +183,6 @@ unsafe extern "C" fn entry_buffer_deleted_text( imp.deleted_text(position, n_chars) } -static GET_TEXT_QUARK: Lazy = - Lazy::new(|| glib::Quark::from_str("gtk4-rs-subclass-entry-buffer-text")); - unsafe extern "C" fn entry_buffer_get_text( ptr: *mut ffi::GtkEntryBuffer, n_bytes: *mut usize, @@ -198,9 +196,13 @@ unsafe extern "C" fn entry_buffer_get_text( } // Ensures that the returned text stays alive for as long as // the entry buffer instance + + static QUARK: OnceLock = OnceLock::new(); + let quark = *QUARK.get_or_init(|| glib::Quark::from_str("gtk4-rs-subclass-entry-buffer-text")); + let fullptr = ret.into_glib_ptr(); imp.obj().set_qdata( - *GET_TEXT_QUARK, + quark, PtrHolder(fullptr, |ptr| { glib::ffi::g_free(ptr as *mut _); }), diff --git a/gtk4/src/subclass/font_chooser.rs b/gtk4/src/subclass/font_chooser.rs index 79055d20fb69..5055f22703da 100644 --- a/gtk4/src/subclass/font_chooser.rs +++ b/gtk4/src/subclass/font_chooser.rs @@ -3,8 +3,9 @@ // rustdoc-stripper-ignore-next //! Traits intended for implementing the [`FontChooser`](crate::FontChooser) //! interface. +use std::sync::OnceLock; -use glib::{once_cell::sync::Lazy, translate::*, GString, Quark}; +use glib::{translate::*, GString, Quark}; use pango::{FontFace, FontFamily, FontMap}; use super::PtrHolder; @@ -229,9 +230,6 @@ unsafe impl IsImplementable for FontChooser { } } -static FONT_CHOOSER_GET_FONT_FAMILY_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk4-rs-subclass-font-chooser-font-family")); - unsafe extern "C" fn font_chooser_get_font_family( font_chooser: *mut ffi::GtkFontChooser, ) -> *mut pango::ffi::PangoFontFamily { @@ -241,8 +239,13 @@ unsafe extern "C" fn font_chooser_get_font_family( let ret = imp.font_family(); if let Some(font_family) = ret { let font_family = font_family.into_glib_ptr(); + + static QUARK: OnceLock = OnceLock::new(); + let quark = + *QUARK.get_or_init(|| Quark::from_str("gtk4-rs-subclass-font-chooser-font-family")); + imp.obj().set_qdata( - *FONT_CHOOSER_GET_FONT_FAMILY_QUARK, + quark, PtrHolder(font_family, |ptr| { glib::gobject_ffi::g_object_unref(ptr as *mut _) }), @@ -253,8 +256,6 @@ unsafe extern "C" fn font_chooser_get_font_family( } } -static FONT_CHOOSER_GET_FONT_FACE_QUARK: Lazy = - Lazy::new(|| Quark::from_str("gtk4-rs-subclass-font-chooser-font-face")); unsafe extern "C" fn font_chooser_get_font_face( font_chooser: *mut ffi::GtkFontChooser, ) -> *mut pango::ffi::PangoFontFace { @@ -264,8 +265,11 @@ unsafe extern "C" fn font_chooser_get_font_face( let ret = imp.font_face(); if let Some(font_face) = ret { let font_face = font_face.into_glib_ptr(); + static QUARK: OnceLock = OnceLock::new(); + let quark = + *QUARK.get_or_init(|| Quark::from_str("gtk4-rs-subclass-font-chooser-font-face")); imp.obj().set_qdata( - *FONT_CHOOSER_GET_FONT_FACE_QUARK, + quark, PtrHolder(font_face, |ptr| { glib::gobject_ffi::g_object_unref(ptr as *mut _); }),