writeln!(w, "\tpub result: *mut {},", ok_type).unwrap();
} else {
writeln!(w, "\t/// Note that this value is always NULL, as there are no contents in the OK variant").unwrap();
- writeln!(w, "\tpub result: *mut std::ffi::c_void,").unwrap();
+ writeln!(w, "\tpub result: *mut core::ffi::c_void,").unwrap();
}
if err_type != "()" {
writeln!(w, "\t/// A pointer to the contents in the error state.").unwrap();
writeln!(w, "\tpub err: *mut {},", err_type).unwrap();
} else {
writeln!(w, "\t/// Note that this value is always NULL, as there are no contents in the Err variant").unwrap();
- writeln!(w, "\tpub err: *mut std::ffi::c_void,").unwrap();
+ writeln!(w, "\tpub err: *mut core::ffi::c_void,").unwrap();
}
writeln!(w, "}}").unwrap();
writeln!(w, "#[repr(C)]").unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\tresult: Box::into_raw(Box::new(o)),").unwrap();
} else {
- writeln!(w, "\t\t\tresult: std::ptr::null_mut(),").unwrap();
+ writeln!(w, "\t\t\tresult: core::ptr::null_mut(),").unwrap();
}
writeln!(w, "\t\t}},").unwrap();
writeln!(w, "\t\tresult_ok: true,").unwrap();
if err_type != "()" {
writeln!(w, "\t\t\terr: Box::into_raw(Box::new(e)),").unwrap();
} else {
- writeln!(w, "\t\t\terr: std::ptr::null_mut(),").unwrap();
+ writeln!(w, "\t\t\terr: core::ptr::null_mut(),").unwrap();
}
writeln!(w, "\t\t}},").unwrap();
writeln!(w, "\t\tresult_ok: false,").unwrap();
writeln!(w, "\t\tlet contents = if o.result_ok {{").unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\tlet result = unsafe {{ o.contents.result }};").unwrap();
- writeln!(w, "\t\t\tunsafe {{ o.contents.result = std::ptr::null_mut() }};").unwrap();
+ writeln!(w, "\t\t\tunsafe {{ o.contents.result = core::ptr::null_mut() }};").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ result }}", mangled_container).unwrap();
} else {
writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(o.contents.result) }};").unwrap();
- writeln!(w, "\t\t\to.contents.result = std::ptr::null_mut();").unwrap();
- writeln!(w, "\t\t\t{}Ptr {{ result: std::ptr::null_mut() }}", mangled_container).unwrap();
+ writeln!(w, "\t\t\to.contents.result = core::ptr::null_mut();").unwrap();
+ writeln!(w, "\t\t\t{}Ptr {{ result: core::ptr::null_mut() }}", mangled_container).unwrap();
}
writeln!(w, "\t\t}} else {{").unwrap();
if err_type != "()" {
writeln!(w, "\t\t\tlet err = unsafe {{ o.contents.err }};").unwrap();
- writeln!(w, "\t\t\tunsafe {{ o.contents.err = std::ptr::null_mut(); }}").unwrap();
+ writeln!(w, "\t\t\tunsafe {{ o.contents.err = core::ptr::null_mut(); }}").unwrap();
writeln!(w, "\t\t\t{}Ptr {{ err }}", mangled_container).unwrap();
} else {
writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(o.contents.err) }};").unwrap();
- writeln!(w, "\t\t\to.contents.err = std::ptr::null_mut();").unwrap();
- writeln!(w, "\t\t\t{}Ptr {{ err: std::ptr::null_mut() }}", mangled_container).unwrap();
+ writeln!(w, "\t\t\to.contents.err = core::ptr::null_mut();").unwrap();
+ writeln!(w, "\t\t\t{}Ptr {{ err: core::ptr::null_mut() }}", mangled_container).unwrap();
}
writeln!(w, "\t\t}};").unwrap();
writeln!(w, "\t\tSelf {{").unwrap();
if ok_type != "()" {
writeln!(w, "\t\t\t\tresult: Box::into_raw(Box::new(<{}>::clone(unsafe {{ &*self.contents.result }})))", ok_type).unwrap();
} else {
- writeln!(w, "\t\t\t\tresult: std::ptr::null_mut()").unwrap();
+ writeln!(w, "\t\t\t\tresult: core::ptr::null_mut()").unwrap();
}
writeln!(w, "\t\t\t}} }}").unwrap();
writeln!(w, "\t\t}} else {{").unwrap();
if err_type != "()" {
writeln!(w, "\t\t\t\terr: Box::into_raw(Box::new(<{}>::clone(unsafe {{ &*self.contents.err }})))", err_type).unwrap();
} else {
- writeln!(w, "\t\t\t\terr: std::ptr::null_mut()").unwrap();
+ writeln!(w, "\t\t\t\terr: core::ptr::null_mut()").unwrap();
}
writeln!(w, "\t\t\t}} }}").unwrap();
writeln!(w, "\t\t}}").unwrap();
writeln!(w, "impl {} {{", mangled_container).unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec<{}> {{", inner_type).unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return Vec::new(); }}").unwrap();
- writeln!(w, "\t\tlet ret = unsafe {{ Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }}.into();").unwrap();
- writeln!(w, "\t\tself.data = std::ptr::null_mut();").unwrap();
+ writeln!(w, "\t\tlet ret = unsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }}.into();").unwrap();
+ writeln!(w, "\t\tself.data = core::ptr::null_mut();").unwrap();
writeln!(w, "\t\tself.datalen = 0;").unwrap();
writeln!(w, "\t\tret").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "\t#[allow(unused)] pub(crate) fn as_slice(&self) -> &[{}] {{", inner_type).unwrap();
- writeln!(w, "\t\tunsafe {{ std::slice::from_raw_parts_mut(self.data, self.datalen) }}").unwrap();
+ writeln!(w, "\t\tunsafe {{ core::slice::from_raw_parts_mut(self.data, self.datalen) }}").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
writeln!(w, "impl Drop for {} {{", mangled_container).unwrap();
writeln!(w, "\tfn drop(&mut self) {{").unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return; }}").unwrap();
- writeln!(w, "\t\tunsafe {{ Box::from_raw(std::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
+ writeln!(w, "\t\tunsafe {{ Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }};").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
if clonable {
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
writeln!(w, "\t\tlet mut res = Vec::new();").unwrap();
writeln!(w, "\t\tif self.datalen == 0 {{ return Self::from(res); }}").unwrap();
- writeln!(w, "\t\tres.extend_from_slice(unsafe {{ std::slice::from_raw_parts_mut(self.data, self.datalen) }});").unwrap();
+ writeln!(w, "\t\tres.extend_from_slice(unsafe {{ core::slice::from_raw_parts_mut(self.data, self.datalen) }});").unwrap();
writeln!(w, "\t\tSelf::from(res)").unwrap();
writeln!(w, "\t}}").unwrap();
writeln!(w, "}}").unwrap();
// Implement supertraits for the C-mapped struct.
walk_supertraits!(t, Some(&types), (
("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
- writeln!(w, "impl std::cmp::Eq for {} {{}}", trait_name).unwrap();
- writeln!(w, "impl std::cmp::PartialEq for {} {{", trait_name).unwrap();
+ writeln!(w, "impl core::cmp::Eq for {} {{}}", trait_name).unwrap();
+ writeln!(w, "impl core::cmp::PartialEq for {} {{", trait_name).unwrap();
writeln!(w, "\tfn eq(&self, o: &Self) -> bool {{ (self.eq)(self.this_arg, o) }}\n}}").unwrap();
},
("std::hash::Hash", _)|("core::hash::Hash", _) => {
- writeln!(w, "impl std::hash::Hash for {} {{", trait_name).unwrap();
- writeln!(w, "\tfn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap();
+ writeln!(w, "impl core::hash::Hash for {} {{", trait_name).unwrap();
+ writeln!(w, "\tfn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap();
},
("Send", _) => {}, ("Sync", _) => {},
("Clone", _) => {
writeln!(w, "}}\n").unwrap();
writeln!(w, "// We're essentially a pointer already, or at least a set of pointers, so allow us to be used").unwrap();
writeln!(w, "// directly as a Deref trait in higher-level structs:").unwrap();
- writeln!(w, "impl std::ops::Deref for {} {{\n\ttype Target = Self;", trait_name).unwrap();
+ writeln!(w, "impl core::ops::Deref for {} {{\n\ttype Target = Self;", trait_name).unwrap();
writeln!(w, "\tfn deref(&self) -> &Self {{\n\t\tself\n\t}}\n}}").unwrap();
}
writeln!(w, "\tpub(crate) fn take_inner(mut self) -> *mut native{} {{", struct_name).unwrap();
writeln!(w, "\t\tassert!(self.is_owned);").unwrap();
writeln!(w, "\t\tlet ret = ObjOps::untweak_ptr(self.inner);").unwrap();
- writeln!(w, "\t\tself.inner = std::ptr::null_mut();").unwrap();
+ writeln!(w, "\t\tself.inner = core::ptr::null_mut();").unwrap();
writeln!(w, "\t\tret").unwrap();
writeln!(w, "\t}}\n}}").unwrap();
writeln!(w, "\t\tlet mut rust_obj = {} {{ inner: ObjOps::heap_alloc(obj), is_owned: true }};", ident).unwrap();
writeln!(w, "\t\tlet mut ret = {}_as_{}(&rust_obj);", ident, trait_obj.ident).unwrap();
writeln!(w, "\t\t// We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn").unwrap();
- writeln!(w, "\t\trust_obj.inner = std::ptr::null_mut();").unwrap();
+ writeln!(w, "\t\trust_obj.inner = core::ptr::null_mut();").unwrap();
writeln!(w, "\t\tret.free = Some({}_free_void);", ident).unwrap();
writeln!(w, "\t\tret").unwrap();
}
let ref_type: syn::Type = syn::parse_quote!(&#path);
assert!(!types.write_to_c_conversion_new_var(w, &format_ident!("a"), &*i.self_ty, Some(&gen_types), false), "We don't support new var conversions when comparing equality");
- writeln!(w, "\t// Note that we'd love to use std::collections::hash_map::DefaultHasher but it's not in core").unwrap();
+ writeln!(w, "\t// Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core").unwrap();
writeln!(w, "\t#[allow(deprecated)]").unwrap();
writeln!(w, "\tlet mut hasher = core::hash::SipHasher::new();").unwrap();
- write!(w, "\tstd::hash::Hash::hash(").unwrap();
+ write!(w, "\tcore::hash::Hash::hash(").unwrap();
types.write_from_c_conversion_prefix(w, &ref_type, Some(&gen_types));
write!(w, "o").unwrap();
types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types));
writeln!(w, ", &mut hasher);").unwrap();
- writeln!(w, "\tstd::hash::Hasher::finish(&hasher)\n}}").unwrap();
+ writeln!(w, "\tcore::hash::Hasher::finish(&hasher)\n}}").unwrap();
} else if (path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) || path_matches_nongeneric(&trait_path.1, &["Clone"])) &&
types.c_type_has_inner_from_path(&resolved_path) {
writeln!(w, "impl Clone for {} {{", ident).unwrap();
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
writeln!(w, "\t\tSelf {{").unwrap();
- writeln!(w, "\t\t\tinner: if <*mut native{}>::is_null(self.inner) {{ std::ptr::null_mut() }} else {{", ident).unwrap();
+ writeln!(w, "\t\t\tinner: if <*mut native{}>::is_null(self.inner) {{ core::ptr::null_mut() }} else {{", ident).unwrap();
writeln!(w, "\t\t\t\tObjOps::heap_alloc(unsafe {{ &*ObjOps::untweak_ptr(self.inner) }}.clone()) }},").unwrap();
writeln!(w, "\t\t\tis_owned: true,").unwrap();
writeln!(w, "\t\t}}\n\t}}\n}}").unwrap();
"core::convert::Infallible" => Some("panic!(\"You must never construct a NotConstructable! : "),
- "std::time::Duration"|"core::time::Duration" => Some("std::time::Duration::from_secs("),
+ "std::time::Duration"|"core::time::Duration" => Some("core::time::Duration::from_secs("),
"std::time::SystemTime" => Some("(::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs("),
"bech32::u5" => Some(""),
let is_inner_ref = if let Some(syn::Type::Reference(_)) = single_contained { true } else { false };
if is_ref {
return Some(("if ", vec![
- (".is_none() { std::ptr::null() } else { ObjOps::nonnull_ptr_to_inner(".to_owned(),
+ (".is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner(".to_owned(),
format!("({}{}.unwrap())", var_access, if is_inner_ref { "" } else { ".as_ref()" }))
], ") }", ContainerPrefixLocation::OutsideConv));
} else {
return Some(("if ", vec![
- (".is_none() { std::ptr::null_mut() } else { ".to_owned(), format!("({}.unwrap())", var_access))
+ (".is_none() { core::ptr::null_mut() } else { ".to_owned(), format!("({}.unwrap())", var_access))
], " }", ContainerPrefixLocation::OutsideConv));
}
} else if self.is_primitive(&inner_path) || self.c_type_from_path(&inner_path, false, false).is_none() {
syn::Type::Path(p) => {
let resolved = self.resolve_path(&p.path, generics);
if self.crate_types.opaques.get(&resolved).is_some() {
- write!(w, "crate::{} {{ inner: std::ptr::null_mut(), is_owned: true }}", resolved).unwrap();
+ write!(w, "crate::{} {{ inner: core::ptr::null_mut(), is_owned: true }}", resolved).unwrap();
} else {
// Assume its a manually-mapped C type, where we can just define an null() fn
write!(w, "{}::null()", self.c_type_from_path(&resolved, false, false).unwrap()).unwrap();
syn::Type::Slice(_) => {
// Option<[]> always implies that we want to treat len() == 0 differently from
// None, so we always map an Option<[]> into a pointer.
- write!(w, " == std::ptr::null_mut()").unwrap();
+ write!(w, " == core::ptr::null_mut()").unwrap();
EmptyValExpectedTy::ReferenceAsPointer
},
_ => unimplemented!(),
}
pub(crate) fn into_bitcoin(&self) -> BitcoinTransaction {
if self.datalen == 0 { panic!("0-length buffer can never represent a valid Transaction"); }
- ::bitcoin::consensus::encode::deserialize(unsafe { std::slice::from_raw_parts(self.data, self.datalen) }).unwrap()
+ ::bitcoin::consensus::encode::deserialize(unsafe { core::slice::from_raw_parts(self.data, self.datalen) }).unwrap()
}
pub(crate) fn from_bitcoin(btc: &BitcoinTransaction) -> Self {
let vec = ::bitcoin::consensus::encode::serialize(btc);
}
impl Clone for Transaction {
fn clone(&self) -> Self {
- let sl = unsafe { std::slice::from_raw_parts(self.data, self.datalen) };
+ let sl = unsafe { core::slice::from_raw_parts(self.data, self.datalen) };
let mut v = Vec::new();
v.extend_from_slice(&sl);
Self::from_vec(v)
}
pub(crate) fn to_slice(&self) -> &[u8] {
if self.datalen == 0 { return &[]; }
- unsafe { std::slice::from_raw_parts(self.data, self.datalen) }
+ unsafe { core::slice::from_raw_parts(self.data, self.datalen) }
}
pub(crate) fn to_reader<'a>(&'a self) -> Cursor<&'a [u8]> {
let sl = self.to_slice();
impl Str {
pub(crate) fn into_str(&self) -> &'static str {
if self.len == 0 { return ""; }
- std::str::from_utf8(unsafe { std::slice::from_raw_parts(self.chars, self.len) }).unwrap()
+ core::str::from_utf8(unsafe { core::slice::from_raw_parts(self.chars, self.len) }).unwrap()
}
pub(crate) fn into_string(mut self) -> String {
let bytes = if self.len == 0 {
Vec::new()
} else if self.chars_is_owned {
let ret = unsafe {
- Box::from_raw(std::slice::from_raw_parts_mut(unsafe { self.chars as *mut u8 }, self.len))
+ Box::from_raw(core::slice::from_raw_parts_mut(unsafe { self.chars as *mut u8 }, self.len))
}.into();
self.chars_is_owned = false;
ret
} else {
let mut ret = Vec::with_capacity(self.len);
- ret.extend_from_slice(unsafe { std::slice::from_raw_parts(self.chars, self.len) });
+ ret.extend_from_slice(unsafe { core::slice::from_raw_parts(self.chars, self.len) });
ret
};
String::from_utf8(bytes).unwrap()
impl<T> TakePointer<*const T> for *const T {
fn take_ptr(&mut self) -> *const T {
let ret = *self;
- *self = std::ptr::null();
+ *self = core::ptr::null();
ret
}
}
impl<T> TakePointer<*mut T> for *mut T {
fn take_ptr(&mut self) -> *mut T {
let ret = *self;
- *self = std::ptr::null_mut();
+ *self = core::ptr::null_mut();
ret
}
}
Self { ptr: Box::into_raw(Box::new(o)) }
}
pub(crate) fn null() -> Self {
- Self { ptr: std::ptr::null_mut() }
+ Self { ptr: core::ptr::null_mut() }
}
}
impl<T> Drop for SmartPtr<T> {
fn drop(&mut self) {
- if self.ptr != std::ptr::null_mut() {
+ if self.ptr != core::ptr::null_mut() {
unsafe { Box::from_raw(self.ptr); }
}
}
}
-impl<T> std::ops::Deref for SmartPtr<T> {
+impl<T> core::ops::Deref for SmartPtr<T> {
type Target = *mut T;
fn deref(&self) -> &*mut T {
&self.ptr