mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scripts: checkstack: Convert to Python
@ 2026-10-19 13:45 Breno Rodrigues Alves
  0 siblings, 0 replies; only message in thread
From: Breno Rodrigues Alves @ 2026-10-19 13:45 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: linux-kernel, Jonathan Corbet, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn, Breno Rodrigues Alves

Convert checkstack.pl to Python to unify kernel tooling in a single
language. This reduces the maintenance burden of dealing with two
different sets of idioms for the same class of scripts.

The conversion introduces a robust parse_size helper to handle dynamic
stack adjustments (e.g., sub %eax, %esp). In Perl, hex() silently
evaluates non-numeric strings to 0; Python's int() raises a ValueError.
The new helper ensures 1:1 behavioral parity without crashing on valid
objdump output.

Tested by comparing the output of checkstack.pl and checkstack.py
against a full objdump of /bin/bash on x86_64; the outputs were identical.

Assisted-by: DeepSeek
Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
---
 scripts/checkstack.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/scripts/checkstack.py b/scripts/checkstack.py
index 8be3861b3..c3821c860 100755
--- a/scripts/checkstack.py
+++ b/scripts/checkstack.py
@@ -65,7 +65,18 @@ def config_for(arch):
 
 
 def parse_size(s):
-    return int(s, 16) if s.startswith('0x') else int(s)
+    """
+    Mimics Perl's implicit numeric conversion.
+    In Perl, hex("%eax") silently evaluates to 0.
+    In Python, int("%eax") raises ValueError, so we catch it
+    to maintain 1:1 parity and prevent script crashes.
+    """
+    if not s:
+        return 0
+    try:
+        return int(s, 16) if s.startswith('0x') else int(s)
+    except ValueError:
+        return 0
 
 
 def main(argv):
@@ -81,7 +92,8 @@ def main(argv):
     total = 0
 
     for raw in sys.stdin:
-        line = raw.rstrip('\n')
+        # Fix: Use rstrip('\r\n') to handle Windows-formatted objdump files safely
+        line = raw.rstrip('\r\n')
 
         m = RE_FUNC.match(line)
         if m:
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-19 13:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19 13:45 [PATCH] scripts: checkstack: Convert to Python Breno Rodrigues Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®