This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug other/13221] New: libffi's closure couldn't pass sequence of char and/or short arguments.


In 32bit x86 platform, libffi's closure couldn't pass sequence of char
and/or short type arguments.
Minimum test program is append below.

This probrem maybe fix by following patch below, because passing
arguments are always alignment 4bytes (Also if argument size was less
than 4bytes).

--

/* test program */

#include <ffi.h>

void test_func(ffi_cif *cif, void *rval, void **avals, void *data)
{
    printf("%d, %d\n", *(char *)avals[0], *(char *)avals[1]);
}

main()
{
    ffi_cif cif;
    ffi_closure closure;
    ffi_type *args[2];

    args[0] = &ffi_type_schar;
    args[1] = &ffi_type_schar;

    ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_void, args);
    ffi_prep_closure(&closure, &cif, test_func, NULL);

    ((void(*)(char, char))(&closure))(1, 2);
}

--

Index: ffi.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libffi/src/x86/ffi.c,v
retrieving revision 1.10
diff -u -r1.10 ffi.c
--- ffi.c	21 Mar 2003 13:43:20 -0000	1.10
+++ ffi.c	28 Nov 2003 17:25:13 -0000
@@ -301,8 +301,8 @@
       size_t z;
 
       /* Align if necessary */
-      if (((*p_arg)->alignment - 1) & (unsigned) argp) {
-	argp = (char *) ALIGN(argp, (*p_arg)->alignment);
+      if ((sizeof(int) - 1) & (unsigned) argp) {
+	argp = (char *) ALIGN(argp, sizeof(int));
       }
 
       z = (*p_arg)->size;

-- 
           Summary: libffi's closure couldn't pass sequence of char and/or
                    short arguments.
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hos at tamanegi dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13221


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]