Replace ::atomic::Atomic by std AtomicPtr

NoUninit constraint cannot be satisfied
This commit is contained in:
gwenn 2023-11-11 20:11:37 +01:00
parent 1d74ddcc7b
commit e8c35fce50
5 changed files with 6583 additions and 5478 deletions

View File

@ -23,7 +23,7 @@ min_sqlite_version_3_14_0 = ["pkg-config", "vcpkg"]
# Bundle only the bindings file. Note that this does nothing if
# `buildtime_bindgen` is enabled.
bundled_bindings = []
loadable_extension = ["atomic", "prettyplease", "quote", "syn"]
loadable_extension = ["prettyplease", "quote", "syn"]
# sqlite3_unlock_notify >= 3.6.12
unlock_notify = []
# 3.13.0
@ -43,7 +43,6 @@ winsqlite3 = []
[dependencies]
openssl-sys = { version = "0.9", optional = true }
atomic = { version = "0.6", optional = true }
[build-dependencies]
bindgen = { version = "0.69", optional = true, default-features = false, features = ["runtime"] }

File diff suppressed because it is too large Load Diff

View File

@ -745,25 +745,31 @@ mod loadable_extension {
let ty = &method.output;
let tokens = if "db_config" == name {
quote::quote! {
static #ptr_name: ::atomic::Atomic<Option<unsafe extern "C" fn(#args #varargs) #ty>> = ::atomic::Atomic::new(None);
static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut());
pub unsafe fn #sqlite3_fn_name(#args arg3: ::std::os::raw::c_int, arg4: *mut ::std::os::raw::c_int) #ty {
let fun = #ptr_name.load(::atomic::Ordering::Acquire).expect("SQLite API not initialized");
let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire);
assert!(!ptr.is_null(), "SQLite API not initialized");
let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr);
(fun)(#arg_names, arg3, arg4)
}
}
} else if "log" == name {
quote::quote! {
static #ptr_name: ::atomic::Atomic<Option<unsafe extern "C" fn(#args #varargs) #ty>> = ::atomic::Atomic::new(None);
static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut());
pub unsafe fn #sqlite3_fn_name(#args arg3: *const ::std::os::raw::c_char) #ty {
let fun = #ptr_name.load(::atomic::Ordering::Acquire).expect("SQLite API not initialized");
let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire);
assert!(!ptr.is_null(), "SQLite API not initialized");
let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr);
(fun)(#arg_names, arg3)
}
}
} else {
quote::quote! {
static #ptr_name: ::atomic::Atomic<Option<unsafe extern "C" fn(#args #varargs) #ty>> = ::atomic::Atomic::new(None);
static #ptr_name: ::std::sync::atomic::AtomicPtr<()> = ::std::sync::atomic::AtomicPtr::new(::std::ptr::null_mut());
pub unsafe fn #sqlite3_fn_name(#args) #ty {
let fun = #ptr_name.load(::atomic::Ordering::Acquire).expect("SQLite API not initialized or SQLite feature omitted");
let ptr = #ptr_name.load(::std::sync::atomic::Ordering::Acquire);
assert!(!ptr.is_null(), "SQLite API not initialized or SQLite feature omitted");
let fun: unsafe extern "C" fn(#args #varargs) #ty = ::std::mem::transmute(ptr);
(fun)(#arg_names)
}
}
@ -778,10 +784,12 @@ mod loadable_extension {
&mut stores
}
.push(quote::quote! {
if let Some(fun) = (*#p_api).#ident {
#ptr_name.store(
(*#p_api).#ident,
::atomic::Ordering::Release,
fun as usize as *mut (),
::std::sync::atomic::Ordering::Release,
);
}
});
}
// (3) generate rust code similar to SQLITE_EXTENSION_INIT2 macro

File diff suppressed because it is too large Load Diff

View File

@ -28,12 +28,13 @@ find "$TARGET_DIR" -type f -name bindgen.rs -exec mv {} "$SQLITE3_LIB_DIR/bindge
# Regenerate bindgen file for sqlite3ext.h
# some sqlite3_api_routines fields are function pointers with va_list arg but currently stable Rust doesn't support this type.
# FIXME how to generate portable bindings without :
sed -i'' -e 's/va_list/void*/' "$SQLITE3_LIB_DIR/sqlite3ext.h"
sed -i.bk -e 's/va_list/void*/' "$SQLITE3_LIB_DIR/sqlite3ext.h"
rm -f "$SQLITE3_LIB_DIR/bindgen_bundled_version_ext.rs"
find "$TARGET_DIR" -type f -name bindgen.rs -exec rm {} \;
env LIBSQLITE3_SYS_BUNDLING=1 cargo build --features "buildtime_bindgen loadable_extension" --no-default-features
find "$TARGET_DIR" -type f -name bindgen.rs -exec mv {} "$SQLITE3_LIB_DIR/bindgen_bundled_version_ext.rs" \;
git checkout "$SQLITE3_LIB_DIR/sqlite3ext.h"
rm -f "$SQLITE3_LIB_DIR/sqlite3ext.h.bk"
# Sanity checks
cd "$SCRIPT_DIR/.." || { echo "fatal error" >&2; exit 1; }