Skip to content

Commit

Permalink
Ensure the stemmer fully loads the init locale once
Browse files Browse the repository at this point in the history
Since stemmer->current_lang is initialized before calling
as_stemmer_reload, this first call to as_stemmer_reload is
avoided. So, the stemmer has not been reloaded after the
initialization finishes.

This modification initializes stemmer->current_lang to NULL
explicitely, but then the call to as_stemmer_reload makes sure the
field is non-NULL at the end of the initialization function.
  • Loading branch information
ZLghkA committed Nov 15, 2023
1 parent d0bd9be commit 879266d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/as-stemmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ 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);
stemmer->current_lang = NULL;
as_stemmer_reload (stemmer, locale);
#endif
}

Expand All @@ -99,7 +99,8 @@ 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 (stemmer->current_lang != NULL
&& as_str_equal0 (lang, stemmer->current_lang)) {
g_mutex_locker_free (locker);
return;
}
Expand Down

0 comments on commit 879266d

Please sign in to comment.