GNU bug report logs - #10203
[PATCH] FFI: Properly unpack small integer return values in closure call

Previous Next

Package: guile;

Reported by: Andreas Schwab <schwab <at> linux-m68k.org>

Date: Sat, 3 Dec 2011 11:19:01 UTC

Severity: normal

Tags: patch

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10203 in the body.
You can then email your comments to 10203 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#10203; Package guile. (Sat, 03 Dec 2011 11:19:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Andreas Schwab <schwab <at> linux-m68k.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 03 Dec 2011 11:19:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: bug-guile <at> gnu.org
Subject: [PATCH] FFI: Properly unpack small integer return values in closure
	call
Date: Sat, 03 Dec 2011 12:17:46 +0100
* 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 <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Reply sent to ludo <at> gnu.org (Ludovic Courtès):
You have taken responsibility. (Mon, 19 Dec 2011 00:16:02 GMT) Full text and rfc822 format available.

Notification sent to Andreas Schwab <schwab <at> linux-m68k.org>:
bug acknowledged by developer. (Mon, 19 Dec 2011 00:16:02 GMT) Full text and rfc822 format available.

Message #10 received at 10203-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 10203-done <at> debbugs.gnu.org
Subject: Re: bug#10203: [PATCH] FFI: Properly unpack small integer return
	values in closure call
Date: Mon, 19 Dec 2011 01:13:31 +0100
Hi Andreas,

Andreas Schwab <schwab <at> linux-m68k.org> 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’.




Message #11 received at 10203-done <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 10203-done <at> debbugs.gnu.org
Subject: Re: bug#10203: [PATCH] FFI: Properly unpack small integer return
	values in closure call
Date: Mon, 19 Dec 2011 10:34:03 +0100
ludo <at> gnu.org (Ludovic Courtès) writes:

> Did you actually observe a problem on m68k or something?

Any big endian system qualifies.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Message #12 received at 10203-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 10203-done <at> debbugs.gnu.org
Subject: Re: bug#10203: [PATCH] FFI: Properly unpack small integer return
	values in closure call
Date: Mon, 19 Dec 2011 18:19:45 +0100
Hi,

Andreas Schwab <schwab <at> linux-m68k.org> skribis:

> ludo <at> gnu.org (Ludovic Courtès) writes:
>
>> Did you actually observe a problem on m68k or something?
>
> Any big endian system qualifies.

Hmm strangely, I fixed the dual of your patch on SPARC64 IIRC, which
was happy after that.

Anyway, thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 17 Jan 2012 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 102 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.