]> git.bitcoin.ninja Git - ldk-java/commitdiff
Move native string conversion to per-lang files
authorMatt Corallo <git@bluematt.me>
Mon, 25 Jan 2021 22:22:21 +0000 (17:22 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 25 Jan 2021 22:46:08 +0000 (17:46 -0500)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index 07d892bfce5d4d847b26eabb5dc7ccbb4bc5a58c..5ad3d27f64fe99c631a1ca8378820715255e9fa8 100644 (file)
@@ -174,7 +174,7 @@ class TypeMappingGenerator:
             if ty_info.arr_access is None:
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None,
-                    ret_conv = ("jstring " + ty_info.var_name + "_conv = (*env)->NewStringUTF(env, ", ");"), ret_conv_name = ty_info.var_name + "_conv",
+                    ret_conv = ("jstring " + ty_info.var_name + "_conv = " + self.consts.owned_str_to_c_call[0], self.consts.owned_str_to_c_call[1] + ";"), ret_conv_name = ty_info.var_name + "_conv",
                     to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
             else:
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
@@ -183,7 +183,7 @@ class TypeMappingGenerator:
                         ";\nchar* " + ty_info.var_name + "_buf = MALLOC(" + ty_info.var_name + "_str." + ty_info.arr_len + " + 1, \"str conv buf\");\n" +
                         "memcpy(" + ty_info.var_name + "_buf, " + ty_info.var_name + "_str." + ty_info.arr_access + ", " + ty_info.var_name + "_str." + ty_info.arr_len + ");\n" +
                         ty_info.var_name + "_buf[" + ty_info.var_name + "_str." + ty_info.arr_len + "] = 0;\n" +
-                        "jstring " + ty_info.var_name + "_conv = (*env)->NewStringUTF(env, " + ty_info.var_name + "_str." + ty_info.arr_access + ");\n" +
+                        "jstring " + ty_info.var_name + "_conv = " + self.consts.owned_str_to_c_call[0] + ty_info.var_name + "_str." + ty_info.arr_access + self.consts.owned_str_to_c_call[1] + ";\n" +
                         "FREE(" + ty_info.var_name + "_buf);"),
                     ret_conv_name = ty_info.var_name + "_conv", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
         elif ty_info.var_name == "" and not print_void:
index 516c15e282e0c2790b2011380bfa51cfac2ecec5..04855ce9b864e41f5d39f36db2dae5b83e56228b 100644 (file)
@@ -297,6 +297,7 @@ import java.util.Arrays;
         self.ptr_c_ty = "int64_t"
         self.ptr_native_ty = "long"
         self.result_c_ty = "jclass"
+        self.owned_str_to_c_call = ("(*env)->NewStringUTF(env, ", ")")
         self.ptr_arr = "jobjectArray"
         self.get_native_arr_len_call = ("(*env)->GetArrayLength(env, ", ")")
         self.get_native_arr_ptr_call = ("(*env)->GetPrimitiveArrayCritical(env, ", ", NULL)")
index e2201c77fdbe67ad286536bef9f04ef663c1978c..e631237ce5a0d69a04ce9d66fab241af68c88ef9 100644 (file)
@@ -199,6 +199,9 @@ _Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits");
 typedef struct int64_tArray {uint32_t len;int64_t *ptr;} int64_tArray;
 typedef struct uint32_tArray {uint32_t len;int32_t *ptr;} uint32_tArray;
 typedef struct int8_tArray {uint32_t len;int8_t *ptr;} int8_tArray;
+typedef struct jstring {} jstring;
+
+jstring conv_owned_string(const char* _src) { jstring a; return a; }
 
 typedef bool jboolean;
 
@@ -216,6 +219,7 @@ import * as bindings from '../bindings' // TODO: figure out location
         self.ptr_c_ty = "uint32_t"
         self.ptr_native_ty = "number" # "uint32_t"
         self.result_c_ty = "uint32_t"
+        self.owned_str_to_c_call = ("conv_owned_string(", ")")
         self.ptr_arr = "uint32_tArray"
         self.get_native_arr_len_call = ("", ".len")
         self.get_native_arr_ptr_call = ("", ".ptr")