Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writing of pyc header, add more tests #39

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 1 addition & 8 deletions src/handlers/pyc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ impl PycParser {

let mtime = pyc.py_content_mtime();
// 'size' seems to be the count of serialized objects, excluding TYPE_REF
debug!("{}: from py with mtime={} ({}), size={} entries, {}",
debug!("{}: from py with mtime={} ({}), size={} bytes, {}",
input_path.display(),
mtime,
chrono::DateTime::from_timestamp(mtime as i64, 0).unwrap(),
Expand Down Expand Up @@ -1325,7 +1325,6 @@ impl PycWriter {
w.write_object(code);
w.add_ref_flags();
w.fix_refs();
w.fix_entry_count(parser.version);

// TODO: overwrite content hash if present
w.buffer
Expand Down Expand Up @@ -1617,12 +1616,6 @@ impl PycWriter {
bytes.copy_from_slice(&(index as u32).to_le_bytes());
}
}

fn fix_entry_count(&mut self, version: (u32, u32)) {
let size_offset = if version < (3, 7) { 8 } else { 12 };
let size = self.entry_count as u32;
self.buffer[size_offset .. size_offset + 4].copy_from_slice(&size.to_le_bytes());
}
}


Expand Down
Binary file modified tests/cases/adapters.cpython-312~fixed.pyc
Binary file not shown.
Binary file modified tests/cases/dicto.cpython-313.pyc
Binary file not shown.
Binary file removed tests/cases/dicto.cpython-313.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/listo.cpython-313.pyc
Binary file not shown.
Binary file removed tests/cases/listo.cpython-313.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/ElementTree.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/__future__.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/__init__.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/_tzpath.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/ascii.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/big5hkscs.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/calltip_w.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/chaos.cpython-310.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/chunk.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/config.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/cp850.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/difflib.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/dis.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/dummy.cpython-310.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/dump.cpython-310.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/factory.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/filelist.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/fix_idioms.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/fix_import.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/fixer_base.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/fixer_util.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/fork_wait.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/handlers.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/heapq.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/hz.cpython-310.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/imghdr.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/koi8_r.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/mac_roman.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/main.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/minicompat.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/parse.cpython-310.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/pgen.cpython-310.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/pydoc_mod.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/pyparse.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/pytree.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/quoprimime.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/re.cpython-310.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/redirector.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/replace.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/setup.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/shutil.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/sortperf.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/spawn.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/textview.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/token.cpython-310.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/utf_8_sig.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/wintypes.cpython-310.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.10/zlib_codec.cpython-310.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_constants.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_itertools.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_legacy.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_meta.cpython-311.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_parser.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_pyio.cpython-311.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/_re.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/ast.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/code.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/constants.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/contextlib.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/conv.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/core.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/cp858.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/cp950.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/dist.cpython-311.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/domreg.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/expatreader.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/forkserver.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/genericpath.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/glob.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/graphlib.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/gzip.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/gzip.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/hex_codec.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/ndbm.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/ntpath.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/numbers.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/parse.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/parse.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/pprint.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/pydoc.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/pygram.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/runner.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/selectors.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/shutil.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/site.cpython-311.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/staggered.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/struct.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/sysconfig.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/tasks.cpython-311.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/token.cpython-311.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/utf_32_be.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/utf_8.cpython-311.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.11/util.cpython-311.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/_abc.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/ast.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/base_tasks.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/big5.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/build.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/bz2.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/bz2.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/case.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/cmd.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/cp858.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/cp950.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/crypt.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/dumb.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/dumb.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/fileinput.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/fix_buffer.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/gnu.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/mbcs.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/message.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/mimetypes.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/mixins.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/parser.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/pipes.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/queue.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/rlcompleter.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/runners.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/server.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/shlex.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/simple.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/ssl.cpython-312.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/ssl.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/stat.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/stringprep.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/subprocess.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/suite.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/suite.cpython-312.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/textpad.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/types.cpython-312.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.12/types.cpython-312.pyc.fixed
Binary file not shown.
Binary file not shown.
Loading
Loading