diff --git a/nala/dist/nala.c b/nala/dist/nala.c index f24c78d..ff7908d 100644 --- a/nala/dist/nala.c +++ b/nala/dist/nala.c @@ -3360,7 +3360,7 @@ void nala_subprocess_result_free(struct nala_subprocess_result_t *self_p) // #include "subprocess.h" -#define DEPTH_MAX 100 +#define NALA_DEPTH_MAX 100 #define ANSI_COLOR_GREEN "\x1b[32m" #define ANSI_COLOR_CYAN "\x1b[36m" @@ -3603,9 +3603,9 @@ char *nala_traceback_string(const char *prefix_p, void *arg_p) { int depth; - void *addresses[DEPTH_MAX]; + void *addresses[NALA_DEPTH_MAX]; - depth = backtrace(&addresses[0], DEPTH_MAX); + depth = backtrace(&addresses[0], NALA_DEPTH_MAX); return (nala_traceback_format(addresses, depth, diff --git a/nala/inspect.py b/nala/inspect.py index b26ecc0..449fcf9 100644 --- a/nala/inspect.py +++ b/nala/inspect.py @@ -390,6 +390,20 @@ def parse(self): self.typedefs_code + self.structs_code + self.func_signatures) self.file_ast = self.cparser.parse(code) func_offset = len(self.typedefs_code + self.structs_code) + # PATCH BEGIN + # The above offset calculation sometimes ends up giving a wrong start index. + # As a result the first function_declaration handed over to `rename_parameters` + # is of type 'Struct' which has no argument 'args'! + # Now we test if the element at index `func_offset` has the correct type, and if + # not the AST list is searched for the first 'c_ast.FuncDecl' starting from the + # calculated `func_offset`. The index of the first detected 'c_ast.FuncDecl' is + # then used as new `func_offset`! + if not isinstance(self.file_ast.ext[func_offset].type, c_ast.FuncDecl): + for i in range(func_offset, len(self.file_ast.ext)): + if isinstance(self.file_ast.ext[i].type, c_ast.FuncDecl): + func_offset = i + break + # PATCH END for i, func_name in enumerate(self.func_names, func_offset): if self.param_names is None: