From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30411 invoked by alias); 29 Dec 2002 16:06:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 30396 invoked by uid 71); 29 Dec 2002 16:06:01 -0000 Date: Sun, 29 Dec 2002 08:06:00 -0000 Message-ID: <20021229160601.30395.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Jeff Sturm Subject: Re: libgcj/9078: libffi: problems with uint8 on powerpc Reply-To: Jeff Sturm X-SW-Source: 2002-12/txt/msg01366.txt.bz2 List-Id: The following reply was made to PR libgcj/9078; it has been noted by GNATS. From: Jeff Sturm To: 173074@bugs.debian.org Cc: gcc-gnats@gcc.gnu.org, , , , , David Paul BELANGER Subject: Re: libgcj/9078: libffi: problems with uint8 on powerpc Date: Sun, 29 Dec 2002 11:04:41 -0500 (EST) On Sat, 28 Dec 2002, Matthias Klose wrote: > ffi_type_uint8 and other arguments shorter than one word are > not passed in correctly to the function called by ffi_call. For an ffi_type_uint8, ffi_call expects the corresponding value pointer to be a (unsigned char *). So this is correct usage: int b = 24; args[0] = &ffi_type_uint; values[0] = &b; Also correct would be: unsigned char b = 24; args[0] = &ffi_type_uint8; values[0] = &b; > Also, returns values are not passed correctly. For example, instead of > finding the returned byte value where the pointer points to, it is found > at an offset of 3 from the pointer. Return values are handled a little differently than arguments. libffi/README says: RVALUE is a pointer to a chunk of memory that is to hold the result of the function call. Currently, it must be at least one word in size (except for the n32 version under Irix 6.x, which must be a pointer to an 8 byte aligned value (a long long). It must also be at least word aligned (depending on the return type, and the system's alignment requirements). If RTYPE is &ffi_type_void, this is ignored. If RVALUE is NULL, the return value is discarded. So this cannot work: unsigned char result; if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint8, args) != FFI_OK) { You could use "unsigned int result" on a 32-bit target, or use ffi_arg which is typedef'ed to work correctly on 32 or 64-bit targets: ffi_arg result; if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_uint8, args) != FFI_OK) { With those changes your example should be portable to any target supported by libffi. Jeff