mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Couple opcode/cache/stack metadata with iterator pairs, generator preambles, ordinary import packing, common constants, compiler lowering and VM/JIT consumers. Pin official source/tool hashes and retain strict raw code and marshal comparisons. Use private development magic 0xDA16 and cache tag devabi2 until serialization and Python integration are coherent. Final clean corpus matches recursive code fields in 111/111 requests; full marshal/header exactness remains 0/111. Eight existing disassembly tests remain blocked by unchanged Lib metadata. Monitoring export and frozendict/update_lib integration remain explicit follow-on gates. Validation: compiler-core 23, codegen 807, CAPI 121 (4 existing ignored), focused certified-controller pytest, release/frozen witnesses, workspace and CAPI all-target Clippy. Independent source/artifact review covers manifest ec1013591ae97b4c519f4a2c78a8200664f3479f0c5452991b5fea4d1be669ea. Assisted-by: OpenAI Codex:model identifier unavailable
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""Fail closed before importing any target CPython generator code."""
|
|
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def verify_source(root):
|
|
caches = list((root / "Tools/cases_generator").rglob("*.pyc"))
|
|
if caches:
|
|
raise ValueError(
|
|
"target generator source must be cache-free; found " + str(caches[0])
|
|
)
|
|
manifest = json.loads(Path(__file__).with_suffix(".json").read_text())
|
|
for relative, expected in manifest["files"].items():
|
|
path = root / relative
|
|
actual = hashlib.sha256(path.read_bytes()).hexdigest()
|
|
if actual != expected:
|
|
raise ValueError(f"wrong {manifest['tag']} source: {relative}: {actual}")
|
|
return manifest
|
|
|
|
|
|
def verify_import_origins(root):
|
|
manifest = json.loads(Path(__file__).with_suffix(".json").read_text())
|
|
for relative in manifest["files"]:
|
|
path = Path(relative)
|
|
if path.parent != Path("Tools/cases_generator") or path.suffix != ".py":
|
|
continue
|
|
module = sys.modules.get(path.stem)
|
|
if module is not None:
|
|
origin = getattr(module, "__file__", None)
|
|
if origin is None or Path(origin).resolve() != (root / path).resolve():
|
|
raise ValueError(
|
|
"generator dependency loaded outside pinned source: " + path.stem
|
|
)
|