Skip to content

Group AI backend file-scope statics into named structs#21079

Merged
TurboGit merged 1 commit into
darktable-org:masterfrom
andriiryzhkov:fix_ai_backend_static
May 20, 2026
Merged

Group AI backend file-scope statics into named structs#21079
TurboGit merged 1 commit into
darktable-org:masterfrom
andriiryzhkov:fix_ai_backend_static

Conversation

@andriiryzhkov
Copy link
Copy Markdown
Collaborator

Small maintenance pass on src/ai/backend_onnx.c. No behavior change.

The file had 10 individual file-scope statics – ORT runtime, init guards, loaded module/version, and the at-load conf-snapshot variables. Regrouped into two named anonymous-struct singletons (g_ort, g_conf_snapshot) and added dt_ai_backend_cleanup_globals() to free the heap members at shutdown.

Why not move them to darktable.ai_backend

The obvious alternative – hang them off darktable_t next to darktable.ai_registry – was prototyped and walked back.

src/ai/ is built as a separate static archive with a deliberately minimal include surface. Reaching into darktable.ai_backend requires common/darktable.h, which couples the AI library to the layout of darktable_t. That layout depends on conditional flags like USE_LUA (the inline dt_lua_state_t is 4 bytes off, ~168 bytes on) and everything under #ifdef HAVE_AI. Any flag drift between the main build and the AI library produces silent ABI mismatches at field offsets.

Keeping the singletons file-local in backend_onnx.c keeps the AI library boundary clean: no darktable_t knowledge, no flag propagation. We lose per-instance lifecycle, but we always wanted exactly one ORT per process.

@andriiryzhkov andriiryzhkov added scope: codebase making darktable source code easier to manage scope: AI features AI features related issues and PR labels May 20, 2026
@andriiryzhkov andriiryzhkov added this to the 5.6 milestone May 20, 2026
@TurboGit
Copy link
Copy Markdown
Member

@andriiryzhkov : There is conflicts to be resolved. TIA.

@andriiryzhkov andriiryzhkov force-pushed the fix_ai_backend_static branch from 51ff011 to 6e74e24 Compare May 20, 2026 16:07
@andriiryzhkov
Copy link
Copy Markdown
Collaborator Author

@TurboGit : Conflicts resolved.

Comment thread src/ai/backend_onnx.c
Copy link
Copy Markdown
Member

@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good to go. Thanks!

@TurboGit TurboGit merged commit 5920a1a into darktable-org:master May 20, 2026
5 checks passed
@andriiryzhkov andriiryzhkov deleted the fix_ai_backend_static branch May 20, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: AI features AI features related issues and PR scope: codebase making darktable source code easier to manage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants