Skip to content

Handle missing libc during fallocate setup - #351

Open
CodingFeng101 wants to merge 6 commits into
graphite-project:masterfrom
CodingFeng101:codex/missing-libc-fallocate
Open

Handle missing libc during fallocate setup#351
CodingFeng101 wants to merge 6 commits into
graphite-project:masterfrom
CodingFeng101:codex/missing-libc-fallocate

Conversation

@CodingFeng101

Copy link
Copy Markdown

Summary

  • avoid calling ctypes.CDLL(None) when ctypes.util.find_library('c') cannot locate libc
  • disable fallocate support in that case so whisper can still be imported and used without sparse preallocation
  • add a regression test that reloads the module with libc lookup mocked as missing

Why

On Windows, ctypes is available but ctypes.util.find_library('c') returns None. The module currently treats ctypes import success as enough to enable fallocate setup, then calls ctypes.CDLL(None), which raises during import before callers or tests can use any other whisper functionality.

Verification

  • python -m unittest test_whisper.TestWhisper.test_fallocate_disabled_when_libc_missing
  • python -m unittest test_whisper.TestWhisper.test_validate_archive_list test_whisper.TestParseRetentionDef
  • python -m py_compile whisper.py test_whisper.py
  • python -m flake8 whisper.py test_whisper.py
  • git diff --check

I also ran python test_whisper.py on Windows. It now gets past the original import failure and runs tests, then hits existing Windows lock-path failures because test_lock enables LOCK where fcntl is unavailable.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 56.75676% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.67%. Comparing base (f4721ac) to head (0b4a843).
⚠️ Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
whisper.py 50.00% 8 Missing and 3 partials ⚠️
test_whisper.py 66.66% 4 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
- Coverage   87.83%   87.67%   -0.17%     
==========================================
  Files           2        2              
  Lines        1143     1160      +17     
  Branches      191      142      -49     
==========================================
+ Hits         1004     1017      +13     
- Misses         99      103       +4     
  Partials       40       40              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Whisper’s optional fallocate initialization to avoid import-time crashes when ctypes.util.find_library('c') can’t locate libc (notably on Windows), and adds a regression test to ensure fallocate is disabled in that scenario.

Changes:

  • Guard fallocate setup so ctypes.CDLL(...) is not called when libc can’t be located, disabling fallocate support instead.
  • Add a regression test that reloads whisper with libc lookup mocked as missing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
whisper.py Adds a libc lookup guard to disable fallocate when libc cannot be found.
test_whisper.py Adds a reload-based regression test for the “missing libc” fallocate-disable behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread whisper.py Outdated
Comment on lines +69 to +74
if libc_name is None:
CAN_FALLOCATE = False
else:
libc = ctypes.CDLL(libc_name)
c_off64_t = ctypes.c_int64
c_off_t = ctypes.c_int

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in 94680e4 by catching OSError from ctypes.CDLL(...) and disabling fallocate support while leaving fallocate as None.

Comment thread test_whisper.py
Comment on lines +149 to +156
def test_fallocate_disabled_when_libc_missing(self):
try:
with patch('ctypes.util.find_library', return_value=None):
reload(whisper)
self.assertFalse(whisper.CAN_FALLOCATE)
self.assertIsNone(whisper.fallocate)
finally:
reload(whisper)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in 94680e4 by guarding the test with a ctypes import check and skipping it when ctypes is unavailable.

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