X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FSleeper.cs;h=d086beb1632078a9e638c49054bd1fcf4fe6bdee;hb=HEAD;hp=348a692d57728b254f4cec150f0e34f8ac8077be;hpb=7811d2191440c55034e1abfbf3be442d4b25481b;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/Sleeper.cs b/c_sharp/src/org/ldk/structs/Sleeper.cs index 348a692d..d086beb1 100644 --- a/c_sharp/src/org/ldk/structs/Sleeper.cs +++ b/c_sharp/src/org/ldk/structs/Sleeper.cs @@ -20,7 +20,7 @@ public class Sleeper : CommonBase { * Constructs a new sleeper from one future, allowing blocking on it. */ public static Sleeper from_single_future(org.ldk.structs.Future future) { - long ret = bindings.Sleeper_from_single_future(future == null ? 0 : future.ptr); + long ret = bindings.Sleeper_from_single_future(future.ptr); GC.KeepAlive(future); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); } @@ -33,7 +33,7 @@ public class Sleeper : CommonBase { * Constructs a new sleeper from two futures, allowing blocking on both at once. */ public static Sleeper from_two_futures(org.ldk.structs.Future fut_a, org.ldk.structs.Future fut_b) { - long ret = bindings.Sleeper_from_two_futures(fut_a == null ? 0 : fut_a.ptr, fut_b == null ? 0 : fut_b.ptr); + long ret = bindings.Sleeper_from_two_futures(fut_a.ptr, fut_b.ptr); GC.KeepAlive(fut_a); GC.KeepAlive(fut_b); if (ret >= 0 && ret <= 4096) { return null; } @@ -48,12 +48,20 @@ public class Sleeper : CommonBase { * Constructs a new sleeper on many futures, allowing blocking on all at once. */ public static Sleeper of(Future[] futures) { - long ret = bindings.Sleeper_new(futures != null ? InternalUtils.mapArray(futures, futures_conv_8 => futures_conv_8 == null ? 0 : futures_conv_8.ptr) : null); + long ret = bindings.Sleeper_new(InternalUtils.encodeUint64Array(InternalUtils.mapArray(futures, futures_conv_8 => futures_conv_8.ptr))); GC.KeepAlive(futures); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.Sleeper ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Sleeper(null, ret); } if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); }; - foreach (Future futures_conv_8 in futures) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(futures_conv_8); }; }; + foreach (Future futures_conv_8 in futures) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(futures_conv_8); }; + // Due to rust's strict-ownership memory model, in some cases we need to "move" + // an object to pass exclusive ownership to the function being called. + // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object + // at the FFI layer, creating a new object which Rust can claim ownership of + // However, in some cases (eg here), there is no way to clone an object, and thus + // we actually have to pass full ownership to Rust. + // Thus, after ret_hu_conv call, futures_conv_8 is reset to null and is now a dummy object. + futures_conv_8.ptr = 0;; }; return ret_hu_conv; }