From 2e65586db53fdf2095b06d8e85f48ca1a060825a Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Jan 2023 11:22:10 +0000 Subject: [PATCH 1/5] wayland: remove dead, broken init --- src/wayland.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/wayland.c b/src/wayland.c index 6e569def..3c9fce93 100644 --- a/src/wayland.c +++ b/src/wayland.c @@ -4,12 +4,6 @@ struct squeek_wayland *squeek_wayland = NULL; -void squeek_wayland_init_global(struct squeek_outputs *outputs) { - struct squeek_wayland *wayland = {0}; - wayland->outputs = outputs; - squeek_wayland = wayland; -} - // The following functions only exist // to create linkable symbols out of inline functions, // because those are not directly callable from Rust From 6fd281b2148bf8fa1ce48a02db331aa0a3a1b449 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Jan 2023 11:27:14 +0000 Subject: [PATCH 2/5] Remove dead code --- eek/eek-element.c | 163 ---------------------------------------------- eek/eek-element.h | 53 --------------- src/layout.h | 1 - src/meson.build | 1 - 4 files changed, 218 deletions(-) delete mode 100644 eek/eek-element.c delete mode 100644 eek/eek-element.h diff --git a/eek/eek-element.c b/eek/eek-element.c deleted file mode 100644 index 3ede68ee..00000000 --- a/eek/eek-element.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2010-2011 Daiki Ueno - * Copyright (C) 2010-2011 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -/** - * SECTION:eek-element - * @short_description: Base class of a keyboard element - * - * The #EekElementClass class represents a keyboard element, which - * shall be used to implement #EekKeyboard, #EekSection, or #EekKey. - */ - -#include "config.h" - -#include - -#include "eek-element.h" - -enum { - PROP_0, - PROP_BOUNDS, - PROP_LAST -}; - -typedef struct _EekElementPrivate -{ - EekBounds bounds; -} EekElementPrivate; - -G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (EekElement, eek_element, G_TYPE_OBJECT) - -static void -eek_element_finalize (GObject *object) -{ - G_OBJECT_CLASS (eek_element_parent_class)->finalize (object); -} - -static void -eek_element_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EekElement *element = EEK_ELEMENT(object); - - switch (prop_id) { - case PROP_BOUNDS: - eek_element_set_bounds (element, g_value_get_boxed (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -eek_element_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EekElement *element = EEK_ELEMENT(object); - EekBounds bounds; - - switch (prop_id) { - case PROP_BOUNDS: - eek_element_get_bounds (element, &bounds); - g_value_set_boxed (value, &bounds); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -eek_element_class_init (EekElementClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - /* signals */ - gobject_class->set_property = eek_element_set_property; - gobject_class->get_property = eek_element_get_property; - gobject_class->finalize = eek_element_finalize; - - /** - * EekElement:bounds: - * - * The bounding box of #EekElement. - */ - pspec = g_param_spec_boxed ("bounds", - "Bounds", - "Bounding box of the element", - EEK_TYPE_BOUNDS, - G_PARAM_READWRITE); - g_object_class_install_property (gobject_class, - PROP_BOUNDS, - pspec); -} - -static void -eek_element_init (EekElement *self) -{ - (void)self; -} - -/** - * eek_element_set_bounds: - * @element: an #EekElement - * @bounds: bounding box of @element - * - * Set the bounding box of @element to @bounds. Note that if @element - * has parent, X and Y positions of @bounds are relative to the parent - * position. - */ -void -eek_element_set_bounds (EekElement *element, - EekBounds *bounds) -{ - g_return_if_fail (EEK_IS_ELEMENT(element)); - - EekElementPrivate *priv = eek_element_get_instance_private (element); - - memcpy (&priv->bounds, bounds, sizeof(EekBounds)); -} - -/** - * eek_element_get_bounds: - * @element: an #EekElement - * @bounds: (out): pointer where bounding box of @element will be stored - * - * Get the bounding box of @element. Note that if @element has - * parent, position of @bounds are relative to the parent. To obtain - * the absolute position, use eek_element_get_absolute_position(). - */ -void -eek_element_get_bounds (EekElement *element, - EekBounds *bounds) -{ - g_return_if_fail (EEK_IS_ELEMENT(element)); - g_return_if_fail (bounds != NULL); - - EekElementPrivate *priv = eek_element_get_instance_private (element); - - memcpy (bounds, &priv->bounds, sizeof(EekBounds)); -} diff --git a/eek/eek-element.h b/eek/eek-element.h deleted file mode 100644 index 83b1e7e5..00000000 --- a/eek/eek-element.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010-2011 Daiki Ueno - * Copyright (C) 2010-2011 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ - -#if !defined(__EEK_H_INSIDE__) && !defined(EEK_COMPILATION) -#error "Only can be included directly." -#endif - -#ifndef EEK_ELEMENT_H -#define EEK_ELEMENT_H 1 - -#include -#include "eek-types.h" - -G_BEGIN_DECLS -#define EEK_TYPE_ELEMENT (eek_element_get_type()) -G_DECLARE_DERIVABLE_TYPE (EekElement, eek_element, EEK, ELEMENT, GObject) - -struct _EekElementClass -{ - /*< private >*/ - GObjectClass parent_class; -}; - -void eek_element_set_name (EekElement *element, - const gchar *name); - -const gchar *eek_element_get_name (EekElement *element); - -void eek_element_set_bounds (EekElement *element, - EekBounds *bounds); - -void eek_element_get_bounds (EekElement *element, - EekBounds *bounds); - -G_END_DECLS -#endif /* EEK_ELEMENT_H */ diff --git a/src/layout.h b/src/layout.h index 1d77876a..9d11650f 100644 --- a/src/layout.h +++ b/src/layout.h @@ -3,7 +3,6 @@ #include #include -#include "eek/eek-element.h" #include "eek/eek-gtk-keyboard.h" #include "eek/eek-renderer.h" #include "eek/eek-types.h" diff --git a/src/meson.build b/src/meson.build index 45df867f..5041f560 100644 --- a/src/meson.build +++ b/src/meson.build @@ -19,7 +19,6 @@ sources = [ 'server-context-service.c', 'wayland.c', '../eek/eek.c', - '../eek/eek-element.c', '../eek/eek-gtk-keyboard.c', '../eek/eek-keyboard.c', '../eek/eek-renderer.c', From 8da59a621672d4f96525e6876c8d91a28000c2d2 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Jan 2023 11:40:27 +0000 Subject: [PATCH 3/5] safety: Replace strncpy with strlcpy --- eek/eek-keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eek/eek-keyboard.c b/eek/eek-keyboard.c index d2570e28..a41336e7 100644 --- a/eek/eek-keyboard.c +++ b/eek/eek-keyboard.c @@ -75,7 +75,7 @@ struct keymap squeek_key_map_from_str(const char *keymap_str) { if ((void*)ptr == (void*)-1) { g_error("Failed to set up mmap"); } - strncpy(ptr, xkb_keymap_str, keymap_len); + strlcpy(ptr, xkb_keymap_str, keymap_len); munmap(ptr, keymap_len); free(xkb_keymap_str); xkb_keymap_unref(keymap); From 20b5cac148b253cf75b6a25b380624a2340e4b8b Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Jan 2023 11:51:53 +0000 Subject: [PATCH 4/5] build: Silence overcautious warning --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 06229d51..0b99ea88 100644 --- a/src/util.rs +++ b/src/util.rs @@ -153,7 +153,7 @@ pub mod c { // A bit dangerous: the Rc may be in use elsewhere let used_rc = unsafe { Arc::from_raw(self.0) }; let rc = used_rc.clone(); - Arc::into_raw(used_rc); // prevent dropping the original reference + let _ = Arc::into_raw(used_rc); // prevent dropping the original reference rc } } From 400e82326d12e3ec20abd9aa1b4a5edeee63388d Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Sun, 15 Jan 2023 11:52:12 +0000 Subject: [PATCH 5/5] memory: Fix undefined behaviour As warned by the compiler. At the same time drop support for older rustc, as the code was dead anyway. --- src/keyboard.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/keyboard.rs b/src/keyboard.rs index 8c3f5d35..12acfc91 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -143,18 +143,17 @@ type SingleKeyMap = [Option; 256]; fn single_key_map_new() -> SingleKeyMap { // Why can't we just initialize arrays without tricks -_- ? - unsafe { - // Inspired by - // https://www.reddit.com/r/rust/comments/5n7bh1/how_to_create_an_array_of_a_type_with_clone_but/ - #[cfg(feature = "rustc_less_1_36")] - let mut array: SingleKeyMap = mem::uninitialized(); - #[cfg(not(feature = "rustc_less_1_36"))] - let mut array: SingleKeyMap = mem::MaybeUninit::uninit().assume_init(); + // Inspired by + // https://www.reddit.com/r/rust/comments/5n7bh1/how_to_create_an_array_of_a_type_with_clone_but/ + let mut array = mem::MaybeUninit::::uninit(); - for element in array.iter_mut() { + unsafe { + let arref = &mut *array.as_mut_ptr(); + for element in arref.iter_mut() { ptr::write(element, None); } - array + + array.assume_init() } }