From 9f6468ec82e70d279250f6d9b9c24ed248eae5de Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 25 Aug 2025 17:51:07 +0300 Subject: [PATCH] sqlite3: Implement sqlite3_malloc() and sqlite3_free() --- sqlite3/src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sqlite3/src/lib.rs b/sqlite3/src/lib.rs index 46d6d64b3..1e19c9eee 100644 --- a/sqlite3/src/lib.rs +++ b/sqlite3/src/lib.rs @@ -461,13 +461,24 @@ pub unsafe extern "C" fn sqlite3_limit( } #[no_mangle] -pub unsafe extern "C" fn sqlite3_malloc64(_n: ffi::c_int) -> *mut ffi::c_void { - stub!(); +pub unsafe extern "C" fn sqlite3_malloc(n: ffi::c_int) -> *mut ffi::c_void { + sqlite3_malloc64(n) } #[no_mangle] -pub unsafe extern "C" fn sqlite3_free(_ptr: *mut ffi::c_void) { - stub!(); +pub unsafe extern "C" fn sqlite3_malloc64(n: ffi::c_int) -> *mut ffi::c_void { + if n <= 0 { + return std::ptr::null_mut(); + } + libc::malloc(n as usize) +} + +#[no_mangle] +pub unsafe extern "C" fn sqlite3_free(ptr: *mut ffi::c_void) { + if ptr.is_null() { + return; + } + libc::free(ptr); } /// Returns the error code for the most recent failed API call to connection.