@@ -1238,18 +1238,28 @@ def map_opaque_struct(self, struct_name, struct_doc_comment):
12381238
12391239 hu_name = struct_name .replace ("LDKC2Tuple" , "TwoTuple" ).replace ("LDKC3Tuple" , "ThreeTuple" ).replace ("LDK" , "" )
12401240 out_opaque_struct_human = f"{ self .hu_struct_file_prefix } "
1241+ constructor_body = "super(ptr, bindings." + struct_name .replace ("LDK" ,"" ) + "_free);"
1242+ extra_docs = ""
1243+ extra_body = ""
12411244 if struct_name .startswith ("LDKLocked" ) or struct_name .startswith ("LDKReadOnly" ):
1242- out_opaque_struct_human += "/** XXX: DO NOT USE THIS - it remains locked until the GC runs (if that ever happens */"
1245+ extra_docs = "\n * This type represents a lock and MUST BE MANUALLY FREE'd!"
1246+ constructor_body = 'super(ptr, () => { throw new Error("Locks must be manually freed with free()"); });'
1247+ extra_body = f"""
1248+ /** Releases this lock */
1249+ public free() {{
1250+ bindings.{ struct_name .replace ("LDK" ,"" )} _free(this.ptr);
1251+ CommonBase.set_null_skip_free(this);
1252+ }}"""
12431253 formatted_doc_comment = struct_doc_comment .replace ("\n " , "\n * " )
12441254 out_opaque_struct_human += f"""
1245- /**
1255+ /**{ extra_docs }
12461256 * { formatted_doc_comment }
12471257 */
12481258export class { hu_name } extends CommonBase { implementations } {{
12491259 /* @internal */
12501260 public constructor(_dummy: object, ptr: number) {{
1251- super(ptr, bindings. { struct_name . replace ( "LDK" , "" ) } _free);
1252- }}
1261+ { constructor_body }
1262+ }}{ extra_body }
12531263
12541264"""
12551265 self .obj_defined ([hu_name ], "structs" )
0 commit comments