mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
Decode marshal slice constants from magic 3608 onward and pin the 3.11 code layout and inline-cache tables for the 3.14 and 3.15 magics. Refs #8206
22 lines
1.0 KiB
TypeScript
22 lines
1.0 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { pythonPycBytecodeIdentity } from "./PythonPycBytecodeEquality.js";
|
|
|
|
const raw = (bytes: Buffer): string =>
|
|
createHash("sha256").update(bytes).digest("hex");
|
|
const identity = (bytes: Buffer, magic: number): string =>
|
|
pythonPycBytecodeIdentity(bytes, magic, raw(bytes));
|
|
|
|
it("skips inline-cache units only under the pinned 3.14 and 3.15 magics", () => {
|
|
// Opcode 80 carries nine cache code units in the 3627 table; only the cache
|
|
// bytes differ between the two bytecodes.
|
|
const first = Buffer.from([80, 0, ...Array(18).fill(1), 83, 0]);
|
|
const second = Buffer.from([80, 0, ...Array(18).fill(9), 83, 0]);
|
|
expect(identity(first, 3627)).toBe(identity(second, 3627));
|
|
// A magic with no pinned table keeps the raw bytecode digest, so code
|
|
// objects that differ only in cache units stay distinct.
|
|
expect(identity(first, 3619)).toBe(`${String(first.length)}:${raw(first)}`);
|
|
expect(identity(first, 3619)).not.toBe(identity(second, 3619));
|
|
});
|