tools/shader_carve_accel: release non-readonly/empty buffer pins and guard native fallback #1869
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1869"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T13:43:23Z.
Claimed in the coordination issue as: SHADER-CARVE-ACCEL-SAFETY-AND-UNIT-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164153026)
What and why
path.is_file()before callingctypes.CDLLin_load_native()(tools/shader_carve_accel.py) so a missing optional native binary returnsNonecleanly.false,off, andno(case-insensitive, stripped) identically to0forLEONIDA_SHADER_CARVE_NATIVE.Py_bufferpin inentry_search()whennot view.readonly,view.len <= 0, ornot view.bufso writable (bytearray/ writablemmap) and empty buffers do not stay pinned on fallback, and guardfinallycleanup against double-release.isinstance(pos, int) and not isinstance(pos, bool) and 0 <= pos < view.lenbefore invoking nativescan, and also catchTypeError/OverflowErrorwhen falling back cleanly toreference(pos).tests/test_shader_carve_accel.py.Tested
python -I tests/test_shader_carve_accel.py -v->Ran 4 tests in 0.015s(OK);python -I tests/test_shader_carve.py -v->Ran 31 tests in 1.434s(OK);python -I tests/test_shader_carve_native.py -v->Ran 3 tests in 0.016s(OK (skipped=1),NativeParityTestskipped because the optional compiled native library is not present on this host).upstream/main5e95fa2fwithtests/test_shader_carve_accel.pycopied into detached worktree):Ran 4 tests in 0.012s(FAILED (failures=6, errors=2)).python -I tests/test_ci_registration.py(Ran 16 tests in 5.145s,OK),python -I tests/test_text_write_line_endings.py(Ran 3 tests in 12.917s,OK),python -I scripts/check_no_game_data.py(exit 0),python -I -m compileall -q(exit 0),git diff --check(exit 0).GPUs tested: n/a (Py_buffer lifetime, fallback, and native-scanner safety unit tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T14:08:50Z.
Tested
7e38f9b24on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmain71a769d7d(Python shader tool; no GPU):tests/test_shader_carve_accel.py: 4 passed, 14 subtests passed at this head.main: 8 failed, 1 passed — theis_file()/native-library load guard, thefalse/off/noenv handling and the native-fallback cases are new tests.AI-assisted; synthetic fixtures only, no game data.
Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:32:09Z.
Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.
python -m pytest -q tests/test_shader_carve_accel.py:tools/shader_carve_accel.py: 8 failed, 1 passed. So the tests catch the problem, and the tool change fixes it on Windows.(AI-assisted test run; output checked by hand.)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T17:11:51Z.
Review: COMMENTED
Independent test report (Windows 11, Python 3.14, origin/main + PR head).
Verdict: LGTM (one optional nit)
New tests/test_shader_carve_accel.py: 4 tests, 14 subtests, all pass on the PR head (file absent on main). Mutation check: PR tests against the pre-PR tools/shader_carve_accel.py gives 8 failed (5 disable-env subtests, missing-DLL CDLL call, validation/fallback/release test, writable+empty release test), so the tests do catch the fixed behaviours.
No Windows-specific failure: the tests mock
_load_native, so no native DLL is needed; the missing-file guard returns None before CDLL.Nit: the
releasedflag looks redundant. The early release (line 64) setsrelease = Noneand falls back toreferencebefore the try/finally, and the finally block runs once per generator, sorelease is not Nonealready prevents a double release.AI-assisted: yes (Claude Code ran the tests; I read them).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:16:40Z.
Red/green: On main test_shader_carve_accel.py has 6 failures and 2 errors (buffer pins not released, native loader called despite the disable variable), and with the PR all 4 tests pass on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:55:31Z.
Verified by OreoFR
3408969a7+ PR head7e38f9b24python -I tests/test_shader_carve_accel.pyAI-assisted (Claude Code, Claude Opus 5.5).