Skip to content

Commit 7bfa5d9

Browse files
authored
Buffer LongDouble + ndim (#6460)
* fix fix_test * ndim buffer
1 parent 46c61a6 commit 7bfa5d9

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

crates/vm/src/buffer.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ pub(crate) enum FormatType {
8888
Half = b'e',
8989
Float = b'f',
9090
Double = b'd',
91+
LongDouble = b'g',
9192
VoidP = b'P',
93+
PyObject = b'O',
9294
}
9395

9496
impl fmt::Debug for FormatType {
@@ -148,7 +150,9 @@ impl FormatType {
148150
Half => nonnative_info!(f16, $end),
149151
Float => nonnative_info!(f32, $end),
150152
Double => nonnative_info!(f64, $end),
151-
_ => unreachable!(), // size_t or void*
153+
LongDouble => nonnative_info!(f64, $end), // long double same as double
154+
PyObject => nonnative_info!(usize, $end), // pointer size
155+
_ => unreachable!(), // size_t or void*
152156
}
153157
}};
154158
}
@@ -183,7 +187,9 @@ impl FormatType {
183187
Half => native_info!(f16),
184188
Float => native_info!(raw::c_float),
185189
Double => native_info!(raw::c_double),
190+
LongDouble => native_info!(raw::c_double), // long double same as double for now
186191
VoidP => native_info!(*mut raw::c_void),
192+
PyObject => native_info!(*mut raw::c_void), // pointer to PyObject
187193
},
188194
Endianness::Big => match_nonnative!(self, BigEndian),
189195
Endianness::Little => match_nonnative!(self, LittleEndian),
@@ -306,8 +312,16 @@ impl FormatCode {
306312
continue;
307313
}
308314

309-
if c == b'{' || c == b'}' {
310-
// Skip standalone braces (pointer targets, etc.)
315+
if c == b'{'
316+
|| c == b'}'
317+
|| c == b'&'
318+
|| c == b'<'
319+
|| c == b'>'
320+
|| c == b'@'
321+
|| c == b'='
322+
|| c == b'!'
323+
{
324+
// Skip standalone braces (pointer targets, etc.), pointer prefix, and nested endianness markers
311325
continue;
312326
}
313327

crates/vm/src/protocol/buffer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,23 @@ impl BufferDescriptor {
201201

202202
#[cfg(debug_assertions)]
203203
pub fn validate(self) -> Self {
204-
assert!(self.itemsize != 0);
205204
// ndim=0 is valid for scalar types (e.g., ctypes Structure)
206205
if self.ndim() == 0 {
206+
// Empty structures (len=0) can have itemsize=0
207+
if self.len > 0 {
208+
assert!(self.itemsize != 0);
209+
}
207210
assert!(self.itemsize == self.len);
208211
} else {
209212
let mut shape_product = 1;
213+
let has_zero_dim = self.dim_desc.iter().any(|(s, _, _)| *s == 0);
210214
for (shape, stride, suboffset) in self.dim_desc.iter().cloned() {
211215
shape_product *= shape;
212216
assert!(suboffset >= 0);
213-
assert!(stride != 0);
217+
// For empty arrays (any dimension is 0), strides can be 0
218+
if !has_zero_dim {
219+
assert!(stride != 0);
220+
}
214221
}
215222
assert!(shape_product * self.itemsize == self.len);
216223
}

scripts/fix_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ def run_test(test_name):
159159
if not test_path.exists():
160160
print(f"Error: File not found: {test_path}")
161161
sys.exit(1)
162-
test_name = test_path.stem
162+
# Detect package tests (e.g., test_ctypes/test_random_things.py)
163+
if test_path.parent.name.startswith("test_"):
164+
test_name = f"{test_path.parent.name}.{test_path.stem}"
165+
else:
166+
test_name = test_path.stem
163167
tests = run_test(test_name)
164168
f = test_path.read_text(encoding="utf-8")
165169

0 commit comments

Comments
 (0)