Skip to content

Conversation

@jenshannoschwalm
Copy link
Collaborator

We don't want the global control struct to be exposed before all internal stuff like mutexes has been set up.

@jenshannoschwalm jenshannoschwalm added this to the 5.4.1 milestone Dec 31, 2025
@jenshannoschwalm jenshannoschwalm added the bugfix pull request fixing a bug label Dec 31, 2025
@jenshannoschwalm jenshannoschwalm force-pushed the late_control_setting branch 2 times, most recently from 0369d74 to f74035d Compare January 1, 2026 08:54
@jenshannoschwalm
Copy link
Collaborator Author

@TurboGit

  1. I don't think there is a reality chance for a race condition because of setting darktable.control too early but still correct and safe
  2. As we don't really know yet if the gtk main loop is even reached we might want to know that for debugging

@dterrahe
Copy link
Member

dterrahe commented Jan 1, 2026

First of all, obviously this doesn't hurt. But I'd argue if something is trying to use control at this early stage that is a bug. We should not just prevent it from accessing it, we should fix the order things are initialised. Because all of this is being set up in the main thread so there shouldn't be any concurrency yet.

So if in dt_control_running we find that darktable.control == NULL that should be reported as an error and fixed. If need be, dt_control_init can be moved earlier in dt_init. So making this more "robust" means papering over bugs and thereby making it harder to find and fix them.

Agree/disagree?

EDIT: is there an active bug that this fixes? It may still benefit from a better fix?

@jenshannoschwalm
Copy link
Collaborator Author

Agree/disagree?

I (generally) think, if an allocated struct is made public, that should be done after initializing that struct.

But:

  1. Agreed, a bug should be fixed elsewhere.
  1. Agreed, there is no bug - i am aware of - "fixed" by this

@jenshannoschwalm jenshannoschwalm removed this from the 5.4.1 milestone Jan 1, 2026
@jenshannoschwalm jenshannoschwalm removed the bugfix pull request fixing a bug label Jan 1, 2026
@jenshannoschwalm jenshannoschwalm marked this pull request as draft January 1, 2026 13:58
@jenshannoschwalm
Copy link
Collaborator Author

@dterrahe "drafted" but added more code trying to locate a problem in dt_control_running. Here still not a single reproducer ...

@dterrahe
Copy link
Member

dterrahe commented Jan 1, 2026

What we often do when we want a function to print more debug info (and what imho is better) is to make it a macro that calls an "internal" function variant _with_caller and passes it __FUNCTION__ (and possibly also __FILE__ and __LINE__). This is more flexible, faster to use, guaranteed to be "in synce" with any naming changes and doesn't require any further changes besides the header and function implementation.

@wpferguson
Copy link
Member

__FUNCTION__, __FILE__, and __LINE__ are already defined somewhere because I use them in fprintf statements when debugging...

@dterrahe
Copy link
Member

dterrahe commented Jan 1, 2026

They're builtins.

What I meant is, #define dt_control_running dt_control_running_with_caller (__FUNCTION__, __FILE__, __LINE__)

1. Set darktable.control after initializing the dt_control_t struct
   as we don't want the global control struct to be exposed before mutexes has been set.
2. Removed superfluous code as struct elements are already set by calloc.
3. last_expose_time in control is not used at all so it was removed
4. Simplified dt_control_cleanup()
5. Leave a note in log about starting/ending gtk_main()
6. If dt_control_running() is used without the global darktable.control being set, that
   we be a bug, so we report it.
@jenshannoschwalm
Copy link
Collaborator Author

Yeah, stupid me not doing that :-) force-pushed updated code with macro-reporting and some cleanup.

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.

3 participants