Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8b204d4
posix: give utime's unnamed time UTIME_NOW, and run ftruncate's EINTR…
youknowone Aug 7, 2026
b6fb1b3
ci: run the parity_tests step even when check.py failed
youknowone Aug 7, 2026
c9ba387
posix: name the function and the argument in path-converter type errors
youknowone Aug 7, 2026
1241d16
posix: retry sendfile's EINTR through the signal gate
youknowone Aug 7, 2026
aa7b51e
posix: bind pipe2 and the scheduling-policy calls where the libc has …
youknowone Aug 7, 2026
ca010e7
posix: bind the CPU affinity pair and the rest of the <fcntl.h> flag set
youknowone Aug 7, 2026
e114db1
posix: read cpu_count from the processor count rather than the thread…
youknowone Aug 7, 2026
dde0932
posix: register dup2 with a Signature so its keyword argument binds
youknowone Aug 8, 2026
156b193
posix: bind the arguments of nine entry points that read the raw slice
youknowone Aug 8, 2026
7f25a8d
function: read a name through the surrogate-tolerant accessor
youknowone Aug 8, 2026
6be0835
sys, pyexpat: check the name argument of audit and ParserCreate
youknowone Aug 8, 2026
9b16d0c
posix: answer os.access's three modifiers through faccessat
youknowone Aug 8, 2026
ac3df89
pyexpat: distinguish an omitted `ParserCreate` intern from an explici…
youknowone Aug 8, 2026
dd756ac
pyexpat, sys: state why the two name unwraps are the strict encode
youknowone Aug 9, 2026
3018a5d
posix: read the pid argument of seven scheduling calls through c_int_w
youknowone Aug 9, 2026
6f793c2
jit: fold the INT_MIN unary negate, pin the unary operand class, and …
youknowone Aug 9, 2026
c157a14
sys: widen the addaudithook refusal to Exception and re-wrap the audi…
youknowone Aug 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/pyre-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,15 @@ jobs:
# semantics fails here. check.py has just built the release pyre-dynasm
# and pyre-cranelift binaries the runner drives, so this costs only the
# per-script process spawns.
#
# Run it even when check.py above failed. The two gates answer different
# questions and check.py is the one that goes red on a jitstats drift
# nobody has re-recorded yet; while it does, every later step in this job
# is skipped and the parity suite reports nothing at all. Windows spent
# its whole history that way: thirteen real parity failures sat unseen
# until one run happened to get past check.py. The job still fails on
# either — this only stops one from hiding the other.
if: ${{ !cancelled() }}
env:
PYRE_CHECK_PYTHON3: ${{ steps.cpython.outputs.python-path }}
run: ${{ steps.cpython.outputs.python-path }} pyre/extra_tests/parity_tests/run.py
Expand Down
6 changes: 3 additions & 3 deletions pyre/bench/synth/unary_negative.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def main():

# UNARY_NEGATIVE on INT_MIN: -INT_MIN overflows the machine-int range, so
# descr_neg (intobject.py:628) takes the long branch and returns 2**63 as a
# W_LongObject. generated_unary_int_value declines the int fast path at the
# concrete INT_MIN operand and traces the residual long-neg, so the compiled
# loop must agree with the long result rather than wrapping back to INT_MIN.
# W_LongObject. The walker fold pins the operand with GUARD_VALUE and takes
# the _make_ovf2long tail, so the compiled loop must agree with the long result
# rather than wrapping back to INT_MIN.
def main_int_min():
m = -9223372036854775807 - 1 # INT_MIN as a machine int
acc = 0
Expand Down
269 changes: 269 additions & 0 deletions pyre/extra_tests/parity_tests/audit_and_parsercreate_name_argument.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
"""`sys.audit` and `pyexpat.ParserCreate` check the name they are handed.

`sys.audit` was registered as `|_| Ok(w_none())` — a no-op that accepted
anything, so `sys.audit()` with no event at all, with an `int`, or by keyword
all returned None. 22 stdlib modules call it (`os.walk`, `glob.glob`,
`pickle.find_class`, `subprocess`, ...), so a bad event name reached none of the
checks that upstream's `@unwrap_spec(event="text")` performs.

`ParserCreate` did check that `encoding` is `str` or `None`, but stored it
without asking whether it has a UTF-8 spelling — the sibling
`namespace_separator` arm did ask. A `str` holding a lone surrogate therefore
built a parser whose stored encoding no `&str` reader can see. The same arm
also spelled its type name as a literal `int`, so every other type was reported
as `int`.

No audit hook can be installed yet (`sys.addaudithook` stores nothing), so
`sys.audit` still does nothing past the checks below; the hook mechanism is a
separate gap. The surrogate is built from bytes rather than written as a
literal because that is how it arrives in practice and because a source file
cannot carry one.

Only one surrogate is used for the messages that are compared verbatim: a run
of adjacent unencodable code points is reported by CPython as one error with a
range (`characters in position 3-4`) and by pyre as the first one alone, which
is a separate divergence in the encoder rather than in these entry points.
"""

import sys

import pyexpat

# b'\xff' has no UTF-8 spelling in any position, so surrogateescape maps it to
# U+DCFF — what a filesystem name or an argv element yields on a host that does
# not enforce UTF-8.
SURR = b"bad\xffname".decode("utf-8", "surrogateescape")
ENCODE_ERROR = (
"'utf-8' codec can't encode character '\\udcff' in position 3: "
"surrogates not allowed"
)

ERRORS = []


def check(cond, what):
if not cond:
ERRORS.append(what)


def raises(what, exc, expected, fn):
"""Assert fn() raises `exc` whose message is exactly `expected`."""
try:
fn()
except exc as e:
check(
str(e) == expected,
f"{what}: got {str(e)!r}, expected {expected!r}",
)
return
except BaseException as e:
ERRORS.append(
f"{what}: raised {type(e).__name__}({e!r}), expected {exc.__name__}"
)
return
ERRORS.append(f"{what}: no exception, expected {exc.__name__}")


# The payload is the point of the test, so verify it before using it.
check(len(SURR) == 8, f"surrogate payload is {len(SURR)} code points, expected 8")
check(SURR.encode("utf-8", "surrogateescape") == b"bad\xffname", "payload lost its byte")


class Odd:
pass


# ── sys.audit: the event name is a str that must encode ───────────────────
raises(
"audit with no event",
TypeError,
"audit expected at least 1 argument, got 0",
lambda: sys.audit(),
)
for value, spelling in (
(123, "int"),
(1.5, "float"),
(None, "None"),
(b"x", "bytes"),
(bytearray(b"x"), "bytearray"),
((), "tuple"),
(Odd(), "Odd"),
):
raises(
f"audit({spelling})",
TypeError,
f"audit() argument 1 must be str, not {spelling}",
lambda value=value: sys.audit(value),
)
raises(
"audit with a surrogate event",
UnicodeEncodeError,
ENCODE_ERROR,
lambda: sys.audit(SURR),
)
# Every parameter is positional-only, so the event cannot be named.
raises(
"audit by keyword",
TypeError,
"sys.audit() takes no keyword arguments",
lambda: sys.audit(event="x"),
)
# ...and the accepting calls still accept, so the checks above are not passing
# because audit stopped working.
check(sys.audit("pyre.test") is None, "audit rejected a plain event name")
check(sys.audit("pyre.test", 1, 2) is None, "audit rejected trailing parameters")


class SubStr(str):
pass


check(sys.audit(SubStr("pyre.test")) is None, "audit rejected a str subclass")


# ── pyexpat.ParserCreate: both str-or-None parameters report their type ────
for value, spelling in ((123, "int"), (1.5, "float"), (b"x", "bytes")):
raises(
f"ParserCreate(encoding={spelling})",
TypeError,
f"ParserCreate() argument 'encoding' must be str or None, not {spelling}",
lambda value=value: pyexpat.ParserCreate(value),
)
raises(
f"ParserCreate(namespace_separator={spelling})",
TypeError,
f"ParserCreate() argument 'namespace_separator' must be str or None, "
f"not {spelling}",
lambda value=value: pyexpat.ParserCreate(None, value),
)

raises(
"ParserCreate with a surrogate encoding",
UnicodeEncodeError,
ENCODE_ERROR,
lambda: pyexpat.ParserCreate(SURR),
)
raises(
"ParserCreate with a surrogate separator",
UnicodeEncodeError,
ENCODE_ERROR,
lambda: pyexpat.ParserCreate(None, SURR),
)
# The encoding check runs before the separator's length check, so a too-long
# separator carrying a surrogate reports the encoding, not the length.
raises(
"ParserCreate with a long surrogate separator",
UnicodeEncodeError,
ENCODE_ERROR,
lambda: pyexpat.ParserCreate(None, SURR + "x"),
)
raises(
"ParserCreate with a two-character separator",
ValueError,
"namespace_separator must be at most one character, omitted, or None",
lambda: pyexpat.ParserCreate(None, "ab"),
)

# The accepting calls, so the checks above are not passing because
# ParserCreate stopped building parsers.
Comment on lines +167 to +168

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the comment sentence.

The sentence is incomplete. Line 111 uses the intended form. Align this one with it.

📝 Proposed wording fix
-# The accepting calls, so the checks above are not passing because
-# ParserCreate stopped building parsers.
+# ...and the accepting calls still accept, so the checks above are not passing
+# because ParserCreate stopped building parsers.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# The accepting calls, so the checks above are not passing because
# ParserCreate stopped building parsers.
# ...and the accepting calls still accept, so the checks above are not passing
# because ParserCreate stopped building parsers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pyre/extra_tests/parity_tests/audit_and_parsercreate_name_argument.py` around
lines 167 - 168, Fix the incomplete comment near the ParserCreate checks by
aligning its wording with the intended sentence form used near line 111, while
preserving the existing meaning about accepting calls and ParserCreate no longer
building parsers.

check(
type(pyexpat.ParserCreate()).__name__ == "xmlparser",
"ParserCreate() no longer builds a parser",
)
check(
type(pyexpat.ParserCreate("utf-8")).__name__ == "xmlparser",
"ParserCreate('utf-8') no longer builds a parser",
)
check(
type(pyexpat.ParserCreate(encoding="utf-8")).__name__ == "xmlparser",
"ParserCreate(encoding=) no longer binds",
)
check(
type(pyexpat.ParserCreate(None, ":")).__name__ == "xmlparser",
"ParserCreate with a separator no longer builds a parser",
)
check(
type(pyexpat.ParserCreate(SubStr("utf-8"))).__name__ == "xmlparser",
"ParserCreate rejected a str subclass encoding",
)


# ── an omitted `intern` is not the same as an explicit None ───────────────
# Omitting it asks for a fresh dictionary; passing None asks for no interning
# at all. A default of `None` cannot tell the two apart, and the parser then
# interns names the caller asked it not to.
def interned(parser):
"""The number of names `parser` interned while parsing, or None."""
parser.StartElementHandler = lambda name, attrs: None
parser.Parse("<a><b/></a>", True)
return None if parser.intern is None else len(parser.intern)


check(
isinstance(pyexpat.ParserCreate().intern, dict),
"an omitted intern did not produce a dictionary",
)
check(interned(pyexpat.ParserCreate()) == 2, "an omitted intern interned nothing")
check(
pyexpat.ParserCreate(None, None, None).intern is None,
"an explicit intern=None was replaced with a dictionary",
)
check(
interned(pyexpat.ParserCreate(None, None, None)) is None,
"an explicit intern=None still interned names",
)
# A dictionary of the caller's own is used as given.
own = {}
p = pyexpat.ParserCreate(None, None, own)
check(p.intern is own, "a supplied intern dictionary was not the one used")
check(interned(p) == 2 and len(own) == 2, "the supplied dictionary was not filled")

# ── ctypes.CDLL: the library name reaches dlopen in filesystem units ──────
# Filed alongside the two above as a third disagreement, and already correct:
# `_ctypes.dlopen` takes the name through `fsencode`, so a surrogate escape
# folds back to the byte it stands for and dlopen is the thing that fails.
# Pinned because the earlier reading came from a binary built before that
# routing landed. A surrogate that is *not* an escape (U+D800 is outside
# U+DC80..U+DCFF) has no byte to fold to, so it is refused before the call —
# which is what the second row separates from the first.
try:
import ctypes
except ImportError:
ctypes = None
if ctypes is not None:

def raises_class(what, exc, fn):
"""Assert fn() raises `exc`; the message is the host's dlopen text."""
try:
fn()
except exc:
return
except BaseException as e:
ERRORS.append(
f"{what}: raised {type(e).__name__}, expected {exc.__name__}"
)
return
ERRORS.append(f"{what}: no exception, expected {exc.__name__}")

raises_class(
"CDLL with a surrogate-escaped name",
OSError,
lambda: ctypes.CDLL(SURR),
)
raises_class(
"CDLL with a non-escape surrogate",
UnicodeEncodeError,
lambda: ctypes.CDLL("bad\ud800name"),
)
raises_class(
"CDLL with a missing library",
OSError,
lambda: ctypes.CDLL("nosuchlib_pyre_parity_test"),
)

if ERRORS:
for e in ERRORS:
sys.stderr.write(f"FAIL: {e}\n".encode("utf-8", "backslashreplace").decode())
raise AssertionError(f"{len(ERRORS)} divergence(s)")

print("OK")
Loading
Loading