From 50e22ac690a7a745c54e65fab2b8a5f5c0d111d5 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 17 Mar 2025 13:08:50 -0500 Subject: [PATCH] scripts: codemap[d3].py: Added -e/--error-on-recursion Might as well, since we already need to find this to calculate stack info. I've been considering adding -z/--depth to these scripts as well, but that would require quite a bit more work. It's probably not worth the added complexity/headache. Depth termination would need to happen on the javascript side, and we'd still need cycle detection anyways. But an error code is easy to add. --- scripts/codemap.py | 8 ++++++++ scripts/codemapd3.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/scripts/codemap.py b/scripts/codemap.py index f0d997aa..9b85fdf8 100755 --- a/scripts/codemap.py +++ b/scripts/codemap.py @@ -1247,6 +1247,10 @@ def main_(f, paths, *, line = canvas.draw(row) f.writeln(line) + if (args.get('error_on_recursion') + and mt.isinf(totals.get('stack', 0))): + sys.exit(2) + def main(paths, *, height=None, @@ -1496,6 +1500,10 @@ if __name__ == "__main__": '--no-label', action='store_true', help="Don't render any labels.") + parser.add_argument( + '-e', '--error-on-recursion', + action='store_true', + help="Error if any functions are recursive.") parser.add_argument( '--code-path', type=lambda x: x.split(), diff --git a/scripts/codemapd3.py b/scripts/codemapd3.py index 3640f49a..7240d6fb 100755 --- a/scripts/codemapd3.py +++ b/scripts/codemapd3.py @@ -1990,6 +1990,10 @@ def main(paths, output, *, totals.get('stack', 0)), totals.get('ctx', 0))) + if (args.get('error_on_recursion') + and mt.isinf(totals.get('stack', 0))): + sys.exit(2) + if __name__ == "__main__": import argparse @@ -2218,6 +2222,10 @@ if __name__ == "__main__": '--background', help="Background color to use. Note #00000000 can make the " "background transparent.") + parser.add_argument( + '-e', '--error-on-recursion', + action='store_true', + help="Error if any functions are recursive.") parser.add_argument( '--code-path', type=lambda x: x.split(),