Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

Implements the first C extension in foamlib by migrating the performance-critical _skip function from Python to C. This function is called extensively during OpenFOAM file parsing to skip whitespace and comments.

Changes

C Extension Module (src/foamlib/_c/skip.c)

  • Implements _skip function in C with identical semantics to Python version
  • Handles whitespace and both comment types (// and /* */)
  • Properly raises FoamFileDecodeError for malformed input

Build System (pyproject.toml)

  • Migrated from uv_build to setuptools.build_meta backend to support C extensions
  • Configured extension module under [tool.setuptools.ext-modules]
  • Package remains buildable with uv build

Integration

  • Updated _parser.py to import C implementation
  • Added type stub file (_skip.pyi) for type checking
  • Added test suite for C extension (tests/test_c_extensions.py)

Usage

The change is transparent to callers - no API changes:

from foamlib._files._parsing._parser import _skip

# Same interface, now backed by C
pos = _skip(b"  /* comment */  data", 0)

This establishes the pattern for migrating additional parser functions to C.

Original prompt

Move the _skip function from the _parser module to a new C extension module, as the first of many functions to be translated to C


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Move _skip function to new C extension module Move _skip function to C extension module for performance Dec 17, 2025
Copilot AI requested a review from gerlero December 17, 2025 05:27
@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.72%. Comparing base (5fbadb9) to head (eda51f9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   84.67%   84.72%   +0.04%     
==========================================
  Files          27       27              
  Lines        3315     3286      -29     
==========================================
- Hits         2807     2784      -23     
+ Misses        508      502       -6     

☔ View full report in Codecov by Sentry.
📢 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.

@gerlero gerlero closed this Dec 17, 2025
@gerlero gerlero deleted the copilot/move-skip-function-to-c-extension-again branch December 17, 2025 08:28
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