From 48812b35db8e4c14e9dc40fd1aff3f0b9ce423dd Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 5 Apr 2022 18:07:12 +0000 Subject: [PATCH] Add a new manual type - UnqualifiedError/LDKError --- gen_type_mapping.py | 10 +++++++++- genbindings.py | 8 ++++++++ src/main/java/org/ldk/util/UnqualifiedError.java | 9 +++++++++ typescript_strings.py | 6 +++++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/ldk/util/UnqualifiedError.java diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 9cee9ab4..ad7d46fc 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -486,7 +486,15 @@ class TypeMappingGenerator: to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";" + to_hu_conv_sfx, to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv) - # The manually-defined types - TxOut and u5 + # The manually-defined types - TxOut, u5, and Error + if ty_info.rust_obj == "LDKError": + assert from_hu_conv is None + return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, + arg_conv = "", arg_conv_name = "(LDKError){ ._dummy = 0 }", arg_conv_cleanup = None, + ret_conv = ("/*", "*/"), ret_conv_name = "0", + to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ")") + ";", + to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("0", "")) + if ty_info.rust_obj == "LDKu5": assert from_hu_conv is None return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, diff --git a/genbindings.py b/genbindings.py index a3ea7d40..2d69168e 100755 --- a/genbindings.py +++ b/genbindings.py @@ -320,6 +320,14 @@ def java_c_types(fn_arg, ret_arr_len): fn_arg = fn_arg[6:].strip() arr_access = "chars" arr_len = "len" + elif fn_arg.startswith("LDKError ") or fn_arg == "LDKError": + java_ty = consts.c_type_map['uint32_t'][0] + java_hu_ty = "UnqualifiedError" + rust_obj = "LDKError" + c_ty = "int32_t" + arr_ty = "uint32_t" + fn_ty_arg = "I" + fn_arg = fn_arg[8:].strip() else: ma = var_ty_regex.match(fn_arg) arr_ty = ma.group(1).strip() diff --git a/src/main/java/org/ldk/util/UnqualifiedError.java b/src/main/java/org/ldk/util/UnqualifiedError.java new file mode 100644 index 00000000..9f6cc1f2 --- /dev/null +++ b/src/main/java/org/ldk/util/UnqualifiedError.java @@ -0,0 +1,9 @@ +package org.ldk.util; + +/** + * An type for cases where no additional information is available. + * In general, if you've gotten this far the cause of the error should already be clear. + */ +public class UnqualifiedError { + public UnqualifiedError(int _dummy) {} +} diff --git a/typescript_strings.py b/typescript_strings.py index 76e43828..670eb2ae 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -326,6 +326,10 @@ export class UInt5 { return this.val; } } + +export class UnqualifiedError { + public constructor(val: number) {} +} """ self.txout_defn = """export class TxOut extends CommonBase { @@ -592,7 +596,7 @@ jstring __attribute__((export_name("TS_get_ldk_version"))) get_ldk_version() { }""" self.hu_struct_file_prefix = """ -import { CommonBase, UInt5 } from './CommonBase.mjs'; +import { CommonBase, UInt5, UnqualifiedError } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' """ -- 2.30.2