]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
python3-cffi: Fix failing ptests with clang
authorKhem Raj <raj.khem@gmail.com>
Tue, 4 Feb 2025 22:09:30 +0000 (14:09 -0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 11 Feb 2025 11:42:23 +0000 (11:42 +0000)
Clang finds additional warnings with cffi generated code

_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:587:10: error: non-constant-expression cannot be narrowed from type 'long' to 'size_t' (ak│a 'unsigned long') in initializer list [-Wc++11-narrowing]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-devtools/python/python3-cffi/0001-Cast-offset-to-size_t-to-avoid-c-11-narrowing-warnin.patch [new file with mode: 0644]
meta/recipes-devtools/python/python3-cffi_1.17.1.bb

diff --git a/meta/recipes-devtools/python/python3-cffi/0001-Cast-offset-to-size_t-to-avoid-c-11-narrowing-warnin.patch b/meta/recipes-devtools/python/python3-cffi/0001-Cast-offset-to-size_t-to-avoid-c-11-narrowing-warnin.patch
new file mode 100644 (file)
index 0000000..a919f4f
--- /dev/null
@@ -0,0 +1,34 @@
+From 2ac63f8765e62f1492ef3ee06791636700bc6cfb Mon Sep 17 00:00:00 2001
+From: triallax <triallax@tutanota.com>
+Date: Sat, 29 Jun 2024 15:25:24 +0100
+Subject: [PATCH] Cast offset to size_t to avoid c++11-narrowing warning (#92)
+
+e.g. with clang 18 on chimera linux:
+
+_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: error: non-constant-expression cannot be narrowed from type 'long' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
+  583 |   { "a", ((char *)&((foo_t)4096)->a) - (char *)4096,
+      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: note: insert an explicit cast to silence this issue
+  583 |   { "a", ((char *)&((foo_t)4096)->a) - (char *)4096,
+      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+      |          static_cast<size_t>(                      )
+
+Upstream-Status: Backport [https://github.com/python-cffi/cffi/pull/92]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ src/cffi/recompiler.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py
+index ac6c163e..14d578ee 100644
+--- a/src/cffi/recompiler.py
++++ b/src/cffi/recompiler.py
+@@ -953,7 +953,7 @@ class Recompiler:
+                 if cname is None or fbitsize >= 0:
+                     offset = '(size_t)-1'
+                 elif named_ptr is not None:
+-                    offset = '((char *)&((%s)4096)->%s) - (char *)4096' % (
++                    offset = '(size_t)(((char *)&((%s)4096)->%s) - (char *)4096)' % (
+                         named_ptr.name, fldname)
+                 else:
+                     offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname)
index fbe9051a90b60585d0197b176afb3a33a9db6e55..5a3af03d9f6b036712d6ee7a78992c15f5d43157 100644 (file)
@@ -6,7 +6,8 @@ DEPENDS += "libffi python3-pycparser"
 
 SRC_URI[sha256sum] = "1c39c6016c32bc48dd54561950ebd6836e1670f2ae46128f67cf49e789c52824"
 
-SRC_URI += "file://run-ptest"
+SRC_URI += "file://run-ptest \
+            file://0001-Cast-offset-to-size_t-to-avoid-c-11-narrowing-warnin.patch"
 
 inherit pypi python_setuptools_build_meta ptest pkgconfig