-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
The fortplot_text module contains global mutable state that violates the mandatory state management principles, creating potential thread-safety issues and making the code harder to test and maintain.
Evidence
Global mutable state found in src/fortplot_text.f90:
! Module state
type(stb_fontinfo_t) :: global_font
logical :: font_initialized = .false.
real(wp) :: font_scale = 0.0_wpThe architecture principles explicitly state:
- 'MUTABLE GLOBAL STATE IS THE SOURCE OF ALL EVIL AND MUST BE AVOIDED AT ALL COST'
- 'NO GLOBAL MUTABLE STATE - All state must be explicitly passed as parameters'
- 'STATELESS OPERATIONS - Functions should not rely on hidden global state'
Impact
- Thread-safety issues in concurrent environments
- Hidden dependencies on global state
- Difficult to test in isolation
- Potential for race conditions
- Violates functional programming principles
- Makes it impossible to have multiple font configurations
Required Fix
- Encapsulate font state in a text_context type
- Pass context explicitly to all text functions
- Initialize context at figure/backend level
- Remove all module-level mutable variables
- Make all operations pure functions with explicit parameters
Example Refactoring
type :: text_context_t
type(stb_fontinfo_t) :: font
logical :: initialized = .false.
real(wp) :: scale = 0.0_wp
end type
! Pure function with explicit context
function render_text(context, text, x, y) result(bitmap)
type(text_context_t), intent(inout) :: context
! ...
end functionMetadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working