Merge pull request #71 from TheBlueMatt/main
[ldk-java] / typescript_strings.py
index 54159d8d85099d3c0db71e0710dd7194d5618c2f..8a83ae4a44ff339f9821c1866d5d2545817ca532 100644 (file)
@@ -124,6 +124,7 @@ void free(void *ptr);
 #define DO_ASSERT(a) (void)(a)
 #define CHECK(a)
 #define CHECK_ACCESS(p)
+#define CHECK_INNER_FIELD_ACCESS_OR_NULL(v)
 """
         else:
             self.c_file_pfx = self.c_file_pfx + """
@@ -189,6 +190,13 @@ static void CHECK_ACCESS(void* ptr) {
                }
        }
 }
+#define CHECK_INNER_FIELD_ACCESS_OR_NULL(v) \\
+       if (v.is_owned && v.inner != NULL) { \\
+               const void *p = __unmangle_inner_ptr(v.inner); \\
+               if (p != NULL) { \\
+                       CHECK_ACCESS(p); \\
+               } \\
+       }
 
 void* __wrap_malloc(size_t len) {
        void* res = __real_malloc(len);
@@ -472,9 +480,11 @@ const decodeString = (stringPointer, free = true) => {
 
         out_typescript_enum_fields = ""
 
-        for var in variants:
+        for var, var_docs in variants:
             out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var)
             ord_v = ord_v + 1
+            if var_docs is not None:
+                out_typescript_enum_fields += f"/**\n * {var_docs}\n */\n"
             out_typescript_enum_fields += f"{var},\n\t\t\t\t"
         out_c = out_c + "\t}\n"
         out_c = out_c + "\tabort();\n"
@@ -483,7 +493,7 @@ const decodeString = (stringPointer, free = true) => {
         out_c = out_c + "static inline int32_t LDK" + struct_name + "_to_js(LDK" + struct_name + " val) {\n"
         out_c = out_c + "\tswitch (val) {\n"
         ord_v = 0
-        for var in variants:
+        for var, _ in variants:
             out_c = out_c + "\t\tcase " + var + ": return %d;\n" % ord_v
             ord_v = ord_v + 1
         out_c = out_c + "\t\tdefault: abort();\n"