Skip to content
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
20 changes: 17 additions & 3 deletions crates/vm/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ pub(crate) enum FormatType {
Half = b'e',
Float = b'f',
Double = b'd',
LongDouble = b'g',
VoidP = b'P',
PyObject = b'O',
}

impl fmt::Debug for FormatType {
Expand Down Expand Up @@ -148,7 +150,9 @@ impl FormatType {
Half => nonnative_info!(f16, $end),
Float => nonnative_info!(f32, $end),
Double => nonnative_info!(f64, $end),
_ => unreachable!(), // size_t or void*
LongDouble => nonnative_info!(f64, $end), // long double same as double
PyObject => nonnative_info!(usize, $end), // pointer size
_ => unreachable!(), // size_t or void*
}
}};
}
Expand Down Expand Up @@ -183,7 +187,9 @@ impl FormatType {
Half => native_info!(f16),
Float => native_info!(raw::c_float),
Double => native_info!(raw::c_double),
LongDouble => native_info!(raw::c_double), // long double same as double for now
VoidP => native_info!(*mut raw::c_void),
PyObject => native_info!(*mut raw::c_void), // pointer to PyObject
},
Endianness::Big => match_nonnative!(self, BigEndian),
Endianness::Little => match_nonnative!(self, LittleEndian),
Expand Down Expand Up @@ -306,8 +312,16 @@ impl FormatCode {
continue;
}

if c == b'{' || c == b'}' {
// Skip standalone braces (pointer targets, etc.)
if c == b'{'
|| c == b'}'
|| c == b'&'
|| c == b'<'
|| c == b'>'
|| c == b'@'
|| c == b'='
|| c == b'!'
{
// Skip standalone braces (pointer targets, etc.), pointer prefix, and nested endianness markers
continue;
}

Expand Down
11 changes: 9 additions & 2 deletions crates/vm/src/protocol/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,23 @@ impl BufferDescriptor {

#[cfg(debug_assertions)]
pub fn validate(self) -> Self {
assert!(self.itemsize != 0);
// ndim=0 is valid for scalar types (e.g., ctypes Structure)
if self.ndim() == 0 {
// Empty structures (len=0) can have itemsize=0
if self.len > 0 {
assert!(self.itemsize != 0);
}
assert!(self.itemsize == self.len);
} else {
let mut shape_product = 1;
let has_zero_dim = self.dim_desc.iter().any(|(s, _, _)| *s == 0);
for (shape, stride, suboffset) in self.dim_desc.iter().cloned() {
shape_product *= shape;
assert!(suboffset >= 0);
assert!(stride != 0);
// For empty arrays (any dimension is 0), strides can be 0
if !has_zero_dim {
assert!(stride != 0);
}
}
assert!(shape_product * self.itemsize == self.len);
}
Expand Down
6 changes: 5 additions & 1 deletion scripts/fix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def run_test(test_name):
if not test_path.exists():
print(f"Error: File not found: {test_path}")
sys.exit(1)
test_name = test_path.stem
# Detect package tests (e.g., test_ctypes/test_random_things.py)
if test_path.parent.name.startswith("test_"):
test_name = f"{test_path.parent.name}.{test_path.stem}"
else:
test_name = test_path.stem
tests = run_test(test_name)
f = test_path.read_text(encoding="utf-8")

Expand Down
Loading