From unknown Sat Aug 16 16:21:21 2025 X-Loop: help-debbugs@gnu.org Subject: bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call Resent-From: Andreas Schwab Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 03 Dec 2011 11:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 10203 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: 10203@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.132291109520726 (code B ref -1); Sat, 03 Dec 2011 11:19:01 +0000 Received: (at submit) by debbugs.gnu.org; 3 Dec 2011 11:18:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWnbi-0005OF-Pt for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:18:14 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWnbg-0005O8-KL for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:18:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWnbL-0002dU-Bp for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:17:52 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:42048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbL-0002dN-AM for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:17:51 -0500 Received: from eggs.gnu.org ([140.186.70.92]:56059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbK-00026R-H8 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWnbI-0002cn-K0 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:50 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:54019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbI-0002cV-A3 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:48 -0500 Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id D55BF1C0C17E for ; Sat, 3 Dec 2011 12:17:46 +0100 (CET) X-Auth-Info: Zvb7ruJpj726w+ueGxibOV+UOGlx+zEt07A/1fnXmlQ= Received: from igel.home (ppp-93-104-149-66.dynamic.mnet-online.de [93.104.149.66]) by mail.mnet-online.de (Postfix) with ESMTPA id 8F6DD1C000BA for ; Sat, 3 Dec 2011 12:17:46 +0100 (CET) Received: by igel.home (Postfix, from userid 501) id 30658CA29C; Sat, 3 Dec 2011 12:17:46 +0100 (CET) From: Andreas Schwab X-Yow: LOU GRANT froze my ASSETS!! Date: Sat, 03 Dec 2011 12:17:46 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -4.6 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) * libguile/foreign.c (unpack): Add parameter return_value_p. Properly store integer return values smaller than int. (scm_i_foreign_call): Update call to unpack. (invoke_closure): Likewise. --- libguile/foreign.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libguile/foreign.c b/libguile/foreign.c index bb88cf5..8351ae1 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -910,7 +910,7 @@ cif_to_procedure (SCM cif, SCM func_ptr) /* Set *LOC to the foreign representation of X with TYPE. */ static void -unpack (const ffi_type *type, void *loc, SCM x) +unpack (const ffi_type *type, void *loc, SCM x, int return_value_p) #define FUNC_NAME "scm_i_foreign_call" { switch (type->type) @@ -921,23 +921,45 @@ unpack (const ffi_type *type, void *loc, SCM x) case FFI_TYPE_DOUBLE: *(double *) loc = scm_to_double (x); break; + + /* For integer return values smaller than `int', libffi expects the + result in an `ffi_arg'-long buffer. */ + case FFI_TYPE_UINT8: - *(scm_t_uint8 *) loc = scm_to_uint8 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint8 (x); + else + *(scm_t_uint8 *) loc = scm_to_uint8 (x); break; case FFI_TYPE_SINT8: - *(scm_t_int8 *) loc = scm_to_int8 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int8 (x); + else + *(scm_t_int8 *) loc = scm_to_int8 (x); break; case FFI_TYPE_UINT16: - *(scm_t_uint16 *) loc = scm_to_uint16 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint16 (x); + else + *(scm_t_uint16 *) loc = scm_to_uint16 (x); break; case FFI_TYPE_SINT16: - *(scm_t_int16 *) loc = scm_to_int16 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int16 (x); + else + *(scm_t_int16 *) loc = scm_to_int16 (x); break; case FFI_TYPE_UINT32: - *(scm_t_uint32 *) loc = scm_to_uint32 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint32 (x); + else + *(scm_t_uint32 *) loc = scm_to_uint32 (x); break; case FFI_TYPE_SINT32: - *(scm_t_int32 *) loc = scm_to_int32 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int32 (x); + else + *(scm_t_int32 *) loc = scm_to_int32 (x); break; case FFI_TYPE_UINT64: *(scm_t_uint64 *) loc = scm_to_uint64 (x); @@ -1073,7 +1095,7 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) args[i] = (void *) ROUND_UP ((scm_t_uintptr) data + off, cif->arg_types[i]->alignment); assert ((scm_t_uintptr) args[i] % cif->arg_types[i]->alignment == 0); - unpack (cif->arg_types[i], args[i], argv[i]); + unpack (cif->arg_types[i], args[i], argv[i], 0); } /* Prepare space for the return value. On some platforms, such as @@ -1112,7 +1134,7 @@ invoke_closure (ffi_cif *cif, void *ret, void **args, void *data) result = scm_call_n (proc, argv, cif->nargs); - unpack (cif->rtype, ret, result); + unpack (cif->rtype, ret, result, 1); } SCM_DEFINE (scm_procedure_to_pointer, "procedure->pointer", 3, 0, 0, -- 1.7.7.4 -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." From unknown Sat Aug 16 16:21:21 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Andreas Schwab Subject: bug#10203: closed (Re: bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call) Message-ID: References: <87zkepfmfo.fsf@gnu.org> X-Gnu-PR-Message: they-closed 10203 X-Gnu-PR-Package: guile X-Gnu-PR-Keywords: patch Reply-To: 10203@debbugs.gnu.org Date: Mon, 19 Dec 2011 00:16:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1324253762-8832-1" This is a multi-part message in MIME format... ------------=_1324253762-8832-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #10203: [PATCH] FFI: Properly unpack small integer return values in closure= call which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 10203@debbugs.gnu.org. --=20 10203: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D10203 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1324253762-8832-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 10203-done) by debbugs.gnu.org; 19 Dec 2011 00:15:27 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RcQt5-0002Hi-B5 for submit@debbugs.gnu.org; Sun, 18 Dec 2011 19:15:27 -0500 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RcQt1-0002HY-Vb for 10203-done@debbugs.gnu.org; Sun, 18 Dec 2011 19:15:25 -0500 X-IronPort-AV: E=Sophos;i="4.71,373,1320620400"; d="scan'208";a="123841483" Received: from reverse-83.fdn.fr (HELO pluto) ([80.67.176.83]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 19 Dec 2011 01:13:32 +0100 From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) To: Andreas Schwab Subject: Re: bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 29 Frimaire an 220 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu Date: Mon, 19 Dec 2011 01:13:31 +0100 In-Reply-To: (Andreas Schwab's message of "Sat, 03 Dec 2011 12:17:46 +0100") Message-ID: <87zkepfmfo.fsf@gnu.org> User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -9.2 (---------) X-Debbugs-Envelope-To: 10203-done Cc: 10203-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -9.2 (---------) Hi Andreas, Andreas Schwab skribis: > * libguile/foreign.c (unpack): Add parameter return_value_p. > Properly store integer return values smaller than int. > (scm_i_foreign_call): Update call to unpack. > (invoke_closure): Likewise. Applied, thank you! Did you actually observe a problem on m68k or something? Ludo=E2=80=99. ------------=_1324253762-8832-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 3 Dec 2011 11:18:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWnbi-0005OF-Pt for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:18:14 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RWnbg-0005O8-KL for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:18:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWnbL-0002dU-Bp for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:17:52 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:42048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbL-0002dN-AM for submit@debbugs.gnu.org; Sat, 03 Dec 2011 06:17:51 -0500 Received: from eggs.gnu.org ([140.186.70.92]:56059) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbK-00026R-H8 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWnbI-0002cn-K0 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:50 -0500 Received: from mail-out.m-online.net ([212.18.0.9]:54019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWnbI-0002cV-A3 for bug-guile@gnu.org; Sat, 03 Dec 2011 06:17:48 -0500 Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id D55BF1C0C17E for ; Sat, 3 Dec 2011 12:17:46 +0100 (CET) X-Auth-Info: Zvb7ruJpj726w+ueGxibOV+UOGlx+zEt07A/1fnXmlQ= Received: from igel.home (ppp-93-104-149-66.dynamic.mnet-online.de [93.104.149.66]) by mail.mnet-online.de (Postfix) with ESMTPA id 8F6DD1C000BA for ; Sat, 3 Dec 2011 12:17:46 +0100 (CET) Received: by igel.home (Postfix, from userid 501) id 30658CA29C; Sat, 3 Dec 2011 12:17:46 +0100 (CET) From: Andreas Schwab To: bug-guile@gnu.org Subject: [PATCH] FFI: Properly unpack small integer return values in closure call X-Yow: LOU GRANT froze my ASSETS!! Date: Sat, 03 Dec 2011 12:17:46 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) * libguile/foreign.c (unpack): Add parameter return_value_p. Properly store integer return values smaller than int. (scm_i_foreign_call): Update call to unpack. (invoke_closure): Likewise. --- libguile/foreign.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-) diff --git a/libguile/foreign.c b/libguile/foreign.c index bb88cf5..8351ae1 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -910,7 +910,7 @@ cif_to_procedure (SCM cif, SCM func_ptr) /* Set *LOC to the foreign representation of X with TYPE. */ static void -unpack (const ffi_type *type, void *loc, SCM x) +unpack (const ffi_type *type, void *loc, SCM x, int return_value_p) #define FUNC_NAME "scm_i_foreign_call" { switch (type->type) @@ -921,23 +921,45 @@ unpack (const ffi_type *type, void *loc, SCM x) case FFI_TYPE_DOUBLE: *(double *) loc = scm_to_double (x); break; + + /* For integer return values smaller than `int', libffi expects the + result in an `ffi_arg'-long buffer. */ + case FFI_TYPE_UINT8: - *(scm_t_uint8 *) loc = scm_to_uint8 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint8 (x); + else + *(scm_t_uint8 *) loc = scm_to_uint8 (x); break; case FFI_TYPE_SINT8: - *(scm_t_int8 *) loc = scm_to_int8 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int8 (x); + else + *(scm_t_int8 *) loc = scm_to_int8 (x); break; case FFI_TYPE_UINT16: - *(scm_t_uint16 *) loc = scm_to_uint16 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint16 (x); + else + *(scm_t_uint16 *) loc = scm_to_uint16 (x); break; case FFI_TYPE_SINT16: - *(scm_t_int16 *) loc = scm_to_int16 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int16 (x); + else + *(scm_t_int16 *) loc = scm_to_int16 (x); break; case FFI_TYPE_UINT32: - *(scm_t_uint32 *) loc = scm_to_uint32 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_uint32 (x); + else + *(scm_t_uint32 *) loc = scm_to_uint32 (x); break; case FFI_TYPE_SINT32: - *(scm_t_int32 *) loc = scm_to_int32 (x); + if (return_value_p) + *(ffi_arg *) loc = scm_to_int32 (x); + else + *(scm_t_int32 *) loc = scm_to_int32 (x); break; case FFI_TYPE_UINT64: *(scm_t_uint64 *) loc = scm_to_uint64 (x); @@ -1073,7 +1095,7 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) args[i] = (void *) ROUND_UP ((scm_t_uintptr) data + off, cif->arg_types[i]->alignment); assert ((scm_t_uintptr) args[i] % cif->arg_types[i]->alignment == 0); - unpack (cif->arg_types[i], args[i], argv[i]); + unpack (cif->arg_types[i], args[i], argv[i], 0); } /* Prepare space for the return value. On some platforms, such as @@ -1112,7 +1134,7 @@ invoke_closure (ffi_cif *cif, void *ret, void **args, void *data) result = scm_call_n (proc, argv, cif->nargs); - unpack (cif->rtype, ret, result); + unpack (cif->rtype, ret, result, 1); } SCM_DEFINE (scm_procedure_to_pointer, "procedure->pointer", 3, 0, 0, -- 1.7.7.4 -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ------------=_1324253762-8832-1--