extract code to align the argument storage pointer to a helper function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
diff --git a/src/arm/ffi.c b/src/arm/ffi.c
index 3ccceb9..4b5fb3d 100644
--- a/src/arm/ffi.c
+++ b/src/arm/ffi.c
@@ -37,6 +37,31 @@
static int vfp_type_p (ffi_type *);
static void layout_vfp_args (ffi_cif *);
+static char* ffi_align(ffi_type **p_arg, char *argp)
+{
+ /* Align if necessary */
+ register size_t alignment = (*p_arg)->alignment;
+ if (alignment < 4)
+ {
+ alignment = 4;
+ }
+#ifdef _WIN32_WCE
+ if (alignment > 4)
+ {
+ alignment = 4;
+ }
+#endif
+ if ((alignment - 1) & (unsigned) argp)
+ {
+ argp = (char *) ALIGN(argp, alignment);
+ }
+
+ if ((*p_arg)->type == FFI_TYPE_STRUCT)
+ {
+ argp = (char *) ALIGN(argp, 4);
+ }
+ return argp;
+}
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments
@@ -65,7 +90,6 @@ int ffi_prep_args(char *stack, extended_cif *ecif, float *vfp_space)
i--, p_arg++)
{
size_t z;
- size_t alignment;
/* Allocated in VFP registers. */
if (ecif->cif->abi == FFI_VFP
@@ -81,19 +105,7 @@ int ffi_prep_args(char *stack, extended_cif *ecif, float *vfp_space)
p_argv++;
continue;
}
-
- /* Align if necessary */
- alignment = (*p_arg)->alignment;
-#ifdef _WIN32_WCE
- if (alignment > 4)
- alignment = 4;
-#endif
- if ((alignment - 1) & (unsigned) argp) {
- argp = (char *) ALIGN(argp, alignment);
- }
-
- if ((*p_arg)->type == FFI_TYPE_STRUCT)
- argp = (char *) ALIGN(argp, 4);
+ argp = ffi_align(p_arg, argp);
z = (*p_arg)->size;
if (z < sizeof(int))
@@ -329,7 +341,6 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
{
size_t z;
- size_t alignment;
if (cif->abi == FFI_VFP
&& vi < cif->vfp_nargs && vfp_type_p (*p_arg))
@@ -337,19 +348,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
*p_argv++ = (void*)(vfp_stack + cif->vfp_args[vi++]);
continue;
}
-
- alignment = (*p_arg)->alignment;
- if (alignment < 4)
- alignment = 4;
-#ifdef _WIN32_WCE
- else
- if (alignment > 4)
- alignment = 4;
-#endif
- /* Align if necessary */
- if ((alignment - 1) & (unsigned) argp) {
- argp = (char *) ALIGN(argp, alignment);
- }
+ argp = ffi_align(p_arg, argp);
z = (*p_arg)->size;