projects
/
ldk-c-bindings
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support building dependent crates with `no-std`
[ldk-c-bindings]
/
lightning-c-bindings
/
src
/
c_types
/
mod.rs
diff --git
a/lightning-c-bindings/src/c_types/mod.rs
b/lightning-c-bindings/src/c_types/mod.rs
index c0c44bcf7470ae4b65924b2b552b012b2fb9f688..e5449a5a934281953c977bd3ddc560e448989ef8 100644
(file)
--- a/
lightning-c-bindings/src/c_types/mod.rs
+++ b/
lightning-c-bindings/src/c_types/mod.rs
@@
-13,9
+13,13
@@
use bitcoin::secp256k1::recovery::RecoveryId;
use bitcoin::secp256k1::recovery::RecoverableSignature as SecpRecoverableSignature;
use bitcoin::bech32;
use bitcoin::secp256k1::recovery::RecoverableSignature as SecpRecoverableSignature;
use bitcoin::bech32;
-use std::convert::TryInto; // Bindings need at least rustc 1.34
+use core::convert::TryInto; // Bindings need at least rustc 1.34
+use core::ffi::c_void;
-use std::io::{Cursor, Read}; // TODO: We should use core2 here when we support no_std
+#[cfg(feature = "std")]
+pub(crate) use std::io::{self, Cursor, Read};
+#[cfg(feature = "no-std")]
+pub(crate) use core2::io::{self, Cursor, Read};
#[repr(C)]
/// A dummy struct of which an instance must never exist.
#[repr(C)]
/// A dummy struct of which an instance must never exist.
@@
-404,8
+408,8
@@
pub struct ThreeBytes { /** The three bytes */ pub data: [u8; 3], }
pub struct FourBytes { /** The four bytes */ pub data: [u8; 4], }
#[derive(Clone)]
#[repr(C)]
pub struct FourBytes { /** The four bytes */ pub data: [u8; 4], }
#[derive(Clone)]
#[repr(C)]
-/// A 1
0
-byte byte array.
-pub struct T
enBytes { /** The ten bytes */ pub data: [u8; 10
], }
+/// A 1
2
-byte byte array.
+pub struct T
welveBytes { /** The twelve bytes */ pub data: [u8; 12
], }
#[derive(Clone)]
#[repr(C)]
/// A 16-byte byte array.
#[derive(Clone)]
#[repr(C)]
/// A 16-byte byte array.
@@
-417,7
+421,7
@@
pub struct TwentyBytes { /** The twenty bytes */ pub data: [u8; 20], }
pub(crate) struct VecWriter(pub Vec<u8>);
impl lightning::util::ser::Writer for VecWriter {
pub(crate) struct VecWriter(pub Vec<u8>);
impl lightning::util::ser::Writer for VecWriter {
- fn write_all(&mut self, buf: &[u8]) -> Result<(),
::std::
io::Error> {
+ fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {
self.0.extend_from_slice(buf);
Ok(())
}
self.0.extend_from_slice(buf);
Ok(())
}
@@
-430,6
+434,9
@@
pub(crate) fn serialize_obj<I: lightning::util::ser::Writeable>(i: &I) -> derive
pub(crate) fn deserialize_obj<I: lightning::util::ser::Readable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> {
I::read(&mut s.to_slice())
}
pub(crate) fn deserialize_obj<I: lightning::util::ser::Readable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> {
I::read(&mut s.to_slice())
}
+pub(crate) fn maybe_deserialize_obj<I: lightning::util::ser::MaybeReadable>(s: u8slice) -> Result<Option<I>, lightning::ln::msgs::DecodeError> {
+ I::read(&mut s.to_slice())
+}
pub(crate) fn deserialize_obj_arg<A, I: lightning::util::ser::ReadableArgs<A>>(s: u8slice, args: A) -> Result<I, lightning::ln::msgs::DecodeError> {
I::read(&mut s.to_slice(), args)
}
pub(crate) fn deserialize_obj_arg<A, I: lightning::util::ser::ReadableArgs<A>>(s: u8slice, args: A) -> Result<I, lightning::ln::msgs::DecodeError> {
I::read(&mut s.to_slice(), args)
}
@@
-615,6
+622,18
@@
pub(crate) mod ObjOps {
}
}
}
}
+#[cfg(test_mod_pointers)]
+#[no_mangle]
+/// This function exists for memory safety testing purposes. It should never be used in production
+/// code
+pub extern "C" fn __unmangle_inner_ptr(ptr: *const c_void) -> *const c_void {
+ if ptr as usize == 1 {
+ core::ptr::null()
+ } else {
+ unsafe { ptr.cast::<u8>().sub(4096).cast::<c_void>() }
+ }
+}
+
pub(crate) struct SmartPtr<T> {
ptr: *mut T,
}
pub(crate) struct SmartPtr<T> {
ptr: *mut T,
}