From 52688fea7c8a7f2af2baef9abebe66feb040e726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20K=C3=B6pcke?= Date: Wed, 26 Jun 2024 10:20:04 +0200 Subject: [PATCH] pythonPackages.cffi: include patch to fix clang error Fixes null-pointer-subtraction --- .../avoid-null-pointer-subtraction-error.diff | 14 +++++++ .../clang-pointer-substraction-warning.diff | 11 ------ .../python-modules/cffi/default.nix | 38 ++++++++----------- 3 files changed, 30 insertions(+), 33 deletions(-) create mode 100644 pkgs/development/python-modules/cffi/avoid-null-pointer-subtraction-error.diff delete mode 100644 pkgs/development/python-modules/cffi/clang-pointer-substraction-warning.diff diff --git a/pkgs/development/python-modules/cffi/avoid-null-pointer-subtraction-error.diff b/pkgs/development/python-modules/cffi/avoid-null-pointer-subtraction-error.diff new file mode 100644 index 0000000000000..e4bddc407f6ec --- /dev/null +++ b/pkgs/development/python-modules/cffi/avoid-null-pointer-subtraction-error.diff @@ -0,0 +1,14 @@ +diff --git a/src/cffi/recompiler.py b/src/cffi/recompiler.py +index 4167bc05..ac6c163e 100644 +--- a/src/cffi/recompiler.py ++++ b/src/cffi/recompiler.py +@@ -953,7 +953,7 @@ def _struct_ctx(self, tp, cname, approxname, named_ptr=None): + if cname is None or fbitsize >= 0: + offset = '(size_t)-1' + elif named_ptr is not None: +- offset = '((char *)&((%s)0)->%s) - (char *)0' % ( ++ offset = '((char *)&((%s)4096)->%s) - (char *)4096' % ( + named_ptr.name, fldname) + else: + offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname) + Login with GitHub diff --git a/pkgs/development/python-modules/cffi/clang-pointer-substraction-warning.diff b/pkgs/development/python-modules/cffi/clang-pointer-substraction-warning.diff deleted file mode 100644 index 75b2677e380e7..0000000000000 --- a/pkgs/development/python-modules/cffi/clang-pointer-substraction-warning.diff +++ /dev/null @@ -1,11 +0,0 @@ -diff -r c649a735cf82 testing/support.py ---- a/testing/support.py Thu Feb 23 05:42:01 2023 +0100 -+++ b/testing/support.py Sat May 20 21:46:56 2023 -0400 -@@ -112,6 +112,7 @@ - '-Wno-unreachable-code'] - # special things for clang - extra_compile_args.append('-Qunused-arguments') -+ extra_compile_args.append('-Wno-null-pointer-subtraction') - else: - # assume a standard gcc - extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion', diff --git a/pkgs/development/python-modules/cffi/default.nix b/pkgs/development/python-modules/cffi/default.nix index 7d03ab82c7bca..c87adddd437ce 100644 --- a/pkgs/development/python-modules/cffi/default.nix +++ b/pkgs/development/python-modules/cffi/default.nix @@ -11,7 +11,6 @@ pycparser, pythonAtLeast, }: - if isPyPy then null else @@ -25,27 +24,22 @@ else hash = "sha256-vLPvQ+WGZbvaL7GYaY/K5ndkg+DEpjGqVkeAbCXgLMA="; }; - patches = - [ - # - # Trusts the libffi library inside of nixpkgs on Apple devices. - # - # Based on some analysis I did: - # - # https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk - # - # I believe that libffi already contains the code from Apple's fork that is - # deemed safe to trust in cffi. - # - ./darwin-use-libffi-closures.diff - ] - ++ lib.optionals (stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion stdenv.cc) "13") [ - # -Wnull-pointer-subtraction is enabled with -Wextra. Suppress it to allow the following tests - # to run and pass when cffi is built with newer versions of clang: - # - testing/cffi1/test_verify1.py::test_enum_usage - # - testing/cffi1/test_verify1.py::test_named_pointer_as_argument - ./clang-pointer-substraction-warning.diff - ]; + patches = [ + # + # Trusts the libffi library inside of nixpkgs on Apple devices. + # + # Based on some analysis I did: + # + # https://groups.google.com/g/python-cffi/c/xU0Usa8dvhk + # + # I believe that libffi already contains the code from Apple's fork that is + # deemed safe to trust in cffi. + # + ./darwin-use-libffi-closures.diff + # https://github.com/python-cffi/cffi/commit/39bdab23615a83c1001ed822f974ae52020201ba + # Needed on newer Clang versions. + ./avoid-null-pointer-subtraction-error.diff + ]; postPatch = lib.optionalString stdenv.isDarwin '' # Remove setup.py impurities