]> git.bitcoin.ninja Git - ldk-java/commitdiff
Work around our stupid hack with a stupid hack (see XXX in genbindings.py)
authorMatt Corallo <git@bluematt.me>
Mon, 1 Mar 2021 17:24:11 +0000 (12:24 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 5 Mar 2021 19:40:22 +0000 (14:40 -0500)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index dfb2b57edddd69b16d0489372ae0d494e2ab701b..afd19979ea297ff788d87c26c35eca9ec44d7f06 100644 (file)
@@ -32,6 +32,8 @@ class TypeMappingGenerator:
             else:
                 arr_name = "ret"
                 arr_len = ret_arr_len
+            if arr_name == "arg":
+                arr_name = "ret"
             if ty_info.c_ty == "int8_tArray":
                 (set_pfx, set_sfx) = self.consts.set_native_arr_contents(arr_name + "_arr", arr_len, ty_info)
                 ret_conv = ("int8_tArray " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
@@ -70,7 +72,9 @@ class TypeMappingGenerator:
             else:
                 assert not arr_len.isdigit() # fixed length arrays not implemented
                 assert ty_info.java_ty[len(ty_info.java_ty) - 2:] == "[]"
-                conv_name = "arr_conv_" + str(len(ty_info.java_hu_ty))
+                if arr_name == "":
+                    arr_name = "ret"
+                conv_name = arr_name + "_conv_" + str(len(ty_info.java_hu_ty))
                 idxc = chr(ord('a') + (len(ty_info.java_hu_ty) % 26))
                 ty_info.subty.var_name = conv_name
                 #XXX: We'd really prefer to only ever set to False, avoiding lots of clone, but need smarter free logic
@@ -84,8 +88,6 @@ class TypeMappingGenerator:
                     # ChannelMonitors inside of vecs.
                     ty_info.subty.requires_clone = False
                 subty = self.map_type_with_info(ty_info.subty, False, None, is_free, holds_ref)
-                if arr_name == "":
-                    arr_name = "arg"
                 arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n"
                 arg_conv = arg_conv + arr_name + "_constr." + arr_len + " = " + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + ";\n"
                 arg_conv = arg_conv + "if (" + arr_name + "_constr." + arr_len + " > 0)\n"
@@ -120,8 +122,6 @@ class TypeMappingGenerator:
                 if ty_info.is_ptr:
                     arg_conv_cleanup = "FREE(" + arr_name + "_constr." + ty_info.arr_access + ");"
 
-                if arr_name == "arg":
-                    arr_name = "ret"
                 ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "")
                 if subty.ret_conv is None:
                     ret_conv = ("DUMMY", "DUMMY")
index e6a17ebd5dde9756eac644d05481b8e1b6be0154..4b2ae77fe7f308cfddf7d278071c7bf6ad06a14a 100644 (file)
@@ -198,7 +198,7 @@ void __attribute__((destructor)) check_leaks() {
        size_t alloc_count = 0;
        size_t alloc_size = 0;
        for (allocation* a = allocation_ll; a != NULL; a = a->next) {
-               fprintf(stderr, "%s %p remains:\\n", a->struct_name, a->ptr);
+               fprintf(stderr, "%s %p (%lu bytes) remains:\\n", a->struct_name, a->ptr, a->alloc_len);
                backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
                fprintf(stderr, "\\n\\n");
                alloc_count++;
@@ -651,7 +651,7 @@ import java.util.Arrays;
 
                 out_c = out_c + "\tjobject obj = (*env)->NewLocalRef(env, j_calls->o);\n\tCHECK(obj != NULL);\n"
                 if fn_line.ret_ty_info.c_ty.endswith("Array"):
-                    out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " arg = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                    out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 elif not fn_line.ret_ty_info.passed_as_ptr:
                     out_c = out_c + "\treturn (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 else:
index 542487bc463fca2ff6b3e945f5c58fcb6c535a75..2bfd240bd22b8846f6cb5ffe00d74569c0adab6e 100644 (file)
@@ -692,7 +692,7 @@ const decodeString = (stringPointer, free = true) => {
                         out_c = out_c + arg_info.ret_conv[1].replace('\n', '\n\t') + "\n"
 
                 if fn_line.ret_ty_info.c_ty.endswith("Array"):
-                    out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " arg = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
+                    out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = js_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
                 elif fn_line.ret_ty_info.java_ty == "void":
                     out_c = out_c + "\tjs_invoke_function_" + str(len(fn_line.args_ty)) + "(j_calls->" + fn_line.fn_name + "_meth"
                 elif not fn_line.ret_ty_info.passed_as_ptr: