Cut down on unstable features in openssl-sys

* Move from `old_path` to `path` (leveraging the `fs` feature as well)
* Move from `StaticMutex` to `Mutex<()>` as they're dynamically initialized
This commit is contained in:
Alex Crichton 2015-03-04 14:14:05 -08:00
parent 5154581c32
commit 1c9b8a029b
3 changed files with 16 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#![feature(env, path)] #![feature(path)]
extern crate "pkg-config" as pkg_config; extern crate "pkg-config" as pkg_config;
extern crate gcc; extern crate gcc;

View File

@ -1,6 +1,6 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
#![allow(dead_code)] #![allow(dead_code)]
#![feature(core, old_io, old_path, std_misc, env)] #![feature(path, fs)]
#![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl-sys")] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl-sys")]
extern crate libc; extern crate libc;
@ -11,7 +11,7 @@ extern crate "libressl-pnacl-sys" as _for_linkage;
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t}; use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::sync::{StaticMutex, MutexGuard, MUTEX_INIT}; use std::sync::{Mutex, MutexGuard};
use std::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT};
pub type ASN1_INTEGER = c_void; pub type ASN1_INTEGER = c_void;
@ -193,7 +193,7 @@ pub const X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: c_int = 45;
pub const X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: c_int = 53; pub const X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: c_int = 53;
pub const X509_V_OK: c_int = 0; pub const X509_V_OK: c_int = 0;
static mut MUTEXES: *mut Vec<StaticMutex> = 0 as *mut Vec<StaticMutex>; static mut MUTEXES: *mut Vec<Mutex<()>> = 0 as *mut Vec<Mutex<()>>;
static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> = 0 as *mut Vec<Option<MutexGuard<'static, ()>>>; static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> = 0 as *mut Vec<Option<MutexGuard<'static, ()>>>;
extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char, extern fn locking_function(mode: c_int, n: c_int, _file: *const c_char,
@ -220,11 +220,11 @@ pub fn init() {
let num_locks = CRYPTO_num_locks(); let num_locks = CRYPTO_num_locks();
let mut mutexes = Box::new(Vec::new()); let mut mutexes = Box::new(Vec::new());
for _ in 0..num_locks { for _ in 0..num_locks {
mutexes.push(MUTEX_INIT); mutexes.push(Mutex::new(()));
} }
MUTEXES = mem::transmute(mutexes); MUTEXES = mem::transmute(mutexes);
let guards: Box<Vec<Option<MutexGuard<()>>>> = let guards: Box<Vec<Option<MutexGuard<()>>>> =
Box::new(range(0, num_locks).map(|_| None).collect()); Box::new((0..num_locks).map(|_| None).collect());
GUARDS = mem::transmute(guards); GUARDS = mem::transmute(guards);
CRYPTO_set_locking_callback(locking_function); CRYPTO_set_locking_callback(locking_function);

View File

@ -1,16 +1,17 @@
use std::env; use std::env;
use std::old_io::fs::PathExtensions; use std::fs::PathExt;
use std::path::PathBuf;
pub struct ProbeResult { pub struct ProbeResult {
pub cert_file: Option<Path>, pub cert_file: Option<PathBuf>,
pub cert_dir: Option<Path>, pub cert_dir: Option<PathBuf>,
} }
/// Probe the system for the directory in which CA certificates should likely be /// Probe the system for the directory in which CA certificates should likely be
/// found. /// found.
/// ///
/// This will only search known system locations. /// This will only search known system locations.
pub fn find_certs_dirs() -> Vec<Path> { pub fn find_certs_dirs() -> Vec<PathBuf> {
// see http://gagravarr.org/writing/openssl-certs/others.shtml // see http://gagravarr.org/writing/openssl-certs/others.shtml
[ [
"/var/ssl", "/var/ssl",
@ -23,7 +24,7 @@ pub fn find_certs_dirs() -> Vec<Path> {
"/etc/openssl", "/etc/openssl",
"/etc/pki/tls", "/etc/pki/tls",
"/etc/ssl", "/etc/ssl",
].iter().map(|s| Path::new(*s)).filter(|p| { ].iter().map(|s| PathBuf::new(*s)).filter(|p| {
p.exists() p.exists()
}).collect() }).collect()
} }
@ -39,7 +40,7 @@ pub fn init_ssl_cert_env_vars() {
None => {} None => {}
} }
fn put(var: &str, path: Path) { fn put(var: &str, path: PathBuf) {
// Don't stomp over what anyone else has set // Don't stomp over what anyone else has set
match env::var(var) { match env::var(var) {
Ok(..) => {} Ok(..) => {}
@ -50,8 +51,8 @@ pub fn init_ssl_cert_env_vars() {
pub fn probe() -> ProbeResult { pub fn probe() -> ProbeResult {
let mut result = ProbeResult { let mut result = ProbeResult {
cert_file: env::var("SSL_CERT_FILE").ok().map(Path::new), cert_file: env::var_os("SSL_CERT_FILE").map(|s| PathBuf::new(&s)),
cert_dir: env::var("SSL_CERT_DIR").ok().map(Path::new), cert_dir: env::var_os("SSL_CERT_DIR").map(|s| PathBuf::new(&s)),
}; };
for certs_dir in find_certs_dirs().iter() { for certs_dir in find_certs_dirs().iter() {
// cert.pem looks to be an openssl 1.0.1 thing, while // cert.pem looks to be an openssl 1.0.1 thing, while
@ -65,7 +66,7 @@ pub fn probe() -> ProbeResult {
result result
} }
fn try(dst: &mut Option<Path>, val: Path) { fn try(dst: &mut Option<PathBuf>, val: PathBuf) {
if dst.is_none() && val.exists() { if dst.is_none() && val.exists() {
*dst = Some(val); *dst = Some(val);
} }