#16 Fix alignment issue on ppc64le
Merged 2 years ago by churchyard. Opened 2 years ago by churchyard.
rpms/ churchyard/python-cffi power  into  rawhide

@@ -0,0 +1,59 @@ 

+ From 4d0cc66daf88f477f3a11262d0e2e093f9397e2c Mon Sep 17 00:00:00 2001

+ From: Armin Rigo <arigo@tunes.org>

+ Date: Tue, 29 Mar 2022 11:48:33 +0200

+ Subject: [PATCH] Issue #531

+ 

+ on ppc64le, libffi requires 16 bytes alignment for at least the return

+ value of functions if that is 'long double'.

+ ---

+  c/_cffi_backend.c | 11 ++++++++---

+  1 file changed, 8 insertions(+), 3 deletions(-)

+ 

+ diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c

+ index ffecbf9a..ce2cacd9 100644

+ --- a/c/_cffi_backend.c

+ +++ b/c/_cffi_backend.c

+ @@ -5665,7 +5665,8 @@ static ffi_type *fb_fill_type(struct funcbuilder_s *fb, CTypeDescrObject *ct,

+      }

+  }

+  

+ -#define ALIGN_ARG(n)  ((n) + 7) & ~7

+ +#define ALIGN_TO(n, a)  ((n) + ((a)-1)) & ~((a)-1)

+ +#define ALIGN_ARG(n)    ALIGN_TO(n, 8)

+  

+  static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,

+                      CTypeDescrObject *fresult)

+ @@ -5690,10 +5691,12 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,

+          /* exchange data size */

+          /* first, enough room for an array of 'nargs' pointers */

+          exchange_offset = nargs * sizeof(void*);

+ +        /* then enough room for the result --- which means at least

+ +           sizeof(ffi_arg), according to the ffi docs, but we also

+ +           align according to the result type, for issue #531 */

+ +        exchange_offset = ALIGN_TO(exchange_offset, fb->rtype->alignment);

+          exchange_offset = ALIGN_ARG(exchange_offset);

+          cif_descr->exchange_offset_arg[0] = exchange_offset;

+ -        /* then enough room for the result --- which means at least

+ -           sizeof(ffi_arg), according to the ffi docs */

+          i = fb->rtype->size;

+          if (i < (Py_ssize_t)sizeof(ffi_arg))

+              i = sizeof(ffi_arg);

+ @@ -5721,6 +5724,7 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,

+          if (fb->atypes != NULL) {

+              fb->atypes[i] = atype;

+              /* exchange data size */

+ +            exchange_offset = ALIGN_TO(exchange_offset, atype->alignment);

+              exchange_offset = ALIGN_ARG(exchange_offset);

+              cif_descr->exchange_offset_arg[1 + i] = exchange_offset;

+              exchange_offset += atype->size;

+ @@ -5737,6 +5741,7 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,

+  }

+  

+  #undef ALIGN_ARG

+ +#undef ALIGN_TO

+  

+  static void fb_cat_name(struct funcbuilder_s *fb, const char *piece,

+                          int piecelen)

+ -- 

+ GitLab

+ 

file modified
+8 -1
@@ -1,12 +1,15 @@ 

  Name:           python-cffi

  %global general_version 1.15.0

  Version:        %{general_version}%{?prerel:~%{prerel}}

- Release:        4%{?dist}

+ Release:        5%{?dist}

  Summary:        Foreign Function Interface for Python to call C code

  License:        MIT

  URL:            https://cffi.readthedocs.org/

  Source0:        %{pypi_source cffi}

  Patch1:         https://foss.heptapod.net/pypy/cffi/-/commit/871bae572cafc3afb81eb13705945f0a6f708d54.patch

+ # on ppc64le, libffi requires 16 bytes alignment for at least the return

+ # value of functions if that is 'long double':

+ Patch2:         https://foss.heptapod.net/pypy/cffi/-/commit/4d0cc66daf88f477f3a11262d0e2e093f9397e2c.patch

  

  BuildRequires: make

  BuildRequires:  libffi-devel
@@ -70,6 +73,10 @@ 

  %doc doc/build/html

  

  %changelog

+ * Wed Mar 30 2022 Miro Hrončok <mhroncok@redhat.com> - 1.15.0-5

+ - Fix alignment issue on ppc64le

+ - Fixes: rhbz#2046865

+ 

  * Wed Feb 02 2022 Tomáš Hrnčiar <thrnciar@redhat.com> - 1.15.0-4

  - Backport patch to fix compatibility with Python 3.11

  - Fixes: rhbz#2040165

no initial comment

Pull-Request has been merged by churchyard

2 years ago