From 28ece42e968ebe5be3f52c41443277da4b8dc645 Mon Sep 17 00:00:00 2001 From: Matt <1009003+tantaman@users.noreply.github.com> Date: Wed, 20 Sep 2023 13:26:37 -0400 Subject: [PATCH] fix err_msg pointer creation --- core/rs/integration_check/src/t/tableinfo.rs | 20 +++++++++++++++++--- core/rs/sqlite-rs-embedded | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/rs/integration_check/src/t/tableinfo.rs b/core/rs/integration_check/src/t/tableinfo.rs index 4c5827802..81e6d3804 100644 --- a/core/rs/integration_check/src/t/tableinfo.rs +++ b/core/rs/integration_check/src/t/tableinfo.rs @@ -9,10 +9,20 @@ use crsql_bundle::test_exports::tableinfo::TableInfo; use sqlite::Connection; use sqlite_nostd as sqlite; +// Unfortunate circumstance that we still have some C code that requires this argument fn make_err_ptr() -> *mut *mut c_char { - let mut inner_ptr: *mut c_char = core::ptr::null_mut(); - let outer_ptr: *mut *mut c_char = &mut inner_ptr; - outer_ptr + let boxed = Box::new(core::ptr::null_mut() as *mut c_char); + return Box::into_raw(boxed); +} + +fn drop_err_ptr(err: *mut *mut c_char) { + unsafe { + let ptr = Box::from_raw(err); + if ptr.is_null() { + return; + } + let _ = CString::from_raw(*ptr); + } } fn make_site() -> *mut c_char { @@ -88,6 +98,7 @@ fn test_ensure_table_infos_are_up_to_date() { .expect("dropped boo"); test_exports::tableinfo::crsql_ensure_table_infos_are_up_to_date(raw_db, ext_data, err); + drop_err_ptr(err); assert_eq!(table_infos.len(), 0); @@ -148,6 +159,7 @@ fn test_pull_table_info() { assert_eq!(tbl_info.non_pks[0].name, "a"); assert_eq!(tbl_info.non_pks[0].cid, 0); assert_eq!(tbl_info.non_pks[0].pk, 0); + drop_err_ptr(err); } fn test_is_table_compatible() { @@ -263,6 +275,7 @@ fn test_is_table_compatible() { let is_compatible = test_exports::tableinfo::is_table_compatible(raw_db, "atable2", err) .expect("checked if atable2 is compatible"); assert_eq!(is_compatible, true); + drop_err_ptr(err); } fn test_create_clock_table_from_table_info() { @@ -298,6 +311,7 @@ fn test_create_clock_table_from_table_info() { test_exports::bootstrap::create_clock_table(raw_db, &boo_tbl_info, err) .expect("created clock table for boo"); + drop_err_ptr(err); // todo: Check that clock tables have expected schema(s) } diff --git a/core/rs/sqlite-rs-embedded b/core/rs/sqlite-rs-embedded index 58489401b..0036ea41b 160000 --- a/core/rs/sqlite-rs-embedded +++ b/core/rs/sqlite-rs-embedded @@ -1 +1 @@ -Subproject commit 58489401b166718b952476b17e4f73aae1dc5472 +Subproject commit 0036ea41bb7e8d0c17871a5e478243549c7c6108