1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Cosmetic changes in `foreign.c'.

* libguile/foreign.c (unpack, pack): Add `const' qualifier for `type'.
  Comment.  Indent.
  (scm_i_foreign_call): Add `const' qualifier for `argv'.  Punctuate
  comments.  Clarify argument unpacking loop.
This commit is contained in:
Ludovic Courtès 2010-03-20 17:00:38 +01:00
parent a2c6904911
commit 165a8643ae
2 changed files with 45 additions and 43 deletions

View file

@ -844,8 +844,9 @@ cif_to_procedure (SCM cif, SCM func_ptr)
return ret;
}
/* Set *LOC to the foreign representation of X with TYPE. */
static void
unpack (ffi_type *type, void *loc, SCM x)
unpack (const ffi_type *type, void *loc, SCM x)
{
switch (type->type)
{
@ -881,8 +882,7 @@ unpack (ffi_type *type, void *loc, SCM x)
break;
case FFI_TYPE_STRUCT:
if (!SCM_FOREIGN_TYPED_P (x, VOID))
scm_wrong_type_arg_msg ("foreign-call", 0, x,
"foreign void pointer");
scm_wrong_type_arg_msg ("foreign-call", 0, x, "foreign void pointer");
if (SCM_FOREIGN_LEN (x) && SCM_FOREIGN_LEN (x) != type->size)
scm_wrong_type_arg_msg ("foreign-call", 0, x,
"foreign void pointer of correct length");
@ -890,8 +890,7 @@ unpack (ffi_type *type, void *loc, SCM x)
break;
case FFI_TYPE_POINTER:
if (!SCM_FOREIGN_TYPED_P (x, VOID))
scm_wrong_type_arg_msg ("foreign-call", 0, x,
"foreign void pointer");
scm_wrong_type_arg_msg ("foreign-call", 0, x, "foreign void pointer");
*(void **) loc = SCM_FOREIGN_POINTER (x, void);
break;
default:
@ -899,8 +898,9 @@ unpack (ffi_type *type, void *loc, SCM x)
}
}
/* Return a Scheme representation of the foreign value at LOC of type TYPE. */
static SCM
pack (ffi_type *type, void *loc)
pack (const ffi_type * type, const void *loc)
{
switch (type->type)
{
@ -941,8 +941,9 @@ pack (ffi_type *type, void *loc)
}
}
SCM
scm_i_foreign_call (SCM foreign, SCM *argv)
scm_i_foreign_call (SCM foreign, const SCM *argv)
{
/* FOREIGN is the pair that cif_to_procedure set as the 0th element of the
objtable. */
@ -955,8 +956,8 @@ scm_i_foreign_call (SCM foreign, SCM *argv)
size_t arg_size;
scm_t_ptrdiff off;
cif = SCM_FOREIGN_POINTER (scm_car (foreign), ffi_cif);
func = SCM_FOREIGN_POINTER (scm_cdr (foreign), void);
cif = SCM_FOREIGN_POINTER (SCM_CAR (foreign), ffi_cif);
func = SCM_FOREIGN_POINTER (SCM_CDR (foreign), void);
/* Argument pointers. */
args = alloca (sizeof(void*) * cif->nargs);
@ -974,16 +975,17 @@ scm_i_foreign_call (SCM foreign, SCM *argv)
data = alloca (arg_size
+ ROUND_UP (cif->rtype->size, cif->rtype->alignment));
/* unpack argv to native values, setting argv pointers */
off = 0;
for (i = 0; i < cif->nargs; i++)
/* Unpack ARGV to native values, setting ARGV pointers. */
for (i = 0, off = 0;
i < cif->nargs;
off += cif->arg_types[i]->size, i++)
{
off = ROUND_UP (off, cif->arg_types[i]->alignment);
args[i] = data + off;
unpack (cif->arg_types[i], args[i], argv[i]);
off += cif->arg_types[i]->size;
}
/* prep space for the return value */
/* Prepare space for the return value. */
off = ROUND_UP (off, cif->rtype->alignment);
rvalue = data + off;

View file

@ -121,7 +121,7 @@ SCM_INTERNAL void scm_i_foreign_print (SCM foreign, SCM port,
SCM_API SCM scm_make_foreign_function (SCM return_type, SCM func_ptr,
SCM arg_types);
SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, SCM *argv);
SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv);