https://github.com/miladfarca updated 
https://github.com/llvm/llvm-project/pull/221024

>From bc744f202d21926363f8a97da748dac0f8f56037 Mon Sep 17 00:00:00 2001
From: Milad Fa <[email protected]>
Date: Thu, 3 Sep 2026 19:00:24 +0000
Subject: [PATCH 1/2] [libclang/python] Fix visitor callback return data type

---
 clang/bindings/python/clang/cindex.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index bc00dd770ce3b..4423096085535 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -71,6 +71,7 @@
     byref,
     c_char_p,
     c_int,
+    c_long,
     c_longlong,
     c_uint,
     c_ulong,
@@ -4117,8 +4118,8 @@ def set_property(self, property, value):
 translation_unit_includes_callback = CFUNCTYPE(
     None, c_object_p, POINTER(SourceLocation), c_uint, py_object
 )
-cursor_visit_callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
-fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object)
+cursor_visit_callback = CFUNCTYPE(c_long, Cursor, Cursor, py_object)
+fields_visit_callback = CFUNCTYPE(c_long, Cursor, py_object)
 
 # Functions strictly alphabetical order.
 FUNCTION_LIST: list[LibFunc] = [

>From 21a86bbf64d359bc432ab4490298af1200ebf1c4 Mon Sep 17 00:00:00 2001
From: Milad Fa <[email protected]>
Date: Fri, 4 Sep 2026 13:10:37 +0000
Subject: [PATCH 2/2] Make it s390x specific

---
 clang/bindings/python/clang/cindex.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 4423096085535..5aaddb5e2a619 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -83,6 +83,7 @@
 )
 
 import os
+import platform
 import sys
 from enum import Enum
 import warnings
@@ -4118,8 +4119,16 @@ def set_property(self, property, value):
 translation_unit_includes_callback = CFUNCTYPE(
     None, c_object_p, POINTER(SourceLocation), c_uint, py_object
 )
-cursor_visit_callback = CFUNCTYPE(c_long, Cursor, Cursor, py_object)
-fields_visit_callback = CFUNCTYPE(c_long, Cursor, py_object)
+# On s390x the visitor callbacks must return a full register word (c_long)
+# rather than c_int. ctypes does not sign/zero-extend a narrow closure return
+# to the full 64-bit return register the s390x ELF ABI requires, leaving
+# garbage in the high bytes. libclang reads the full register and faults with
+# a SIGFPE.
+# TODO: Remove once the ctypes fix 
(https://github.com/python/cpython/issues/156933)
+# has propagated.
+_visitor_result = c_long if platform.machine() == "s390x" else c_int
+cursor_visit_callback = CFUNCTYPE(_visitor_result, Cursor, Cursor, py_object)
+fields_visit_callback = CFUNCTYPE(_visitor_result, Cursor, py_object)
 
 # Functions strictly alphabetical order.
 FUNCTION_LIST: list[LibFunc] = [

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to