MCPcopy Index your code
hub / github.com/RustPython/RustPython / result_from_object

Method result_from_object

crates/stdlib/src/_sqlite3.rs:3358–3381  ·  view source on GitHub ↗
(self, val: &PyObject, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

3356 }
3357
3358 fn result_from_object(self, val: &PyObject, vm: &VirtualMachine) -> PyResult<()> {
3359 unsafe {
3360 if vm.is_none(val) {
3361 sqlite3_result_null(self.ctx)
3362 } else if let Some(val) = val.downcast_ref::<PyInt>() {
3363 sqlite3_result_int64(self.ctx, val.try_to_primitive(vm)?)
3364 } else if let Some(val) = val.downcast_ref::<PyFloat>() {
3365 sqlite3_result_double(self.ctx, val.to_f64())
3366 } else if let Some(val) = val.downcast_ref::<PyStr>() {
3367 let val = val.try_as_utf8(vm)?;
3368 let (ptr, len) = str_to_ptr_len(val, vm)?;
3369 sqlite3_result_text(self.ctx, ptr, len, SQLITE_TRANSIENT())
3370 } else if let Ok(buffer) = PyBuffer::try_from_borrowed_object(vm, val) {
3371 let (ptr, len) = buffer_to_ptr_len(&buffer, vm)?;
3372 sqlite3_result_blob(self.ctx, ptr, len, SQLITE_TRANSIENT())
3373 } else {
3374 return Err(new_programming_error(
3375 vm,
3376 "result type not support".to_owned(),
3377 ));
3378 }
3379 }
3380 Ok(())
3381 }
3382 }
3383
3384 fn value_to_object(val: *mut sqlite3_value, db: *mut sqlite3, vm: &VirtualMachine) -> PyResult {

Callers 2

func_callbackMethod · 0.80

Calls 8

str_to_ptr_lenFunction · 0.85
buffer_to_ptr_lenFunction · 0.85
try_to_primitiveMethod · 0.80
to_f64Method · 0.80
try_as_utf8Method · 0.80
ErrClass · 0.50
is_noneMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected