From 6108d1a32ba0b434521d3f0d9e4176c4d12de25b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 16 Jan 2022 23:11:35 +0000 Subject: [PATCH] [TS] Free native -> human arrays after we're done converting --- gen_type_mapping.py | 3 +++ java_strings.py | 2 ++ typescript_strings.py | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 517deb2f..10b22546 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -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: diff --git a/java_strings.py b/java_strings.py index 8fcc3e5c..2fcf836d 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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: diff --git a/typescript_strings.py b/typescript_strings.py index 7d63af91..0d9f30b8 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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 -- 2.30.2