Skip to content

ctypes: expose frozen module tables - #1157

Merged
youknowone merged 1 commit into
mainfrom
rbigint
Aug 11, 2026
Merged

ctypes: expose frozen module tables#1157
youknowone merged 1 commit into
mainfrom
rbigint

Conversation

@youknowone

@youknowone youknowone commented Aug 11, 2026

Copy link
Copy Markdown
Owner

What changed

  • project pyre's canonical _imp frozen-module census through the three ctypes _PyImport_Frozen* ABI tables
  • route ctypes in_dll() frozen-symbol lookup through those stable process-global tables
  • classify CPython's ctypes Py_TPFLAGS_IMMUTABLETYPE assertions as CPython-only, preserving PyPy's public type.__flags__ contract
  • promote test.test_ctypes from CRASH to PASS in the CPython-suite baseline

Why

Pyre already owns a real frozen-module census in _imp, but ctypes exposed an always-empty sentinel for every _PyImport_Frozen* symbol. The compatibility view now derives names, ordering, package flags, and payload storage from the existing owner rather than maintaining a second module census.

The vendored CPython 3.14 suite also asserts CPython-specific immutable-type bits for ctypes internals. PyPy intentionally reports its own public __flags__ surface: static builtins do not gain that bit, and immutability remains enforced by the existing heap/static ownership path. Marking only those assertions cpython_only keeps the suite portable without changing runtime semantics.

CI fix

The first version added Py_TPFLAGS_IMMUTABLETYPE to every non-heap pyre type. That made synth/pypy_type_surface fail on Linux, macOS, and Windows because the fixture locks PyPy's public flag values. This revision restores the line-for-line PyPy flag calculation and limits the compatibility adjustment to the CPython-only tests.

Validation

  • PYPYLOG=jit-summary:- pypy3 pyre/bench/synth/pypy_type_surface.py
  • python3 pyre/check.py --backend dynasm --synthetic-only --synthetic-pattern pypy_type_surface.py (1/1 passed)
  • cargo check --features dynasm
  • cargo test --features dynasm
  • python3 pyre/cpython_tests/run.py --backend dynasm --filter test_ctypes --timeout 300
  • python3 pyre/cpython_tests/run.py --backend dynasm --no-jit --filter test_ctypes --full --timeout 300
  • python3 pyre/check.py --backend dynasm --no-synthetic --no-cpython-suite (17/17 passed)
  • refreshed LLBC for the default extraction set

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility when accessing frozen-module data through ctypes.
    • Fixed frozen-module metadata handling to better match CPython behavior.
    • Resolved an issue that could cause dynamic assembly-related tests to crash.
  • Tests

    • Updated platform-specific test coverage so CPython-only checks run in the appropriate environment.
    • Confirmed the affected ctypes test suite now passes successfully.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 09046b3a-2375-4fe5-860d-3fedd308b09f

📥 Commits

Reviewing files that changed from the base of the PR and between 1de6c8b and 1b36253.

📒 Files selected for processing (7)
  • lib-python/3/test/test_ctypes/test_arrays.py
  • lib-python/3/test/test_ctypes/test_simplesubclasses.py
  • lib-python/3/test/test_ctypes/test_struct_fields.py
  • lib-python/3/test/test_ctypes/test_structunion.py
  • pyre/cpython_tests/baseline.json
  • pyre/pyre-interpreter/src/module/_ctypes/cdata.rs
  • pyre/pyre-interpreter/src/module/imp/interp_imp.rs

Walkthrough

The interpreter now exposes CPython-compatible frozen-module ABI tables. cdata_in_dll uses these tables for frozen symbol resolution. Related ctypes tests run only on CPython, and the DynASM baseline changes from CRASH to PASS.

Changes

Frozen ABI and ctypes integration

