* src/types.c (FFI_TYPEDEF, FFI_NONCONST_TYPEDEF): Merge the macros by adding another argument that controls whether the result is const or not (FFI_LDBL_CONST): Temporary macro to reduce ifdef confusion * src/prep_cif.c (ffi_prep_cif_core): Replace list of systems with new macro FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION * src/pa/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION): Define. * src/s390/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION): Define. * src/x86/ffitarget.h (FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION): Define. 2014-07-22 Dominik Vogt <vogt@linux.vnet.ibm.com> * doc/libffi.texi (Primitive Types): Document ffi_type_complex_float, ffi_type_complex_double and ffi_type_complex_longdouble (Complex Types): New subsection. (Complex Type Example): Ditto. * testsuite/libffi.call/cls_align_complex_double.c: New FFI_TYPE_COMPLEX test. * testsuite/libffi.call/cls_align_complex_float.c: Ditto. * testsuite/libffi.call/cls_align_complex_longdouble.c: Ditto. * testsuite/libffi.call/cls_complex_double.c: Ditto. * testsuite/libffi.call/cls_complex_float.c: Ditto. * testsuite/libffi.call/cls_complex_longdouble.c: Ditto. * testsuite/libffi.call/cls_complex_struct_double.c: Ditto. * testsuite/libffi.call/cls_complex_struct_float.c: Ditto. * testsuite/libffi.call/cls_complex_struct_longdouble.c: Ditto. * testsuite/libffi.call/cls_complex_va_double.c: Ditto. * testsuite/libffi.call/cls_complex_va_float.c: Ditto. * testsuite/libffi.call/cls_complex_va_longdouble.c: Ditto. * testsuite/libffi.call/complex_double.c: Ditto. * testsuite/libffi.call/complex_defs_double.c: Ditto. * testsuite/libffi.call/complex_float.c: Ditto. * testsuite/libffi.call/complex_defs_float.c: Ditto. * testsuite/libffi.call/complex_longdouble.c: Ditto. * testsuite/libffi.call/complex_defs_longdouble.c: Ditto. * testsuite/libffi.call/complex_int.c: Ditto. * testsuite/libffi.call/many_complex_double.c: Ditto. * testsuite/libffi.call/many_complex_float.c: Ditto. * testsuite/libffi.call/many_complex_longdouble.c: Ditto. * testsuite/libffi.call/return_complex1_double.c: Ditto. * testsuite/libffi.call/return_complex1_float.c: Ditto. * testsuite/libffi.call/return_complex1_longdouble.c: Ditto. * testsuite/libffi.call/return_complex2_double.c: Ditto. * testsuite/libffi.call/return_complex2_float.c: Ditto. * testsuite/libffi.call/return_complex2_longdouble.c: Ditto. * testsuite/libffi.call/return_complex_double.c: Ditto. * testsuite/libffi.call/return_complex_float.c: Ditto. * testsuite/libffi.call/return_complex_longdouble.c: Ditto. * src/raw_api.c (ffi_raw_to_ptrarray): Handle FFI_TYPE_COMPLEX (ffi_ptrarray_to_raw): Ditto. * src/prep_cif.c (ffi_prep_cif_core): Abort if FFI_TYPE_COMPLEX is not implemented in libffi for the target. * src/java_raw_api.c (ffi_java_raw_size): FFI_TYPE_COMPLEX not supported yet (abort). (ffi_java_raw_to_ptrarray): Ditto. (ffi_java_rvalue_to_raw): Ditto. (ffi_java_raw_to_rvalue): Ditto. * src/debug.c (ffi_type_test): Add debug tests for complex types. * include/ffi.h.in (FFI_TYPE_COMPLEX): Add new FFI_TYPE_COMPLEX. (FFI_TYPE_LAST): Bump. (ffi_type_complex_float): Add new ffi_type_.... (ffi_type_complex_double): Ditto. (ffi_type_complex_longdouble): Ditto. 2014-07-22 Dominik Vogt <vogt@linux.vnet.ibm.com> * src/s390/ffitarget.h (FFI_TARGET_HAS_COMPLEX_TYPE): Define to provide FFI_TYPE_COMPLEX support. * src/s390/ffi.c (ffi_check_struct_type): Implement FFI_TYPE_COMPLEX (ffi_prep_args): Ditto. (ffi_prep_cif_machdep): Ditto. (ffi_closure_helper_SYSV): Ditto.
81 lines
2.0 KiB
C
81 lines
2.0 KiB
C
/* -*-c-*- */
|
|
#include "ffitest.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <complex.h>
|
|
|
|
static _Complex T_C_TYPE gComplexValue1 = 1 + 2 * I;
|
|
static _Complex T_C_TYPE gComplexValue2 = 3 + 4 * I;
|
|
|
|
static int cls_variadic(const char *format, ...)
|
|
{
|
|
va_list ap;
|
|
_Complex T_C_TYPE p1, p2;
|
|
|
|
va_start (ap, format);
|
|
p1 = va_arg (ap, _Complex T_C_TYPE);
|
|
p2 = va_arg (ap, _Complex T_C_TYPE);
|
|
va_end (ap);
|
|
|
|
return printf(format, T_CONV creal (p1), T_CONV cimag (p1),
|
|
T_CONV creal (p2), T_CONV cimag (p2));
|
|
}
|
|
|
|
static void
|
|
cls_complex_va_fn(ffi_cif* cif __UNUSED__, void* resp,
|
|
void** args, void* userdata __UNUSED__)
|
|
{
|
|
char* format = *(char**)args[0];
|
|
gComplexValue1 = *(_Complex T_C_TYPE*)args[1];
|
|
gComplexValue2 = *(_Complex T_C_TYPE*)args[2];
|
|
|
|
*(ffi_arg*)resp =
|
|
printf(format,
|
|
T_CONV creal (gComplexValue1), T_CONV cimag (gComplexValue1),
|
|
T_CONV creal (gComplexValue2), T_CONV cimag (gComplexValue2));
|
|
}
|
|
|
|
int main (void)
|
|
{
|
|
ffi_cif cif;
|
|
void *code;
|
|
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
void* args[4];
|
|
ffi_type* arg_types[4];
|
|
char *format = "%.1f,%.1fi %.1f,%.1fi\n";
|
|
|
|
_Complex T_C_TYPE complexArg1 = 1.0 + 22.0 *I;
|
|
_Complex T_C_TYPE complexArg2 = 333.0 + 4444.0 *I;
|
|
ffi_arg res = 0;
|
|
|
|
arg_types[0] = &ffi_type_pointer;
|
|
arg_types[1] = &T_FFI_TYPE;
|
|
arg_types[2] = &T_FFI_TYPE;
|
|
arg_types[3] = NULL;
|
|
|
|
/* This printf call is variadic */
|
|
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 3, &ffi_type_sint,
|
|
arg_types) == FFI_OK);
|
|
|
|
args[0] = &format;
|
|
args[1] = &complexArg1;
|
|
args[2] = &complexArg2;
|
|
args[3] = NULL;
|
|
|
|
ffi_call(&cif, FFI_FN(cls_variadic), &res, args);
|
|
printf("res: %d\n", (int) res);
|
|
CHECK (res == 24);
|
|
|
|
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_complex_va_fn, NULL, code)
|
|
== FFI_OK);
|
|
|
|
res = ((int(*)(char *, ...))(code))(format, complexArg1, complexArg2);
|
|
CHECK (gComplexValue1 == complexArg1);
|
|
CHECK (gComplexValue2 == complexArg2);
|
|
printf("res: %d\n", (int) res);
|
|
CHECK (res == 24);
|
|
|
|
exit(0);
|
|
}
|