From 3c80c9d8174c6a4355b2fc0790288ea46e4631e4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 12 Jan 2021 23:48:24 -0500 Subject: [PATCH] Fix short, push trait struct refcnt increment down to lang --- gen_type_mapping.py | 4 +--- genbindings.py | 2 +- java_strings.py | 6 ++++++ typescript_strings.py | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 7eda9b7c..fe2aed21 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -275,9 +275,7 @@ class TypeMappingGenerator: if needs_full_clone and (ty_info.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns: base_conv = base_conv + "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(" + ty_info.var_name + ");" else: - base_conv = base_conv + "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n" - base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n" - base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_clone(" + ty_info.var_name + "_conv.this_arg);\n}" + base_conv = base_conv + self.consts.trait_struct_inc_refcnt(ty_info) if needs_full_clone: base_conv = base_conv + "// Warning: we may need a move here but can't do a full clone!\n" diff --git a/genbindings.py b/genbindings.py index fa75b0fb..221b1bd8 100755 --- a/genbindings.py +++ b/genbindings.py @@ -201,7 +201,7 @@ def java_c_types(fn_arg, ret_arr_len): elif fn_arg.startswith("uint16_t"): mapped_type = consts.c_type_map['uint16_t'] java_ty = mapped_type[0] - c_ty = "jshort" + c_ty = "int16_t" fn_ty_arg = "S" fn_arg = fn_arg[8:].strip() is_primitive = True diff --git a/java_strings.py b/java_strings.py index 2e9ae670..d73a15de 100644 --- a/java_strings.py +++ b/java_strings.py @@ -702,6 +702,12 @@ import java.util.Arrays; return (out_java, out_java_trait, out_c) + def trait_struct_inc_refcnt(self, ty_info): + base_conv = "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n" + base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n" + base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_clone(" + ty_info.var_name + "_conv.this_arg);\n}" + return base_conv + def map_complex_enum(self, struct_name, variant_list, camel_to_snake): java_hu_type = struct_name.replace("LDK", "") out_java_enum = "" diff --git a/typescript_strings.py b/typescript_strings.py index 6e2ce6fa..7c6e6ab5 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -650,6 +650,9 @@ const wasm = wasmInstance.exports; return (out_typescript_bindings, out_typescript_human, out_c) + def trait_struct_inc_refcnt(self, ty_info): + return "" + def map_complex_enum(self, struct_name, variant_list, camel_to_snake): java_hu_type = struct_name.replace("LDK", "") -- 2.30.2