try and stop reinit segfaulting; doesn't really work
This commit is contained in:
parent
e90ee73dc8
commit
7562f18141
@ -23,6 +23,8 @@ struct PPkgIterator {
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void init_config_system();
|
||||
|
||||
PCache *pkg_cache_create();
|
||||
void pkg_cache_release(PCache *cache);
|
||||
|
||||
@ -38,10 +40,12 @@ extern "C" {
|
||||
char *pkg_iter_pretty(PCache *cache, PPkgIterator *iterator);
|
||||
}
|
||||
|
||||
PCache *pkg_cache_create() {
|
||||
void init_config_system() {
|
||||
pkgInitConfig(*_config);
|
||||
pkgInitSystem(*_config, _system);
|
||||
}
|
||||
|
||||
PCache *pkg_cache_create() {
|
||||
pkgCacheFile *cache_file = new pkgCacheFile();
|
||||
pkgCache *cache = cache_file->GetPkgCache();
|
||||
|
||||
|
23
src/lib.rs
23
src/lib.rs
@ -7,29 +7,6 @@ pub mod sane;
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
// Leaks on panic.
|
||||
#[test]
|
||||
fn goin_in_raw() {
|
||||
unsafe {
|
||||
let cache = raw::pkg_cache_create();
|
||||
let iter = raw::pkg_cache_pkg_iter(cache);
|
||||
loop {
|
||||
println!("{}", CStr::from_ptr(raw::pkg_iter_name(iter)).to_str().expect("package names are always valid utf-8, in that they're always valid low ascii"));
|
||||
let pretty = raw::pkg_iter_pretty(cache, iter);
|
||||
println!("{}", CStr::from_ptr(pretty).to_str().expect("package names are always valid utf-8, in that they're always valid low ascii"));
|
||||
libc::free(pretty as *mut libc::c_void);
|
||||
raw::pkg_iter_next(iter);
|
||||
if raw::pkg_iter_end(iter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
raw::pkg_iter_release(iter);
|
||||
raw::pkg_cache_release(cache);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_all() {
|
||||
let mut cache = sane::Cache::new();
|
||||
|
16
src/raw.rs
16
src/raw.rs
@ -13,6 +13,10 @@ pub type PPkgIterator = *mut c_void;
|
||||
#[link(name = "apt-pkg")]
|
||||
#[link(name = "stdc++")]
|
||||
extern {
|
||||
/// Must be called exactly once, before anything else?
|
||||
fn init_config_system();
|
||||
|
||||
/// I'm not convinced you can even call this multiple times.
|
||||
pub fn pkg_cache_create() -> PCache;
|
||||
pub fn pkg_cache_release(cache: PCache);
|
||||
|
||||
@ -25,3 +29,15 @@ extern {
|
||||
pub fn pkg_iter_name(iterator: PPkgIterator) -> *const c_char;
|
||||
pub fn pkg_iter_pretty(cache: PCache, iterator: PPkgIterator) -> *mut c_char;
|
||||
}
|
||||
|
||||
static mut INIT_CONFIG_CALLED: bool = false;
|
||||
|
||||
pub unsafe fn init_config_system_once() {
|
||||
if INIT_CONFIG_CALLED {
|
||||
return;
|
||||
}
|
||||
|
||||
INIT_CONFIG_CALLED = true;
|
||||
|
||||
init_config_system()
|
||||
}
|
||||
|
@ -19,8 +19,11 @@ impl Drop for Cache {
|
||||
|
||||
impl Cache {
|
||||
pub fn new() -> Cache {
|
||||
Cache {
|
||||
ptr: unsafe { raw::pkg_cache_create() }
|
||||
unsafe {
|
||||
raw::init_config_system_once();
|
||||
Cache {
|
||||
ptr: raw::pkg_cache_create()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user