Repository navigation
Add a _testcapi module #9143
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
base: main
Are you sure you want to change the base?
Add a _testcapi module #9143
Changes from all commits
1b459a1
346c12f
d000865
c731e54
4235d62
80f6bf3
ff55211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| use crate::{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| marshal::MarshalError, | ||||||||||||||||||||||||||||||||||||||||||||||||
| varint::{read_varint, read_varint_with_start, write_varint_be, write_varint_with_start}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| varint::{ | ||||||||||||||||||||||||||||||||||||||||||||||||
| read_varint, read_varint_with_start, write_signed_varint, write_varint_be, | ||||||||||||||||||||||||||||||||||||||||||||||||
| write_varint_with_start, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| {OneIndexed, SourceLocation}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| use alloc::{borrow::ToOwned, boxed::Box, collections::BTreeSet, fmt, string::String, vec::Vec}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -143,6 +146,66 @@ pub fn decode_exception_table(table: &[u8]) -> Vec<ExceptionTableEntry> { | |||||||||||||||||||||||||||||||||||||||||||||||
| entries | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// scan_varint | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn scan_varint(data: &[u8]) -> u32 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut iter = data.iter(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut read = iter.next().copied().unwrap_or(0); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut val = u32::from(read & 63); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut shift = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
| while read & 64 != 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| read = iter.next().copied().unwrap_or(0); | ||||||||||||||||||||||||||||||||||||||||||||||||
| shift += 6; | ||||||||||||||||||||||||||||||||||||||||||||||||
| val |= u32::from(read & 63) << shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Under Useful? React with 👍 / 👎. |
||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+150
to
+159
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '145,215p' crates/compiler-core/src/bytecode.rs
sed -n '640,665p' crates/vm/src/builtins/code.rs
rg -n 'remove_column_info|co_linetable|linetable_to_locations' crates/vm/src/builtins/code.rsRepository: RustPython/RustPython Length of output: 4493 🏁 Script executed: set -o pipefail
printf '%s\n' '--- scan_varint callers and definitions ---'
rg -n -F --glob '*.rs' -e 'scan_varint' -e 'get_line_delta' -e 'remove_column_info' crates/compiler-core/src/bytecode.rs crates/vm/src/builtins/code.rs
printf '%s\n' '--- code constructor and replace blocks ---'
sed -n '1120,1210p' crates/vm/src/builtins/code.rs
sed -n '1680,1785p' crates/vm/src/builtins/code.rs
printf '%s\n' '--- linetable parsing and validation ---'
rg -n -F --glob '*.rs' -e 'linetable_to_locations' -e 'PyCodeLocationInfoKind' -e 'locations' crates/compiler-core/src/marshal.rs crates/compiler-core/src/bytecode.rs crates/vm/src/builtins/code.rs | head -160
sed -n '1,145p' crates/compiler-core/src/bytecode.rs
sed -n '1,180p' crates/compiler-core/src/marshal.rs
printf '%s\n' '--- tests mentioning no_debug_ranges or malformed linetables ---'
rg -n -F --glob '*.py' --glob '*.rs' -e 'no_debug_ranges' -e 'co_linetable' -e 'linetable' tests stdlib crates | head -220Repository: RustPython/RustPython Length of output: 39177 🏁 Script executed: set -o pipefail
printf '%s\n' '--- code() signature and argument definitions ---'
sed -n '1000,1075p' crates/vm/src/builtins/code.rs
sed -n '1560,1620p' crates/vm/src/builtins/code.rs
printf '%s\n' '--- linetable_to_locations complete implementation ---'
sed -n '1735,1870p' crates/compiler-core/src/marshal.rs
printf '%s\n' '--- linetable varint readers/writers ---'
rg -n -F --glob '*.rs' -e 'fn lt_read_varint' -e 'fn lt_read_signed_varint' -e 'fn lt_byte' -e 'pub fn write_signed_varint' -e 'pub fn write_varint' crates/compiler-core/src
sed -n '1,145p' crates/compiler-core/src/varint.rs
sed -n '1810,1855p' crates/compiler-core/src/marshal.rs
printf '%s\n' '--- code_debug_ranges setting and tests ---'
sed -n '45,80p' crates/vm/src/vm/setting.rs
rg -n -F --glob '*.py' --glob '*.rs' -e 'code.replace' -e 'co_linetable=' -e 'CodeType(' -e 'no_debug_ranges' tests crates | head -220Repository: RustPython/RustPython Length of output: 17248 Bound
Suggested fix while read & 64 != 0 {
read = iter.next().copied().unwrap_or(0);
shift += 6;
+ if shift >= 32 {
+ break;
+ }
val |= u32::from(read & 63) << shift;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| val | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// scan_signed_varint | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn scan_signed_varint(data: &[u8]) -> i32 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let uval = scan_varint(data); | ||||||||||||||||||||||||||||||||||||||||||||||||
| if uval & 1 != 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| -((uval >> 1) as i32) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| (uval >> 1) as i32 | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// get_line_delta | ||||||||||||||||||||||||||||||||||||||||||||||||
| fn get_line_delta(entry: &[u8]) -> i32 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| match PyCodeLocationInfoKind::from_code((entry[0] >> 3) & 15) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| Some(PyCodeLocationInfoKind::NoColumns | PyCodeLocationInfoKind::Long) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| scan_signed_varint(&entry[1..]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| Some(PyCodeLocationInfoKind::OneLine1) => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||
| Some(PyCodeLocationInfoKind::OneLine2) => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||
| // None, OneLine0 and the short forms stay on the same line. | ||||||||||||||||||||||||||||||||||||||||||||||||
| _ => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// remove_column_info: rewrite every entry of a linetable that has a | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// location as a NO_COLUMNS entry with the same length and line delta. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn remove_column_info(locations: &[u8]) -> Vec<u8> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut output = Vec::with_capacity(locations.len()); | ||||||||||||||||||||||||||||||||||||||||||||||||
| let mut offset = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
| while offset < locations.len() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let header = locations[offset]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (header >> 3) & 15 == PyCodeLocationInfoKind::None as u8 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| output.push(header); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let blength = (header & 7) + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| output.push(0x80 | ((PyCodeLocationInfoKind::NoColumns as u8) << 3) | (blength - 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||
| write_signed_varint(&mut output, get_line_delta(&locations[offset..])); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| offset += 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| while offset < locations.len() && locations[offset] & 128 == 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||
| offset += 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| output | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Parse linetable to build a boolean mask indicating which code units | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// have NO_LOCATION (line == -1). Returns a Vec<bool> of length `num_units`. | ||||||||||||||||||||||||||||||||||||||||||||||||
| #[must_use] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
_testcapiis now importable but lackstest_datetime_capi, this unconditional class decorator suppresses every fast datetime C-API test instead of retaining executable failure coverage, so later partial implementations cannot expose regressions or unexpected passes. Implement the setup helper/Rust functionality rather than skipping the entire class; repository policy reserves skips for tests that would crash, abort, or hang the test process.AGENTS.md reference: AGENTS.md:L98-L101
Useful? React with 👍 / 👎.