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 comparisons of Ref objects #41

Merged
merged 2 commits into from
Oct 17, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion src/handlers/pyc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fmt;
use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::{self, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str;
Expand Down Expand Up @@ -776,8 +777,12 @@ enum Object {
impl PartialEq for Object {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
// For References, we want to actually look at the
// reference target, so dereference before comparing.
(Object::Ref(v), w) => v.target.deref().eq(w),
(v, Object::Ref(w)) => v.eq(w.target.deref()),

(Object::Code(v), Object::Code(w)) => v == w,
(Object::Ref(v), Object::Ref(w)) => v == w,
(Object::Long(v, _), Object::Long(w, _)) => v == w,
(Object::Int(v, _), Object::Int(w, _)) => v == w,
(Object::Null(_), Object::Null(_)) => true,
Expand Down Expand Up @@ -1767,6 +1772,7 @@ impl super::Processor for PycZeroMtime {

#[cfg(test)]
mod tests {
use std::hash::{DefaultHasher, Hasher};
use super::*;

#[test]
Expand All @@ -1782,4 +1788,94 @@ mod tests {
assert!(!h.filter(Path::new("/some/path/pyc_pyc")).unwrap());
assert!(!h.filter(Path::new("/")).unwrap());
}

#[test]
fn seq_string_equality() {
let seq1 = Object::Seq(
SeqObject {
variant: SeqVariant::FrozenSet,
items: [
Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112].to_vec(),
ref_index: Some(43),
}
).into(),
Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112, 115].to_vec(),
ref_index: Some(44),
}
).into(),
].to_vec(),
ref_index: None,
}
);
let seq2 = Object::Seq(
SeqObject {
variant: SeqVariant::FrozenSet,
items: [
Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112].to_vec(),
ref_index: None,
}
).into(),
Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112, 115].to_vec(),
ref_index: None,
}
).into(),
].to_vec(),
ref_index: Some(43),
}
);

assert!(seq1 == seq1);
assert!(seq2 == seq2);
assert!(seq1 == seq2);
assert!(seq2 == seq1);

let mut hash1 = DefaultHasher::new();
seq1.hash(&mut hash1);

let mut hash2 = DefaultHasher::new();
seq2.hash(&mut hash2);

assert!(hash1.finish() == hash2.finish());
}

#[test]
fn seq_ref_equality() {
let obj1 = Object::Ref(
RefObject {
number: 43,
target: Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112].to_vec(),
ref_index: Some(43),
},
).into(),
ref_index: Some(99),
}
);
let obj2 = Object::String(
StringObject {
variant: StringVariant::ShortAsciiInterned,
bytes: [104, 116, 116, 112].to_vec(),
ref_index: None,
},
);

assert!(obj1 == obj1);
assert!(obj2 == obj2);
assert!(obj1 == obj2);
assert!(obj2 == obj1);
}
}
Binary file modified tests/cases/python_stdlib/3.13/ftplib.cpython-313.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.13/ftplib.cpython-313.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/_dummy_thread.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/_endian.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/_sitebuiltins.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/ascii.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/asynchat.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/binhex.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/calltip.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/case.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/chaos.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/cp1253.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/cp424.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/cp856.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/cp857.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/cp860.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/debugger_r.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/dist.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/dnd.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/dyld.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/enum.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/expatbuilder.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/expatreader.cpython-36.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.6/gzip.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/lock_tests.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/mapping_tests.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/message.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/parser.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/penrose.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/profile.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/pyshell.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/quoprimime.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/random.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/redirector.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/refactor.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/saxutils.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/simpledialog.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/smtpd.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/squeezer.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/ssl.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/statusbar.cpython-36.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.6/threading.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/traceback.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/tree.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/turtle.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/types.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/types.cpython-36.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/utf_32.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/util.cpython-36.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/util.cpython-36.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/util.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/uuid.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/weakref.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.6/xmlreader.cpython-36.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/__init__.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/_py_abc.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/_pydecimal.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/abc.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/binhex.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/cmd.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/config.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/context.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/cp1006.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/cp1254.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/cp1257.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/cp737.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/datetime.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/difflib.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/dis.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/fileinput.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/font.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/format.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/fractions.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/ftplib.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/headers.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/heap.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/heapq.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/help.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/help_about.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/install_data.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/latin_1.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/minidom.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/mock_tk.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/modulefinder.cpython-37.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/optparse.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/outwin.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/pipes.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/pprint.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/process.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/pulldom.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/pyclbr.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/replace.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/secrets.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/shutil.cpython-37.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/spawn.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/sre_parse.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/support.cpython-37.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/token.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/traceback.cpython-37.opt-1.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/uu.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/uu_codec.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/uuid.cpython-37.pyc.fixed
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/window.cpython-37.opt-2.pyc.fixed
Binary file not shown.
Binary file not shown.
Binary file modified tests/cases/python_stdlib/3.7/xmlreader.cpython-37.pyc.fixed
Binary file not shown.
Loading