Skip to content

Require the GLib versions the code needs - #1140

Merged
sthibaul merged 5 commits into
brailcom:masterfrom
shindere:require-glib-versions
Nov 16, 2026
Merged

sthibaul merged 5 commits into
brailcom:masterfrom
shindere:require-glib-versions

Conversation

@shindere

@shindere shindere commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

configure.ac asks for GLib 2.36, but the code needs more than that:

  • src/modules/module_utils.c passes G_REGEX_MATCH_DEFAULT to g_regex_replace. GLib introduced this name for 0 in 2.74, so the output modules do not build with an older GLib.
  • The kitten module calls g_string_new_take (GLib 2.78) in src/modules/kitten_utilities.c, and g_memdup2 (GLib 2.68) in src/modules/kitten_worker.c.
  • libspeechd hands strings allocated by GLib to callers who release them with free() (for instance the error string of spd_open2). This is only guaranteed since GLib 2.46, from which g_malloc always uses the system malloc; this came up in the review of Share the per-user socket path definition #1139.

The first commit passes 0 instead of G_REGEX_MATCH_DEFAULT, as the other GRegex calls in speechd do; 0 means no match options in every GLib version. The second makes configure require 2.46. The third builds the kitten module only with GLib 2.78 or later, like its other dependencies: it is skipped otherwise, and --with-kitten=yes fails. Requiring 2.78 everywhere would instead prevent building speech-dispatcher on Debian bookworm (2.74) for the sake of an optional module.

To find the newest GLib API in use, I built every module with GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED defined to GLIB_VERSION_2_46, which makes GLib warn about anything newer: with this PR, only kitten's calls remain. The shims do not use GLib. I also built this PR on Debian stretch (GLib 2.50), where make check passes and master fails on G_REGEX_MATCH_DEFAULT.

The last two commits keep this from happening again. The fourth makes the version check around g_memdup2 in src/common/speak_queue.c test GLIB_VERSION_MAX_ALLOWED instead of the installed GLib, which changes nothing in a normal build. The fifth adds a build-glib-min job to the CI: it reads the minimum from configure.ac, sets both macros to it, and makes deprecation warnings errors (GLib reports newer API as deprecated), so that a newer GLib API fails the build. The kitten module is left out, since it requires 2.78. On master with these two commits, the job fails on G_REGEX_MATCH_DEFAULT and on nothing else; on this PR, it passes.

@sthibaul

Copy link
Copy Markdown
Collaborator

the alternative is to replace G_REGEX_MATCH_DEFAULT with 0

Does passing 0 already have the G_REGEX_MATCH_DEFAULT meaning in the 2.46 case?

@sthibaul

Copy link
Copy Markdown
Collaborator

It'd be useful to add a build test in the github workflow for e.g. an old image to check against regressions on this.

module_utils.c passes G_REGEX_MATCH_DEFAULT to g_regex_replace, but
GLib only introduced this name in 2.74, as a name for 0, which means
no match options in all versions. Pass the literal value 0 instead,
as the other calls to the GRegex functions in speechd do.
libspeechd hands strings allocated by GLib to callers who release
them with free(), for instance the error string of spd_open2. GLib
only guarantees that this works since 2.46, from which g_malloc always
uses the system malloc. Check for that version in configure, which
used to accept 2.36.
The kitten module calls g_string_new_take
(src/modules/kitten_utilities.c), which GLib introduced in 2.78.
configure now builds the module only with that version, and fails
when --with-kitten=yes is given with an older GLib.
@shindere
shindere force-pushed the require-glib-versions branch from 176497c to ad586a8 Compare November 16, 2026 08:28
@shindere

Copy link
Copy Markdown
Contributor Author

Does passing 0 already have the G_REGEX_MATCH_DEFAULT meaning in the 2.46 case?

Yes: G_REGEX_MATCH_DEFAULT is only a name for 0, added in 2.74 (gregex.h defines it as G_REGEX_MATCH_DEFAULT GLIB_AVAILABLE_ENUMERATOR_IN_2_74 = 0 and documents it as "No special options set"). The other GRegexMatchFlags values are all single bits, so 0 has meant "no options" in every version. I have therefore switched the PR to that alternative: the first commit passes 0, as the other GRegex calls in speechd do, and the second requires GLib 2.46, the version from which free() on GLib strings is guaranteed to work. The kitten commit is unchanged.

It'd be useful to add a build test in the github workflow for e.g. an old image to check against regressions on this.

I see two ways to check this, which test different things.

The first is to build with GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED set to the minimum version, in which case GLib warns about any API newer than that. That is how I found the problems this PR fixes. It is cheap (a build option in the existing workflow, on the current runner) and checks exactly the minimum, but only for GLib. It needs one small fix first: the version check around g_memdup2 in src/common/speak_queue.c tests the installed GLib, not the limit, so it would warn too.

The second is the old image you suggest. I tried Debian stretch (GLib 2.50) in a container: with this PR, speech-dispatcher builds and make check passes, while master fails on G_REGEX_MATCH_DEFAULT. It checks more than GLib (the other dependencies, the compiler), but needs more setup: stretch is archived, and since the JavaScript actions such as actions/checkout need a newer glibc than stretch has, the job would have to build through docker run.

I would suggest adding the first to this PR, since it makes visible what used to go unnoticed, and keeping the old image for a separate PR. Would that suit you?

@sthibaul

Copy link
Copy Markdown
Collaborator

I would suggest adding the first to this PR, since it makes visible what used to go unnoticed, and keeping the old image for a separate PR. Would that suit you?

Yes, that looks good

speak_queue.c used g_memdup2 whenever the installed GLib is 2.68 or
newer. It now tests GLIB_VERSION_MAX_ALLOWED instead, which is the
installed version unless the build restricts the GLib API to an
older one: in that case it uses g_memdup, which that older GLib has.
A new job builds with GLIB_VERSION_MIN_REQUIRED and
GLIB_VERSION_MAX_ALLOWED set to the minimum GLib version that
configure.ac requires, read from configure.ac, and with deprecation
warnings made errors, so that using a newer GLib API fails the build.
The kitten module, which requires a newer GLib, is not built.
@shindere
shindere force-pushed the require-glib-versions branch from 0f4d173 to e7bb705 Compare November 16, 2026 09:37
@shindere

Copy link
Copy Markdown
Contributor Author

Thanks, done in the last two commits. The first makes the version check in src/common/speak_queue.c test GLIB_VERSION_MAX_ALLOWED instead of the installed GLib, which changes nothing in a normal build. The second adds a build-glib-min job to ci.yml: it reads the minimum from configure.ac, sets GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED to it, makes deprecation warnings errors (that is how GLib reports newer API), and leaves out the kitten module, which requires 2.78.

To check that the job catches the problem, I ran it on master with these two commits added: it fails on G_REGEX_MATCH_DEFAULT in module_utils.c, and on nothing else (https://github.com/shindere/speechd/actions/runs/43837189531). On this PR it passes (https://github.com/shindere/speechd/actions/runs/43837194389).

@sthibaul
sthibaul merged commit af73916 into brailcom:master Nov 16, 2026
8 checks passed
@sthibaul

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants