Matt Corallo [Wed, 22 Sep 2021 18:39:46 +0000 (18:39 +0000)]
Correct printing generic methods in traits
If a trait method is generic (and not the object itself), we
previously would print the concrete resolved types in the
`impl nativeTrait for TraitStruct` block instead of the generic
names, leading to compilation failures.
Matt Corallo [Mon, 6 Sep 2021 00:53:56 +0000 (00:53 +0000)]
Map Vecs to slices when constructing a getter for a public field
This adds logic to allow constructing a getter for a public Vec
field where the inner items are opaque structs. In order to do this
we map them as slices, which will end up generating Vecs with
elements which all have their `is_owned` flags unset.
Matt Corallo [Wed, 18 Aug 2021 21:51:28 +0000 (21:51 +0000)]
Differentiate `inner` pointers representing `None` and `Some(ZST)`
For zero-sized-types, rust `Box::into_inner(Box::new(ZST {}))`
returns `1usize as *mut ZST`, which confuses our Java bindings
which check for `None` by checking if `inner < 1024`. While we
could convert the Java bindings to check for `inner == 0`, the
magic value for ZST pointers is not, to my knowledge, an ABI
guarantee Rust provides.
Instead, we add an offset to the `inner` pointers to push them
past the zero page for ZSTs, taking this opportunity to clean up
some of our pointer conversion and push them through a common set
of utility functions.
We also add testing infrastructure to add similar offsets to
non-ZSTs to get good test coverage of the offset addition-removal,
though Rust should largely be ignoring pointer values for ZSTs
anyway so there should be little risk in anything going wrong here.
Matt Corallo [Sat, 7 Aug 2021 19:03:27 +0000 (19:03 +0000)]
Add utility method to construct new complex enums
This is incredibly useful for downstream languages eg Java as it
avoids having to manually implement constructors and can just use
common function-mapping logic.
Matt Corallo [Thu, 5 Aug 2021 01:53:48 +0000 (01:53 +0000)]
Note which parameters or return values are (secretly) Options
Because `Option<OpaqueType>` is mapped the same as `OpaqueType` its
not immediately clear which values in the API are actually
`Option<>`al. Thus, we should at least have documentation noting
this.
Matt Corallo [Wed, 21 Jul 2021 18:51:54 +0000 (18:51 +0000)]
Expose struct method calls on trait structs to C++ directly
We can add method calls for non-trait structs later, but this is
particularly useful as otherwise you need to extract both the
method and the `this_arg` to make the call.
Matt Corallo [Sun, 18 Jul 2021 02:09:45 +0000 (02:09 +0000)]
Provide full (new) struct to trait clone functions
Previously, when we went to clone a trait-implementation struct,
we'd provide only the `this_arg` void pointer, requiring that the
`this_arg` pointer be cloned into a new object while all remaining
fields are copied over exactly.
This has a few important limitations:
* When a struct is cloned, it is not possible to set a `free`
function to free any new data placed in `this_arg` without it
also being set on the original struct.
* Supertrait fields cannot be updated in the subtrait clone
method, including the `this_arg` and `free` methods.
The first limitation prevents us from setting `free` after a clone
when the original trait may or may not have had `free` set. For
example, if the original trait was created with a `Obj_as_Trait`
method, cloned copies would never be free'd.
The second limitation prevents us from keeping the super and
subtrait `this_arg` fields in sync, in addition to limitations
similar to the above.
This resulted in Java code double-free'ing the `this_arg` field in
`InMemorySigner` objects which were accessed as both `Sign` and
`BaseSign` traits.
Matt Corallo [Wed, 28 Jul 2021 00:39:47 +0000 (00:39 +0000)]
If we're leaving binaries around, use -fPIC for ldk_net.o
This is needed if downstream projects want to just take our
ldk_net.o binary and link them in directly, eg with addrsan to
avoid figuring out exact compile flags.
Matt Corallo [Tue, 6 Jul 2021 22:07:42 +0000 (22:07 +0000)]
Drop -flto from non-cross-language-lto C++ demo builds
It appears somehow the LLVM IR is slipping into the Rust library,
causing Ubunto link to fail with the following error:
/usr/bin/ld: error: LLVM gold plugin has failed to create LTO module: Invalid record
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Matt Corallo [Wed, 14 Apr 2021 02:58:12 +0000 (22:58 -0400)]
Impl Send+Sync for every trait, not just those with it explicit
Because Send+Sync are generated by the compiler for us, we don't
really know when we should or should not generate it. That said,
Send+Sync aren't exposed outside of Rust, so it only impacts
whether we can use a type when passed to Rust, not how users will
ultimately interact with types.
Matt Corallo [Sun, 30 May 2021 16:17:25 +0000 (16:17 +0000)]
Add an export tag to indicate users cannot implement a given trait
Specifically, for the LDK `EventsProvider` trait, we can't
(trivially) implement the `process_pending_events` function,
defined as:
`fn process_pending_events<H: Deref>(&self, handler: H) where H::Target: EventHandler;`
We currently do not support implementing generic methods, as we'd
need to wrap them in a generic Rust-trait-to-C-trait conversion
utility, which we do not currently have. Thus, because users
almost certainly have no reason to implement the `EventsProvider`
themselves, its simpler to simply prevent the use of the C trait
struct as the Rust trait.
Concretely, this means just skipping the
`impl rustEventsProvider for CEventsProvider` block, which works
fine as no Rust functions take an `EventsProvider` as an argument.
Matt Corallo [Mon, 3 May 2021 17:52:43 +0000 (17:52 +0000)]
Fix handling of returning Option<&Object> from Rust functions
Specifically, these were previously mapped by calling
`<object.as_ref().unwrap() as *const _>`, taking a pointer to the
option on stack instead of a pointer to the option itself.
We just need to drop the `as_ref()` to make it correct.