Bindings updates
[ldk-java] / ts / structs / RouteHop.ts
index 6a943251a6123b289cc2177e1bf8998e85818796..f03f698946c28badb6ab6702ea519b94eee9c016 100644 (file)
@@ -21,6 +21,7 @@ import * as bindings from '../bindings' // TODO: figure out location
        public RouteHop clone() {
                number ret = bindings.RouteHop_clone(this.ptr);
                const ret_hu_conv: RouteHop = new RouteHop(null, ret);
+               ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
        }
 
@@ -36,12 +37,21 @@ import * as bindings from '../bindings' // TODO: figure out location
        public NodeFeatures get_node_features() {
                number ret = bindings.RouteHop_get_node_features(this.ptr);
                const ret_hu_conv: NodeFeatures = new NodeFeatures(null, ret);
+               ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
        }
 
        public void set_node_features(NodeFeatures val) {
                bindings.RouteHop_set_node_features(this.ptr, val == null ? 0 : val.ptr & ~1);
                this.ptrs_to.add(val);
+               // 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 this 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 this call, val is reset to null and is now a dummy object.
+               val.ptr = 0;
        }
 
        public number get_short_channel_id() {
@@ -56,12 +66,21 @@ import * as bindings from '../bindings' // TODO: figure out location
        public ChannelFeatures get_channel_features() {
                number ret = bindings.RouteHop_get_channel_features(this.ptr);
                const ret_hu_conv: ChannelFeatures = new ChannelFeatures(null, ret);
+               ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
        }
 
        public void set_channel_features(ChannelFeatures val) {
                bindings.RouteHop_set_channel_features(this.ptr, val == null ? 0 : val.ptr & ~1);
                this.ptrs_to.add(val);
+               // 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 this 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 this call, val is reset to null and is now a dummy object.
+               val.ptr = 0;
        }
 
        public number get_fee_msat() {
@@ -85,8 +104,25 @@ import * as bindings from '../bindings' // TODO: figure out location
        public static RouteHop constructor_new(Uint8Array pubkey_arg, NodeFeatures node_features_arg, number short_channel_id_arg, ChannelFeatures channel_features_arg, number fee_msat_arg, number cltv_expiry_delta_arg) {
                number ret = bindings.RouteHop_new(pubkey_arg, node_features_arg == null ? 0 : node_features_arg.ptr & ~1, short_channel_id_arg, channel_features_arg == null ? 0 : channel_features_arg.ptr & ~1, fee_msat_arg, cltv_expiry_delta_arg);
                const ret_hu_conv: RouteHop = new RouteHop(null, ret);
+               ret_hu_conv.ptrs_to.add(ret_hu_conv);
                ret_hu_conv.ptrs_to.add(node_features_arg);
+               // 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, node_features_arg is reset to null and is now a dummy object.
+               node_features_arg.ptr = 0;
                ret_hu_conv.ptrs_to.add(channel_features_arg);
+               // 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, channel_features_arg is reset to null and is now a dummy object.
+               channel_features_arg.ptr = 0;
                return ret_hu_conv;
        }