Last active
July 3, 2023 17:08
-
-
Save gwenn/32beb99dec960f73e025e8b322199812 to your computer and use it in GitHub Desktop.
sqlite3_api_routines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(c_variadic)] | |
use atomic::{Atomic, Ordering}; | |
#[allow(non_camel_case_types)] | |
pub struct sqlite3_api_routines { | |
pub db_config: ::std::option::Option< | |
unsafe extern "C" fn( | |
//arg1: *mut sqlite3, | |
arg2: ::std::os::raw::c_int, | |
... | |
) -> ::std::os::raw::c_int, | |
>, | |
} | |
unsafe extern "C" fn db_config(arg2: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int { | |
123 | |
} | |
#[allow(non_upper_case_globals)] | |
static _sqlite3_db_config: Atomic< | |
Option<unsafe extern "C" fn(arg2: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int>, | |
> = Atomic::new(None); | |
pub unsafe fn sqlite3_db_config(arg2: ::std::os::raw::c_int) -> ::std::os::raw::c_int { | |
if let Some(fun) = _sqlite3_db_config.load(Ordering::Acquire) { | |
fun(arg2) | |
} else { | |
panic!("SQLite API not initialized") | |
} | |
} | |
fn main() { | |
let sqlite3_api = sqlite3_api_routines { | |
db_config: Some(db_config), | |
}; | |
_sqlite3_db_config.store(sqlite3_api.db_config, Ordering::Release); | |
println!("sqlite3_db_config: {}", unsafe { sqlite3_db_config(0) }); | |
println!( | |
"is_lock_free: {}", | |
Atomic::< | |
Option<unsafe extern "C" fn(arg2: ::std::os::raw::c_int, ...) -> ::std::os::raw::c_int>, | |
>::is_lock_free() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment