* bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call
@ 2011-12-03 11:17 Andreas Schwab
2011-12-19 0:13 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2011-12-03 11:17 UTC (permalink / raw)
To: 10203
* 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."
^ permalink raw reply related [flat|nested] 2+ messages in thread
* bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call
2011-12-03 11:17 bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call Andreas Schwab
@ 2011-12-19 0:13 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2011-12-19 0:13 UTC (permalink / raw)
To: Andreas Schwab; +Cc: 10203-done
Hi Andreas,
Andreas Schwab <schwab@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’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-19 0:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-03 11:17 bug#10203: [PATCH] FFI: Properly unpack small integer return values in closure call Andreas Schwab
2011-12-19 0:13 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).