Commit Graph

140 Commits

Author SHA1 Message Date
anth64 4250f91969 feat(stk.h, module, stk): improve dependency failure logging
- Add STK_MOD_DEP_LOG_BUFFER (2048) to stk.h for the dep failure message
buffer size.

- Add stk_log_dependency_failures(index, action) to module.c. Walks all
deps for the given module, skips satisfied ones, and builds a single
log line listing every unmet dep with its reason: "not found" or
"requires <constraint>, have <version>". The action parameter
("Deferring" / "Unloading") lets call sites produce contextually
appropriate messages:

  - Deferring 'test_mod_dep': unmet deps: test_mod (not found)
  - Unloading 'test_mod_dep': unmet deps: test_mod (not found), renderer (requires ^2.0.0, have 1.3.0)

- Replace the silent defer at init and the vague "unmet dependencies"
cascade log in stk_poll() with calls to stk_log_dependency_failures().
2026-03-07 11:34:23 +01:00
anth64 42a96f2bc0 feat(module, stk): dependency ordering, cascade unload, and pending queue
- Refactor the Kahn topological sort into a generic stk_kahn_sort() that
accepts a has_dep callback and an on_cycle callback, eliminating direct
coupling to stk_modules. stk_topo_sort() becomes a thin wrapper using
stk_loaded_has_dep() and stk_log_cycle(). stk_sort_load_order() uses the
same core via stk_batch_has_dep(), which opens tmp files to inspect deps
so simultaneous load events are processed dependency-first without needing
a retry cycle.

- Split stk_module_load() into stk_module_preload(), stk_module_activate(),
stk_module_discard(), and stk_validate_dependencies_single(). preload
handles library loading and metadata only; activate calls init; discard
cleans up without calling shutdown; validate_dependencies_single checks a
single module's deps. stk_module_load() composes these in order and does
not call init if deps are unmet.

- On UNLOAD events in stk_poll(), expand the unload set to include all
transitively dependent loaded modules via stk_collect_dependents(), sort
dependents-first via stk_sort_unload_order(), and unload in that order.
Modules unloaded due to expansion are queued to pending so they reload
automatically when their dependency returns. Remove trim_arrays, now
handled by the compact pass after the unload block.

- On LOAD events with unmet dependencies, add the tmp path to the pending
queue instead of dropping the module. stk_pending_retry() skips already
loaded entries and prunes entries whose file no longer exists. Move the
free_poll label above stk_pending_retry() so retry always runs regardless
of which path exits the event processing block.
2026-03-07 09:38:46 +01:00
anth64 55fcc019e4 chore(CHANGELOG.md): add v1.0.0-pre.2 entry v1.0.0-pre.2 2026-03-06 22:44:04 +01:00
anth64 5d758c2998 fix(module.c): validate dependencies before calling init in stk_module_load 2026-03-06 22:41:31 +01:00
anth64 2e2c3d5e9e feat: phase 1 complete - dependency system, cascade unload, pending queue (v1.0.0-pre.1) v1.0.0-pre.1 2026-03-06 22:13:35 +01:00
anth64 6477cde367 feat(module.c, stk.c): implement pending queue and cascade dependency resolution 2026-03-06 07:52:34 +01:00
anth64 4f4ae80a14 test: add test_mod_dep build targets and update test_mod with metadata 2026-03-05 00:10:06 +01:00
anth64 8e9007fdfe refactor(module.c, stk.c): reorder stk_mod_t fields largest to smallest 2026-03-04 23:37:15 +01:00
anth64 6e8df4e0e1 feat(stk.c): add module metadata logging on init, load, reload, and unload 2026-03-04 07:46:29 +01:00
anth64 f4c76f7b5a feat(module.c): log all dependency validation failures before returning error 2026-03-03 23:10:46 +01:00
anth64 5e7b41ab68 feat(module.c): log offending modules on circular dependency detection 2026-03-03 23:03:46 +01:00
anth64 9a4b5ee9ef refactor(stk.h, module.c, stk.c): switch deps to exported array and clean up types
- Move stk_dep_t to public header
- Rename stk_set_module_dependencies_fn to stk_set_module_deps_sym
- Change default deps symbol name from stk_mod_dependencies to stk_mod_deps
- Read deps as direct exported stk_dep_t array instead of function call
- Update sentinel check to .id[0] != '\0'
- Default module version to 0.0.0 if not provided or invalid
- Remove deps_func from union in stk_module_load
2026-03-03 22:53:37 +01:00
anth64 ceb389de0d feat(module.c, stk.c): expose dependency functions and integrate into init and poll
- Make stk_validate_dependencies and stk_topo_sort non static
- Add extern declarations in stk.c
- Run stk_validate_dependencies after module loads in stk_init
- Validation failure is fatal; unload all modules and return error code
- Run stk_topo_sort after validation, sort failure is logged but not fatal
- Add validate_deps label in stk_poll so all load/unload paths run validation
- Add dep error codes to stk_error_string
2026-03-03 22:29:59 +01:00
anth64 6faf33d944 feat(module.c): add topological sort with cycle detection 2026-03-03 22:21:04 +01:00
anth64 46f0f31ed7 feat(module.c): add dependency validation pass 2026-03-03 22:09:24 +01:00
anth64 e48d5f0d5b feat(module.c): add internal version parsing and constraint validation 2026-03-03 21:59:45 +01:00
anth64 dc014292cb refactor(module.c, stk.c): replace parallel arrays with stk_mod_t struct
- Consolidate handles, function pointers, metadata, and deps into single stk_mod_t
- Remove all separate metadata arrays and index mappings
- Simplify init, free, realloc, load, and unload significantly
- stk.c externs reduced to stk_modules and module_count
2026-03-03 21:42:43 +01:00
anth64 cb7c43f8af feat(module.c): add stk_dep_t struct and dependency arrays 2026-03-03 21:23:57 +01:00
anth64 6bddc6a888 refactor(module.c): extract common setter logic into stk_set_fn_name helper 2026-03-03 21:06:37 +01:00
anth64 7d23ddbc11 feat(module.c): add stk_mod_dependencies setter and default symbol name 2026-03-03 20:50:52 +01:00
anth64 9aba1a9ad8 docs(readme): add missing module metadata function documentation 2026-03-02 22:02:39 +01:00
anth64 d344e9bbd3 feat(stk.h): add dependency management defines and callbacks
Add error codes for dependency failures, constraint operators,
and setter for custom dependencies symbol name.
2026-03-02 21:53:58 +01:00
anth64 33de5e981e docs(README): update project status to 0.1.3 2026-02-26 07:37:54 +01:00
anth64 aefd962baf chore: bump version to 0.1.3 v0.1.3 2026-02-25 22:45:58 +01:00
anth64 983f9b7393 feat(module.c): add optional module metadata support
- Add tight-packed arrays with index mappings for name, version, and description
- Resolve optional metadata symbols at load time via platform_get_symbol
- Add setter functions for metadata symbol name overrides
2026-02-25 22:31:22 +01:00
anth64 13067902a8 feat: add buffer constants and setters for optional module metadata 2026-02-25 21:37:05 +01:00
anth64 345cd35f19 chore: bump version to 0.1.2 v0.1.2 2026-02-15 23:05:18 +01:00
anth64 c2b9571c2d fix(platform,core,test): fix Windows compatibility issues
- platform_mkdir now checks if directory exists before creating
- Add FILE_ATTRIBUTE_HIDDEN for dot-prefixed directories on Windows
- Create parent mods directory before temp directory
- Move module unload before copy in reload sequence to fix issue on Windows
- Force CMD shell in test makefile on Windows

Test makefile now uses cmd.exe instead of bash on Windows, fixing
syntax errors when running via build.bat.
2026-02-15 22:53:12 +01:00
anth64 3f7f216c92 chore: bump version to 0.1.1 and update documentation v0.1.1 2026-02-14 17:25:20 +01:00
anth64 70d50dda92 fix(logging): correct log level severity order
Reverse enum so lower values = less severe, higher = more severe.
This makes the filter check (level < min_log_level) work correctly.

- DEBUG (0) - least severe, filtered by default
- INFO (1) - default minimum level
- WARN (2) - warnings and above
- ERROR (3) - most severe, always shown

Fixes incorrect filtering where ERROR/WARN were being blocked.
2026-02-14 17:22:39 +01:00
anth64 70e9ec2fc3 chore: bump version to 0.1.0 and update documentation
- Update stk_version.h: 0.0.4 → 0.1.0
- Add CHANGELOG entry for 0.1.0 release
  - C89 compliance fixes
  - Flags bitfield system
  - Enhanced logging system
- Update README project status and API reference
- Document new logging functions and configuration
v0.1.0
2026-02-14 17:06:50 +01:00
anth64 110b7ffca8 feat(logging)!: add enhanced logging system
BREAKING CHANGE: stk_log() signature changed to require log level

- Add log levels (ERROR, WARN, INFO, DEBUG) with runtime filtering
- Add timestamps (yyyy-mm-dd HH:MM:SS.mmm format)
- Add stk_set_log_output(), stk_set_log_prefix(), stk_set_log_level()
- Platform-specific timestamp: GetLocalTime (Windows), gettimeofday (POSIX)
- Consolidate duplicate platform includes into POSIX common block
- Setting log output to NULL disables logging.

Default: INFO level, "stk" prefix, stdout output. All internal messages
use appropriate severity levels. Single byte flag controls enable/disable.
2026-02-14 16:59:56 +01:00
anth64 26fb19a7f5 feat(core): add flags bitfield system
- Replace stk_initialized with stk_flags bitfield
- Add STK_FLAG_INITIALIZED (0x01) and STK_FLAG_LOGGING_ENABLED (0x02)
- Add stk_set_logging_enabled() and stk_is_logging_enabled() API
- Single byte for all boolean state and settings

Logging enabled by default, packs all flags into one byte for efficiency.
2026-02-14 12:39:13 +01:00
anth64 bcb1795218 fix(core)!: enforce strict C89 compliance
BREAKING CHANGE: Public API now uses unsigned char instead of uint8_t

- Remove stdint.h dependency (C99 feature, not C89, I am a fucking idiot)
- Replace uint8_t with unsigned char throughout codebase
- Affects stk_init() return type and internal functions
- Corrects unintended C99 dependency, restoring intended C89 compliance
2026-02-14 11:41:41 +01:00
anth64 fb0d8adb8f chore: bump version to 0.0.4 v0.0.4 2026-02-11 00:22:59 +01:00
anth64 2c4d27f915 fix(linux): prevent segfault from invalid module indices during rapid reloads
When spamming file changes rapidly, inotify can report stale UNLOAD/RELOAD
events for modules that were already unloaded by previous events in the same
poll cycle. This caused is_mod_loaded() to return -1, which was then cast to
size_t (18446744073709551615) and used as an array index, causing segfaults.

Additionally, event counts were calculated before validation, causing loops to
run more iterations than valid indices were populated, reading garbage values.

Changes:
- stk.c: Check if is_mod_loaded() returns valid index (>= 0) before adding
  to unload/reload lists
- stk.c: Reset and recalculate counts after populating arrays with only valid
  indices to prevent loop overrun
- Skip processing events for modules that are no longer loaded

This completes the Linux stability fixes started in v0.0.2.
2026-02-11 00:17:33 +01:00
anth64 96fb957991 chore: bump version to 0.0.3 v0.0.3 2026-02-09 23:03:35 +01:00
anth64 0cbee45ad2 fix(platform): replace strncpy with memmove to silence -Wrestrict warning 2026-02-09 22:53:42 +01:00
anth64 142a61a843 chore: bump version to 0.0.2 v0.0.2 2026-02-09 22:32:55 +01:00
anth64 f83f2051ef fix(linux): prevent segfaults during rapid module reloads
Fixes multiple issues causing segfaults when hot-reloading modules
on Linux, particularly when file changes are detected rapidly:

- Enable is_file_ready() check on Linux to prevent loading partially-written
  shared libraries (previously only used on Windows/BSD)
- Fix event deduplication on Linux to actually remove duplicate inotify events
  instead of just marking them, preventing double-free on same module
- Reorder reload operations to unload old module only after successfully
  copying new version, avoiding invalid state when copy fails

Changes:
- platform.c: Remove __linux__ guards around is_file_ready() function
- platform.c: Add compaction step after deduplication to remove -1 entries
- stk.c: Move module unload to after platform_copy_file() in reload loop

These changes make Linux hot-reload as robust as Windows/BSD implementations.
2026-02-09 22:25:02 +01:00
anth64 043fea6092 fix(install): install headers to stk/ subdirectory for proper namespacing
- Install headers to /include/stk/ instead of /include/
- Update README examples to use #include <stk/stk.h>
- Update Windows install instructions to reflect stk/ directory structure
- Add MPL-2.0 license badge to README
- Clarify DLL can be placed in binary or lib directory on Windows

This prevents header name collisions with other libraries and follows
standard library distribution conventions (similar to SDL).
Users now include stk headers as <stk/stk.h> rather than <stk.h>.
v0.0.1
2026-02-02 22:52:44 +01:00
anth64 96a3d80e60 docs: add comprehensive usage examples and API reference to README 2026-02-01 12:07:51 +01:00
anth64 e0ee9226e7 chore: bump version to 0.0.1 2026-02-01 11:42:39 +01:00
anth64 761f6fdc02 docs: add changelog for 0.0.1 release 2026-02-01 11:22:46 +01:00
anth64 64f7260b3a feat(build): add install and uninstall targets for Unix systems
- Add PREFIX, LIBDIR, and INCDIR variables (default: /usr/local)
- Implement install target that builds release and installs to system paths
- Implement uninstall target to cleanly remove installed files
- Support custom install locations via PREFIX variable
- Add helpful message on Windows directing users to manual installation

Both gmake.mk and bmake.mk now support standard installation workflow
on Unix-like systems (Linux, BSD, macOS). Windows users are instructed
to copy files manually as per platform conventions.

Usage:
  make install              # Install to /usr/local (requires root)
  make PREFIX=$HOME install # Install to custom location
  make uninstall            # Remove installed files
2026-02-01 11:19:02 +01:00
anth64 28dfc89b15 fix(platform): correct filename buffer handling and prevent overflows
- Replace undefined 'len' variable references with 'name_len'
- Add explicit null terminators after memcpy operations
- Move name_len declaration to Windows-specific scope to eliminate unused variable warning on BSD
- Standardize string copy pattern across all platforms: strlen -> clamp -> memcpy -> null terminate
- Fix increment operator placement for clarity (i++ moved outside array indexing)
- Remove duplicate name_len declaration in platform_directory_watch_check

This ensures proper bounds checking and null termination for filenames
on both Windows and BSD systems, preventing potential buffer overflows
when handling long filenames (approaching STK_PATH_MAX).
2026-02-01 02:38:45 +01:00
anth64 1919287c39 fix(test): ensure Windows compatibility in test suite
- Add OS detection for Windows vs Unix platforms
- Handle .exe extension on Windows for test program
- Fix directory creation with Windows-native commands (mkdir/copy vs mkdir -p/cp)
- Update clean target to use appropriate commands per platform
- Set PATH environment for DLL loading on Windows
- Remove broken uname detection that fails on Windows
2026-02-01 01:41:03 +01:00
anth64 dc30ce5366 fix: cast size_t to unsigned long in printf format specifiers
Prevent potential format string mismatches on platforms where
size_t and unsigned long may have different sizes by explicitly
casting size_t variables to unsigned long when using %lu format
specifier in printf calls.
2026-02-01 01:39:01 +01:00
anth64 11d8c5cd46 fix(platform): fix string truncation warnings on Windows
Replace strncpy with memcpy+nullterm to handle Windows MAX_PATH (259) vs
STK_PATH_MAX (256) mismatch.
2026-02-01 01:35:05 +01:00
anth64 c514b09be9 fix(build): correct release library output path on BSD systems 2026-01-31 23:30:56 +01:00