Layer / File(s) Summary
Build frozen-module ABI tables
pyre/pyre-interpreter/src/module/imp/interp_imp.rs
Adds C-layout frozen entries, null-terminated tables, fallback source payloads, and lazy pointers for Bootstrap, Stdlib, and Test symbols.
Resolve frozen ABI pointers in ctypes
pyre/pyre-interpreter/src/module/_ctypes/cdata.rs
cdata_in_dll resolves frozen ABI symbols and creates address-backed CData views.
Align ctypes tests and baseline
lib-python/3/test/test_ctypes/*, pyre/cpython_tests/baseline.json
Marks CPython-specific type-flag tests with cpython_only and changes the DynASM result to PASS.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit checks the frozen tables at dawn,
While ctypes follows each pointer drawn.
CPython tests hop into place,
DynASM reports a passing trace.
ABI carrots now grow strong!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: exposing frozen module tables through ctypes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rbigint

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Ruff (0.16.1)
lib-python/3/test/test_ctypes/test_arrays.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load extended configuration /lib-python/.ruff.toml (/lib-python/3/test/.ruff.toml extends /lib-python/.ruff.toml)
�[1mCause:�[0m Failed to read /lib-python/.ruff.toml
�[1mCause:�[0m No such file or directory (os error 2)

lib-python/3/test/test_ctypes/test_simplesubclasses.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load extended configuration /lib-python/.ruff.toml (/lib-python/3/test/.ruff.toml extends /lib-python/.ruff.toml)
�[1mCause:�[0m Failed to read /lib-python/.ruff.toml
�[1mCause:�[0m No such file or directory (os error 2)

lib-python/3/test/test_ctypes/test_struct_fields.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load extended configuration /lib-python/.ruff.toml (/lib-python/3/test/.ruff.toml extends /lib-python/.ruff.toml)
�[1mCause:�[0m Failed to read /lib-python/.ruff.toml
�[1mCause:�[0m No such file or directory (os error 2)

  • 1 others

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone youknowone changed the title ctypes: expose immutable types and frozen module tables ctypes: expose frozen module tables Aug 11, 2026
@youknowone
youknowone marked this pull request as ready for review August 11, 2026 14:41
@github-actions

Copy link
Copy Markdown

🤖 Codex parity review

Static analysis of this diff vs the local RPython/PyPy sources (commit 1b36253).
Updated: 2026-08-11T14:44:16.590Z

Files in the reviewed diff
lib-python/3/test/test_ctypes/test_arrays.py
lib-python/3/test/test_ctypes/test_simplesubclasses.py
lib-python/3/test/test_ctypes/test_struct_fields.py
lib-python/3/test/test_ctypes/test_structunion.py
pyre/cpython_tests/baseline.json
pyre/pyre-interpreter/src/module/_ctypes/cdata.rs
pyre/pyre-interpreter/src/module/imp/interp_imp.rs

1. Regressions to PyPy parity introduced by this patch

None.

2. Other mismatches introduced by this patch

None.

3. Pre-existing mismatches (already present before this patch)

  • pyre/pyre-interpreter/src/module/imp/interp_imp.rs:43 ↔ pypy/module/imp/interp_imp.py:119 — Pyre’s pre-existing frozen-module list includes test modules such as __hello__; PyPy explicitly leaves test frozen modules unimplemented and returns only the essential bootstrap entries.

4. Structural adaptations

  • pyre/pyre-interpreter/src/module/_ctypes/cdata.rs:107 ↔ pypy/module/imp/interp_imp.py:110 — Pyre adds a CPython ctypes ABI path for _PyImport_FrozenBootstrap, _PyImport_FrozenStdlib, and _PyImport_FrozenTest; PyPy exposes frozen-module names as a Python list and has no equivalent exported C pointer tables.
  • pyre/pyre-interpreter/src/module/imp/interp_imp.rs:119 ↔ pypy/module/imp/interp_imp.py:125 — the Rust #[repr(C)] frozen-table projection stores source-byte payloads and leaked stable pointers, while PyPy has no _frozen ABI representation and its get_frozen_object raises. This is a CPython ABI/Rust ownership adaptation, not a faulty direct port.
  • lib-python/3/test/test_ctypes/test_arrays.py:27 ↔ pypy/objspace/std/typeobject.py:1310; lib-python/3/test/test_ctypes/test_simplesubclasses.py:24 ↔ pypy/objspace/std/typeobject.py:1310; lib-python/3/test/test_ctypes/test_struct_fields.py:167 ↔ pypy/objspace/std/typeobject.py:1310; lib-python/3/test/test_ctypes/test_structunion.py:80 ↔ pypy/objspace/std/typeobject.py:1310 — marking CPython ctypes type-flag assertions @cpython_only correctly excludes CPython C-API flag-layout expectations from Pyre/PyPy-style type objects.
  • pyre/cpython_tests/baseline.json:289 ↔ pypy/module/imp/interp_imp.py:110 — changing the local CPython-suite result from CRASH to PASS is recorded test metadata, not an RPython/PyPy source-port semantic change.

@youknowone
youknowone merged commit 2bb2aa2 into main Aug 11, 2026
17 of 18 checks passed
@youknowone
youknowone deleted the rbigint branch August 11, 2026 14:46
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.

1 participant