Commits

Ronald Oussoren committed 4890497

Missing file from merger with ctype's copy of libffi

Comments (0)

Files changed (1)

libffi-src/src/prep_cif.c

 
 #ifdef POWERPC_DARWIN
       {
-      int curalign;
+	      int curalign;
 
-      curalign = (*ptr)->alignment;
-      if (ptr != &(arg->elements[0])) {
-	      if (curalign > 4 && curalign != 16) {
-		      curalign = 4;
+	      curalign = (*ptr)->alignment;
+	      if (ptr != &(arg->elements[0])) {
+		      if (curalign > 4 && curalign != 16) {
+			      curalign = 4;
+		      }
 	      }
-      }
-
       arg->size = ALIGN(arg->size, curalign);
       arg->size += (*ptr)->size;
 
       arg->alignment = (arg->alignment > curalign) ? 
-	arg->alignment : curalign;
+	      arg->alignment : curalign;
       }
 #else
-      int curalign;
-
       arg->size = ALIGN(arg->size, (*ptr)->alignment);
       arg->size += (*ptr)->size;
 
   /*@=usedef@*/
 }
 
+#ifndef __CRIS__
+/* The CRIS ABI specifies structure elements to have byte
+   alignment only, so it completely overrides this functions,
+   which assumes "natural" alignment and padding.  */
+
 /* Perform machine independent ffi_cif preparation, then call
    machine dependent routine. */
 
+#ifdef X86_DARWIN
+static inline int struct_on_stack(int size)
+{
+	if (size > 8) return 1;
+	/* This is not what the ABI says, but is what is really implemented */
+	switch (size) {
+	case 1: case 2: case 4: case 8: return 0;
+	return 1;
+	}
+}
+#endif
+
+
 ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, 
 			ffi_abi abi, unsigned int nargs, 
 			/*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, 
       && (cif->abi != FFI_V9 || cif->rtype->size > 32)
 #endif
 #ifdef X86_DARWIN
-      && (cif->rtype->size > 8) 
+
+      && (struct_on_stack(cif->rtype->size))
 #endif
       )
     bytes = STACK_ARG_SIZE(sizeof(void*));
 	 check after the initialization.  */
       FFI_ASSERT_VALID_TYPE(*ptr);
 
-#ifdef X86_DARWIN
+#if defined(X86_DARWIN)
       {
-	/* Add padding, but at most to 4 bytes */
-	int align = (*ptr)->alignment;
-	if (align>4) align = 4;
-	if ((align - 1) & bytes) 
-	  bytes = ALIGN(bytes, align);
-        bytes += STACK_ARG_SIZE((*ptr)->size);
+	      int align = (*ptr)->alignment;
+	      if (align > 4) align = 4;
+	      if ((align - 1) & bytes)
+		 bytes = ALIGN(bytes, align);
+	      bytes += STACK_ARG_SIZE((*ptr)->size);
       }
+
 #elif !defined __x86_64__ && !defined S390 && !defined PA
 #ifdef SPARC
       if (((*ptr)->type == FFI_TYPE_STRUCT
   /* Perform machine dependent cif processing */
   return ffi_prep_cif_machdep(cif);
 }
+#endif /* not __CRIS__ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.