• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Returning values from objc_msgSend etc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning values from objc_msgSend etc


  • Subject: Re: Returning values from objc_msgSend etc
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 31 Mar 2008 17:54:45 +0200

returnCharValue  is not a valid argument for ffi_call

man ffi_call

void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue);
rvalue must point to storage that is sizeof(long) or larger. For smaller
return value sizes, the ffi_arg or ffi_sarg integral type must be used to
hold the return value


Le 31 mars 08 à 17:34, Sherm Pendley a écrit :

On Sat, Mar 1, 2008 at 9:00 AM, Greg Parker <email@hidden> wrote:

libffi is smart enough to know about all of the ABI rules. If your ffi_types
correctly describe the method's parameters, then libffi will marshal them
properly. (If it doesn't, then that's a libffi bug.)


I don't think libffi does any type promotion.


Indeed not - the sample below prints different results when run on PPC
(including Rosetta) and i386. On PPC, only the promoted version returns the
correct result. On Intel, both of them do. The question then, becomes -
should libffi be handling this difference transparently?


sherm--

#include <stdio.h>

#define MACOSX
#include <ffi.h>

char getCharFunction() {
   return 5;
}

int main (int argc, const char * argv[]) {
   ffi_cif cif_nopromote;
   ffi_cif cif_promote;

   long returnLongValue;
   char returnCharValue;

   if (ffi_prep_cif( &cif_nopromote,
                     FFI_DEFAULT_ABI,
                     0,
                     &ffi_type_schar,
                     NULL
                     )
       != FFI_OK ) {
       printf("%s", "Error creating ffi cif_nopromote\n");
       return 1;
   }

   if (ffi_prep_cif( &cif_promote,
                     FFI_DEFAULT_ABI,
                     0,
                     &ffi_type_slong,
                     NULL
                     )
       != FFI_OK ) {
       printf("%s", "Error creating ffi cif_promote\n");
       return 1;
   }

ffi_call(&cif_nopromote,
(void(*)(void))getCharFunction,
&returnCharValue,
NULL
);
printf("Return value from cif_nopromote is %d.\n", returnCharValue);


   ffi_call(&cif_promote,
            (void(*)(void))getCharFunction,
            &returnLongValue,
            NULL
            );
   printf("Return value from cif_promote is %d.\n", returnLongValue);

   return 0;
}





--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Returning values from objc_msgSend etc (From: "Sherm Pendley" <email@hidden>)
 >Re: Returning values from objc_msgSend etc (From: Greg Parker <email@hidden>)
 >Re: Returning values from objc_msgSend etc (From: "Sherm Pendley" <email@hidden>)

  • Prev by Date: Re: Returning values from objc_msgSend etc
  • Next by Date: Re: Spaces Implementation
  • Previous by thread: Re: Returning values from objc_msgSend etc
  • Next by thread: Re: Returning values from objc_msgSend etc
  • Index(es):
    • Date
    • Thread