Fix ref-count underflow, PSP timezone units, thread restart race, color codegen

- util/ref.c: refUnlock's assert(count >= 0) on an unsigned count was
  tautological, so a double-unlock silently underflowed to UINT32_MAX
  instead of asserting. Now asserts count > 0 before decrementing.
- duskpsp/time/timepsp.c: timeGetRealTimeZonePSP returned hours while
  every other platform (and timeepoch.c's math) expects seconds.
- thread.c: threadHandler reset threadId outside the mutex, after
  signaling STOPPED, letting a caller's immediate threadStart() race
  threadStartRequest()'s "thread id not 0" assert. threadId is now
  reset inside the same locked section.
- tools/color.py: whole-number CSV channels (0, 1) produced invalid C
  float literals (0f, 1f) for the generated COLOR_*_3F/_4F macros.
  Route through float() so they always stringify with a decimal point.

Also adds .claude/code-check.md: a full review pass over every
subsystem in src/dusk/, with the above (plus several other findings
not yet acted on) written up in detail.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 15:02:17 -05:00
parent df9fdf26c8
commit 56230dd340
8 changed files with 927 additions and 23 deletions
+11 -10
View File
@@ -69,19 +69,20 @@ static void test_thread_data(void **state) {
}
static void test_thread_restart(void **state) {
// A thread can be started, stopped, and started again.
// A thread can be started, stopped, and started again on the same
// thread_t -- without re-calling threadInit() -- because threadId is
// reset under stateMutex before threadHandler() signals STOPPED, so
// threadStop() returning guarantees threadStartRequest()'s "thread id
// not 0" assert won't race against it. Looping a few times gives any
// regression of that ordering repeated chances to hit the window.
thread_t thread;
threadInit(&thread, helper_noop);
threadStart(&thread);
threadStop(&thread);
assert_int_equal(thread.state, THREAD_STATE_STOPPED);
// Re-initialise so threadId / state are reset, then start again.
threadInit(&thread, helper_noop);
threadStart(&thread);
threadStop(&thread);
assert_int_equal(thread.state, THREAD_STATE_STOPPED);
for(int32_t i = 0; i < 20; i++) {
threadStart(&thread);
threadStop(&thread);
assert_int_equal(thread.state, THREAD_STATE_STOPPED);
}
}
// --- threadmutex_t tests ---