From fd59673b53bd5e74459132e685a10258b3c1d5a6 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 1 Mar 2021 12:24:11 -0500 Subject: [PATCH] Work around our stupid hack with a stupid hack (see XXX in genbindings.py) --- gen_type_mapping.py | 10 +++++----- java_strings.py | 4 ++-- typescript_strings.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gen_type_mapping.py b/gen_type_mapping.py index dfb2b57e..afd19979 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -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") diff --git a/java_strings.py b/java_strings.py index e6a17ebd..4b2ae77f 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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: diff --git a/typescript_strings.py b/typescript_strings.py index 542487bc..2bfd240b 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -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: -- 2.39.5