From 658f43fc13642257060fceb6c42d4a58a35e54af Mon Sep 17 00:00:00 2001 From: Eero Vaher Date: Wed, 19 Aug 2026 21:48:55 +0300 Subject: [PATCH] Improve handling LDBODY array sizes in tests The sizes of LDBODY arrays are not known at compile-time, so ERFA C functions require the size to be passed as a separate argument. The ufunc wrappers can look up array sizes at runtime, so they do not have that argument. Therefore, when `erfa_generator` translates ERFA C tests to Python the array size arguments must be removed. So far that has been done by replacing sub-strings in the C source code, but that required making assumptions about variable names and literal values. Now the removal is performed without those assumptions. --- erfa_generator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erfa_generator.py b/erfa_generator.py index e9a8f15..955916b 100644 --- a/erfa_generator.py +++ b/erfa_generator.py @@ -712,8 +712,6 @@ def to_python(self) -> list[str]: # Call of function that is being tested. elif self.func.name in line: - # correct for LDBODY (complete hack!) - line = line.replace('3, b', 'b').replace('n, b', 'b') in_args, out_args = _args_from_func_call(line, self.func) if self.func.c_retval: out_args.append(line.split(" =", 1)[0]) @@ -743,6 +741,9 @@ def _args_from_func_call(line: str, func: Function) -> tuple[list[str], list[str arg.strip().removeprefix("&") for arg in line.split("(", 1)[1].removesuffix(")").split(",") ] + for i, elem in enumerate(func.c_args): + if elem.ctype == "eraLDBODY": + args.pop(i) # pyerfa does not require array sizes as separate arguments. in_args = [ # convert any C octal integer literals [ str(int(arg, 8)) if arg.startswith("0") and arg.isdigit() else arg