]> git.bitcoin.ninja Git - ldk-java/commitdiff
[Java] Add a reachabilityFence on underlying trait impl calls
authorMatt Corallo <git@bluematt.me>
Thu, 3 Mar 2022 02:32:15 +0000 (02:32 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 3 Mar 2022 06:26:21 +0000 (06:26 +0000)
Because the implementation instance is implicitly held as a
reference in the `held` field, it seems unlikely this could ever
matter, hwoever, in the simplified implementation in `PeerTest`
(where there is no Human instance to hold a reference to the
underlying bindings instance), we do see the implementation being
free'd while its still in use. Thus, to ensure we can't hit any
such issue in the future, we add one in normal human objects as
well.

java_strings.py
src/test/java/org/ldk/PeerTest.java

index cc1a361702794047eec6026db366d63ff94771a2..3a8ba6cb613047a728cb77a09abd7b5557664aba 100644 (file)
@@ -882,7 +882,8 @@ import javax.annotation.Nullable;
                     else:
                         java_trait_constr = java_trait_constr + arg_info.arg_name
 
-                java_trait_constr = java_trait_constr + ");\n"
+                java_trait_constr += ");\n"
+                java_trait_constr += "\t\t\t\tReference.reachabilityFence(arg);\n"
                 if fn_line.ret_ty_info.java_ty != "void":
                     if fn_line.ret_ty_info.from_hu_conv is not None:
                         java_trait_constr = java_trait_constr + "\t\t\t\t" + fn_line.ret_ty_info.java_ty + " result = " + fn_line.ret_ty_info.from_hu_conv[0] + ";\n"
index 7dc3f1a39df568c31362d562388836752e2076a8..9b3d2f1702b97fa757ac4849550d7c487eb88348 100644 (file)
@@ -7,6 +7,7 @@ import org.ldk.enums.Network;
 import org.ldk.enums.Recipient;
 import org.ldk.impl.bindings;
 
+import java.lang.ref.Reference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -234,7 +235,8 @@ public class PeerTest {
         deliver_peer_messages(list, peer1.peer_manager, peer2.peer_manager);
 
         ArrayList<Long> events = new ArrayList();
-        long handler = bindings.LDKEventHandler_new(events::add);
+        bindings.LDKEventHandler events_adder = events::add;
+        long handler = bindings.LDKEventHandler_new(events_adder);
 
         bindings.EventsProvider_process_pending_events(peer1.chan_manager_events, handler);
         assert events.size() == 1;
@@ -336,6 +338,7 @@ public class PeerTest {
         bindings.LDKEvent sent_path = bindings.LDKEvent_ref_from_ptr(events.get(0));
         assert sent_path instanceof bindings.LDKEvent.PaymentPathSuccessful;
         bindings.Event_free(events.remove(0));
+        Reference.reachabilityFence(events_adder);
 
         bindings.EventHandler_free(handler);