unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob a2cf84c8b1d7d46b86ccf6592dc213d7df13d1dd 2778 bytes (raw)
name: gnu/packages/patches/appstream-force-reload-stemmer.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
From 32182d7a7a67d0d204cd0a37bd211bfd0177bc27 Mon Sep 17 00:00:00 2001
Message-ID: <32182d7a7a67d0d204cd0a37bd211bfd0177bc27.1700093066.git.vivien@planete-kraus.eu>
From: Matthias Klumpp <matthias@tenstral.net>
Date: Thu, 16 Nov 2023 00:59:15 +0100
Subject: [PATCH] stemmer: Resolve potential issue where stemmer may never be
 initialized

If the initial locale was equal to the current stemming language, we may
never have initialized the stemmer (which could lead to crashes or
stemming being disabled).

So we force the reload to always happen on initialization.
CC: #558
---
 src/as-stemmer.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/as-stemmer.c b/src/as-stemmer.c
index 63d45267..16ebd09b 100644
--- a/src/as-stemmer.c
+++ b/src/as-stemmer.c
@@ -47,6 +47,8 @@ G_DEFINE_TYPE (AsStemmer, as_stemmer, G_TYPE_OBJECT)
 
 static gpointer as_stemmer_object = NULL;
 
+static void as_stemmer_reload_internal (AsStemmer *stemmer, const gchar *locale, gboolean force);
+
 /**
  * as_stemmer_finalize:
  **/
@@ -76,21 +78,14 @@ as_stemmer_init (AsStemmer *stemmer)
 
 	/* we don't use the locale in XML, so it can be POSIX */
 	locale = as_get_current_locale_posix ();
-	stemmer->current_lang = as_utils_locale_to_language (locale);
 
-	as_stemmer_reload (stemmer, stemmer->current_lang);
+	/* force a reload for initialization */
+	as_stemmer_reload_internal (stemmer, locale, TRUE);
 #endif
 }
 
-/**
- * as_stemmer_reload:
- * @stemmer: A #AsStemmer
- * @locale: The stemming language as POSIX locale.
- *
- * Allows realoading the #AsStemmer with a different language.
- */
-void
-as_stemmer_reload (AsStemmer *stemmer, const gchar *locale)
+static void
+as_stemmer_reload_internal (AsStemmer *stemmer, const gchar *locale, gboolean force)
 {
 #ifdef HAVE_STEMMING
 	g_autofree gchar *lang = NULL;
@@ -99,7 +94,7 @@ as_stemmer_reload (AsStemmer *stemmer, const gchar *locale)
 	/* check if we need to reload */
 	lang = as_utils_locale_to_language (locale);
 	locker = g_mutex_locker_new (&stemmer->mutex);
-	if (as_str_equal0 (lang, stemmer->current_lang)) {
+	if (!force && as_str_equal0 (lang, stemmer->current_lang)) {
 		g_mutex_locker_free (locker);
 		return;
 	}
@@ -119,6 +114,20 @@ as_stemmer_reload (AsStemmer *stemmer, const gchar *locale)
 #endif
 }
 
+/**
+ * as_stemmer_reload:
+ * @stemmer: A #AsStemmer
+ * @locale: The stemming language as POSIX locale.
+ *
+ * Allows realoading the #AsStemmer with a different language.
+ * Does nothing if the stemmer is already using the selected language.
+ */
+void
+as_stemmer_reload (AsStemmer *stemmer, const gchar *locale)
+{
+	as_stemmer_reload_internal (stemmer, locale, FALSE);
+}
+
 /**
  * as_stemmer_stem:
  * @stemmer: A #AsStemmer
-- 
2.41.0


debug log:

solving a2cf84c8b1 ...
found a2cf84c8b1 in https://git.savannah.gnu.org/cgit/guix.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).