From c9798d007cd66047f4fb03647658153efb88fda8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 28 Aug 2020 23:50:14 -0400 Subject: [PATCH] Convert String (tested from Java!) --- genbindings.py | 10 +++++++--- src/main/jni/bindings.c | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/genbindings.py b/genbindings.py index 66bc6253..65869c7b 100755 --- a/genbindings.py +++ b/genbindings.py @@ -112,12 +112,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg var_is_arr = var_is_arr_regex.match(fn_arg) if var_is_arr is not None or ret_arr_len is not None: assert(not take_by_ptr) - #assert(not passed_as_ptr) + assert(not is_ptr) java_ty = java_ty + "[]" c_ty = c_ty + "Array" if var_is_arr is not None: - return TypeInfo(rust_obj=None, java_ty=java_ty, java_fn_ty_arg="[" + fn_ty_arg, c_ty=c_ty, passed_as_ptr=is_ptr, - is_ptr=False, var_name=var_is_arr.group(1), arr_len=var_is_arr.group(2)) + return TypeInfo(rust_obj=None, java_ty=java_ty, java_fn_ty_arg="[" + fn_ty_arg, c_ty=c_ty, + passed_as_ptr=False, is_ptr=False, var_name=var_is_arr.group(1), arr_len=var_is_arr.group(2)) return TypeInfo(rust_obj=rust_obj, java_ty=java_ty, java_fn_ty_arg=fn_ty_arg, c_ty=c_ty, passed_as_ptr=is_ptr or take_by_ptr, is_ptr=is_ptr, var_name=fn_arg, arr_len=None) @@ -169,6 +169,10 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg elif ty_info.is_ptr: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = None, arg_conv_name = ty_info.var_name, ret_conv = None, ret_conv_name = None) + elif ty_info.java_ty == "String": + return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, + arg_conv = None, arg_conv_name = None, + ret_conv = ("jstring " + ty_info.var_name + "_conv = (*_env)->NewStringUTF(_env, ", ");"), ret_conv_name = ty_info.var_name + "_conv") else: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = None, arg_conv_name = ty_info.var_name, ret_conv = None, ret_conv_name = None) diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 0b021c3c..2bf779f4 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -78,7 +78,8 @@ typedef struct LDKLogger_JCalls { } LDKLogger_JCalls; void log_jcall(const void* this_arg, const char *record) { LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg; - return (*j_calls->env)->CallVoidMethod(j_calls->env, j_calls->o, j_calls->log_meth, record); + jstring record_conv = (*j_calls->env)->NewStringUTF(j_calls->env, record); + return (*j_calls->env)->CallVoidMethod(j_calls->env, j_calls->o, j_calls->log_meth, record_conv); } void LDKLogger_JCalls_free(void* this_arg) { LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg; -- 2.39.5