]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS] Free native -> human arrays after we're done converting
authorMatt Corallo <git@bluematt.me>
Sun, 16 Jan 2022 23:11:35 +0000 (23:11 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 17 Jan 2022 04:34:51 +0000 (04:34 +0000)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index 517deb2f9c0203d36a55b6d360a04535daa2c064..10b2254606b5310065001483e777dddab3697e91 100644 (file)
@@ -196,6 +196,9 @@ class TypeMappingGenerator:
                     to_hu_conv += "\t" + self.consts.var_decl_statement(subty.java_ty, conv_name, self.consts.get_java_arr_elem(subty, arr_name, idxc)) + ";\n"
                     to_hu_conv += "\t" + subty.to_hu_conv.replace("\n", "\n\t") + "\n"
                     to_hu_conv += "\t" + conv_name + "_arr[" + idxc + "] = " + subty.to_hu_conv_name + ";\n}"
+                    cleanup = self.consts.cleanup_converted_native_array(ty_info, arr_name)
+                    if cleanup is not None:
+                        to_hu_conv += "\n" + cleanup
                     to_hu_conv_name = conv_name + "_arr"
                 from_hu_conv = self.consts.primitive_arr_from_hu(ty_info.subty, None, arr_name)
                 if subty.from_hu_conv is not None:
index 8fcc3e5cf13cf6bcf6b59c1671a94f2d5710bee9..2fcf836d23b900bcf87bd3b7e5875c5ee0c52523 100644 (file)
@@ -673,6 +673,8 @@ import javax.annotation.Nullable;
             # Do a bit of a dance to move any excess [] to the end
             conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1]
         return conv
+    def cleanup_converted_native_array(self, ty_info, arr_name):
+        return None
 
     def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
         if fixed_len is not None:
index 7d63af91a69f405765cdfd67c54fb31eea1c07c4..0d9f30b81b2293f09acb7b45f00745330e04f1a1 100644 (file)
@@ -207,6 +207,9 @@ const decodeUint32Array = (arrayPointer: number, free = true) => {
        return actualArray;
 }
 
+
+export function freeWasmMemory(pointer: number) { wasm.TS_free(pointer); }
+
 /* @internal */
 export function getU32ArrayElem(arrayPointer: number, idx: number): number {
        const actualArrayViewer = new Uint32Array(wasm.memory.buffer, arrayPointer + 4, idx + 1);
@@ -635,6 +638,8 @@ import * as bindings from '../bindings.mjs'
             assert False
     def constr_hu_array(self, ty_info, arr_len):
         return "new Array(" + arr_len + ").fill(null)"
+    def cleanup_converted_native_array(self, ty_info, arr_name):
+        return "bindings.freeWasmMemory(" + arr_name + ")"
 
     def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
         inner = arr_name