X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=1d28d0d1007e0a12acbc9cf9e792a9603ef910dc;hb=886f4905d378c4225cbf13d53f073022fbb5acbc;hp=5452829d70275e4e547bcf47dfc50fc2dba4df44;hpb=5fa9d3629264036cedc44283cf5fd5eb78bb73f2;p=ldk-java diff --git a/java_strings.py b/java_strings.py index 5452829d..1d28d0d1 100644 --- a/java_strings.py +++ b/java_strings.py @@ -115,7 +115,7 @@ import java.util.LinkedList; class CommonBase { long ptr; LinkedList ptrs_to = new LinkedList(); - protected CommonBase(long ptr) { assert ptr > 1024; this.ptr = ptr; } + protected CommonBase(long ptr) { assert ptr < 0 || ptr > 1024; this.ptr = ptr; } } """ @@ -162,6 +162,7 @@ void __attribute__((constructor)) spawn_stderr_redirection() { if not DEBUG or sys.platform == "darwin": self.c_file_pfx = self.c_file_pfx + """#define MALLOC(a, _) malloc(a) #define FREE(p) if ((uint64_t)(p) > 1024) { free(p); } +#define CHECK_ACCESS(p) """ if not DEBUG: self.c_file_pfx += """#define DO_ASSERT(a) (void)(a) @@ -282,7 +283,7 @@ static void alloc_freed(void* ptr) { while (it->ptr != ptr) { p = it; it = it->next; if (it == NULL) { - DEBUG_PRINT("Tried to free unknown pointer %p at:\\n", ptr); + DEBUG_PRINT("ERROR: Tried to free unknown pointer %p at:\\n", ptr); void* bt[BT_MAX]; int bt_len = backtrace(bt, BT_MAX); backtrace_symbols_fd(bt, bt_len, STDERR_FILENO); @@ -318,6 +319,24 @@ void __wrap_free(void* ptr) { __real_free(ptr); } +static void CHECK_ACCESS(void* ptr) { + DO_ASSERT(!pthread_mutex_lock(&allocation_mtx)); + allocation* it = allocation_ll; + while (it->ptr != ptr) { + it = it->next; + if (it == NULL) { + DEBUG_PRINT("ERROR: Tried to access unknown pointer %p at:\\n", ptr); + void* bt[BT_MAX]; + int bt_len = backtrace(bt, BT_MAX); + backtrace_symbols_fd(bt, bt_len, STDERR_FILENO); + DEBUG_PRINT("\\n\\n"); + DO_ASSERT(!pthread_mutex_unlock(&allocation_mtx)); + return; // addrsan should catch and print more info than we have + } + } + DO_ASSERT(!pthread_mutex_unlock(&allocation_mtx)); +} + void* __real_realloc(void* ptr, size_t newlen); void* __wrap_realloc(void* ptr, size_t len) { if (ptr != NULL) alloc_freed(ptr); @@ -1112,11 +1131,12 @@ import javax.annotation.Nullable; out_opaque_struct_human += self.hu_struct_file_prefix out_opaque_struct_human += "\n/**\n * " + struct_doc_comment.replace("\n", "\n * ") + "\n */\n" out_opaque_struct_human += "@SuppressWarnings(\"unchecked\") // We correctly assign various generic arrays\n" - out_opaque_struct_human += ("public class " + struct_name.replace("LDK","") + " extends CommonBase") + hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "") + out_opaque_struct_human += ("public class " + hu_name + " extends CommonBase") if struct_name.startswith("LDKLocked"): out_opaque_struct_human += (" implements AutoCloseable") out_opaque_struct_human += (" {\n") - out_opaque_struct_human += ("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n") + out_opaque_struct_human += ("\t" + hu_name + "(Object _dummy, long ptr) { super(ptr); }\n") if struct_name.startswith("LDKLocked"): out_opaque_struct_human += ("\t@Override public void close() {\n") else: @@ -1127,8 +1147,10 @@ import javax.annotation.Nullable; out_opaque_struct_human += ("\t}\n\n") return out_opaque_struct_human + def map_tuple(self, struct_name): + return self.map_opaque_struct(struct_name, "A Tuple") - def map_function(self, argument_types, c_call_string, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment): + def map_function(self, argument_types, c_call_string, method_name, meth_n, return_type_info, struct_meth, default_constructor_args, takes_self, takes_self_as_ref, args_known, type_mapping_generator, doc_comment): out_java = "" out_c = "" out_java_struct = None @@ -1155,7 +1177,6 @@ import javax.annotation.Nullable; if not args_known: out_java_struct += ("\t// Skipped " + method_name + "\n") else: - meth_n = method_name[len(struct_meth) + 1 if len(struct_meth) != 0 else 0:].strip("_") if doc_comment is not None: out_java_struct += "\t/**\n\t * " + doc_comment.replace("\n", "\n\t * ") + "\n\t */\n" if return_type_info.nullable: @@ -1256,7 +1277,7 @@ import javax.annotation.Nullable; out_java_struct += (info.arg_name) out_java_struct += (");\n") if return_type_info.java_ty == "long" and return_type_info.java_hu_ty != "long": - out_java_struct += "\t\tif (ret < 1024) { return null; }\n" + out_java_struct += "\t\tif (ret >= 0 && ret < 1024) { return null; }\n" if return_type_info.to_hu_conv is not None: if not takes_self: