Skip to content

Commit 19a79df

Browse files
committed
Use uint32 bounds for sqlite cursor fetch sizes
Store arraysize and bind fetchmany size as u32, matching Python 3.15. Preserve the current arraysize fallback and size=1 metadata, and rely on the existing unsigned index converter for negative ValueError and oversized OverflowError. The row loop still grows its result only as rows are returned and does not reserve by the declared limit. This follow-up depends on the sqlite signature branch at b5c50e7. Independent source review and normal hooks passed; no local native compilation, runtime tests, or allocation-heavy boundary probes were run. Exact error wording and CPython post-error setter storage are not claimed identical. Assisted-by: OpenAI Codex:model version not exposed
1 parent 29c8c5b commit 19a79df

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

‎crates/stdlib/src/_sqlite3.rs‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ mod _sqlite3 {
22882288
struct Cursor {
22892289
connection: PyRef<Connection>,
22902290
#[pytraverse(skip)]
2291-
arraysize: PyAtomic<c_int>,
2291+
arraysize: PyAtomic<u32>,
22922292
#[pytraverse(skip)]
22932293
row_factory: PyAtomicRef<Option<PyObject>>,
22942294
inner: PyMutex<Option<CursorInner>>,
@@ -2312,7 +2312,7 @@ mod _sqlite3 {
23122312
// Like Clinic, display the initial arraysize but read the current value
23132313
// when omitted. Explicit None must still fail integer conversion.
23142314
#[pyarg(any, optional, py_default = "1")]
2315-
size: OptionalArg<c_int>,
2315+
size: OptionalArg<u32>,
23162316
}
23172317

23182318
#[derive(FromArgs)]
@@ -2606,16 +2606,9 @@ mod _sqlite3 {
26062606
args: FetchManyArgs,
26072607
vm: &VirtualMachine,
26082608
) -> PyResult<Vec<PyObjectRef>> {
2609-
let max_rows = match args.size {
2610-
OptionalArg::Present(size) => {
2611-
if size < 0 {
2612-
return Err(vm.new_value_error("fetchmany may not be negative"));
2613-
}
2614-
2615-
size
2616-
}
2617-
OptionalArg::Missing => zelf.arraysize.load(Ordering::Relaxed),
2618-
};
2609+
let max_rows = args
2610+
.size
2611+
.unwrap_or_else(|| zelf.arraysize.load(Ordering::Relaxed));
26192612

26202613
let mut list = vec![];
26212614
let mut remaining = max_rows;
@@ -2691,19 +2684,13 @@ mod _sqlite3 {
26912684
}
26922685

26932686
#[pygetset]
2694-
fn arraysize(zelf: &Py<Self>) -> c_int {
2687+
fn arraysize(zelf: &Py<Self>) -> u32 {
26952688
zelf.arraysize.load(Ordering::Relaxed)
26962689
}
26972690

26982691
#[pygetset(setter)]
2699-
fn set_arraysize(zelf: &Py<Self>, val: c_int, vm: &VirtualMachine) -> PyResult<()> {
2700-
if val < 0 {
2701-
return Err(vm.new_value_error("arraysize may not be negative"));
2702-
}
2703-
2692+
fn set_arraysize(zelf: &Py<Self>, val: u32) {
27042693
zelf.arraysize.store(val, Ordering::Relaxed);
2705-
2706-
Ok(())
27072694
}
27082695

27092696
#[pygetset]

0 commit comments

Comments
 (0)