1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 23:36:37 +02:00

script: track per-script theme contributions and purge on script unload

Make individual scripts the unit of ownership for theme contributions
so that loading a script that calls weechat.theme_register(...) and
later unloading it correctly removes the script's overrides.

Plugin API addition (weechat-plugin.h):

  - new function pointer t_weechat_plugin.theme_unregister_script
    delegates to core's theme_unregister_script.
  - new convenience macro weechat_theme_unregister_script(script).
  - WEECHAT_PLUGIN_API_VERSION bumped to 20260527-02.

Script API additions (plugin-script-api.{c,h}):

  - new plugin_script_api_theme_register (plugin, script, name,
    overrides) forwards to the plugin API with the script pointer
    as the contribution owner, so contributions are tracked
    per-script (not per script-language plugin).

Lifecycle wiring (plugin-script.c):

  - new file-local plugin_script_remove_themes (plugin, script)
    calls weechat_theme_unregister_script.
  - plugin_script_remove now calls it alongside the other
    plugin_script_remove_* helpers, so script-unload tears down
    everything (configs, bar items, themes, hooks).

Eight language bindings updated to call
plugin_script_api_theme_register instead of weechat_theme_register
directly, so they pass the script pointer as owner:

  - python, perl, ruby, lua, tcl, javascript, php, guile.

The behavior change is end-to-end visible only at script unload:
before, an unloaded script's theme overrides lingered in the
registry forever and would be re-applied on the next /theme apply;
after, they vanish when the script unloads. /plugin unload of an
entire script-language plugin already worked via commit 24's hook
in plugin_remove (which drops both plugin-only contributions and
their script-owned children when the language plugin itself goes
away, because the contribution's plugin pointer matches).

No new unit tests in this commit: the underlying theme_unregister_script
function is covered by TEST(CoreTheme, UnregisterByOwner), and the
remaining changes are plumbing.
This commit is contained in:
Sébastien Helleu
2026-05-27 21:16:07 +02:00
parent ca8ccf8c02
commit 133fb88d86
13 changed files with 78 additions and 11 deletions
+14
View File
@@ -1080,6 +1080,18 @@ plugin_script_free (struct t_plugin_script *script)
free (script);
}
/*
* Remove all theme contributions registered by this script.
*/
void
plugin_script_remove_themes (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script)
{
weechat_theme_unregister_script (script);
(void) weechat_plugin; /* used implicitly via the macro */
}
/*
* Remove a script from list of scripts.
*/
@@ -1101,6 +1113,8 @@ plugin_script_remove (struct t_weechat_plugin *weechat_plugin,
plugin_script_remove_configs (weechat_plugin, script);
plugin_script_remove_themes (weechat_plugin, script);
/*
* remove again all hooks created by this script (just in case new hooks
* were created by the calls above)