From 84235d9e7ba8a55dea182adc4007bfab6a35fb1f Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Wed, 29 Oct 2014 09:08:01 +0100 Subject: [PATCH] libgo: Enable complex number support from libffi. --- libgo/runtime/go-ffi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libgo/runtime/go-ffi.c b/libgo/runtime/go-ffi.c index 21879b9..42462d0 100644 --- a/libgo/runtime/go-ffi.c +++ b/libgo/runtime/go-ffi.c @@ -150,11 +150,26 @@ go_complex_to_ffi (ffi_type *float_type) ffi_type *ret; ret = (ffi_type *) __go_alloc (sizeof (ffi_type)); + /* Use libffi with complex type support for targets that have it. This should + be the case for all targets eventually, so the #else branch should then be + removed. */ +#if defined (__s390__) && defined (FFI_TYPE_COMPLEX) + ret->type = FFI_TYPE_COMPLEX; + ret->size = 2 * float_type->size; + ret->alignment = float_type->alignment; + ret->elements = (ffi_type **) __go_alloc (2 * sizeof (ffi_type *)); + ret->elements[0] = float_type; + ret->elements[1] = NULL; +#else + /* Warning: This works only on platforms that define C _Complex types like + structures in their Abi. */ ret->type = FFI_TYPE_STRUCT; ret->elements = (ffi_type **) __go_alloc (3 * sizeof (ffi_type *)); ret->elements[0] = float_type; ret->elements[1] = float_type; ret->elements[2] = NULL; +#endif + return ret; } @@ -184,6 +199,9 @@ go_type_to_ffi (const struct __go_type_descriptor *descriptor) #ifdef __alpha__ runtime_throw("the libffi library does not support Complex64 type with " "reflect.Call or runtime.SetFinalizer"); +#elif defined(__s390__) && !defined(FFI_TYPE_COMPLEX) + runtime_throw("the libffi library does not support Complex64 type with " + "reflect.Call or runtime.SetFinalizer"); #else if (sizeof (float) == 4) return go_complex_to_ffi (&ffi_type_float); @@ -193,6 +211,9 @@ go_type_to_ffi (const struct __go_type_descriptor *descriptor) #ifdef __alpha__ runtime_throw("the libffi library does not support Complex128 type with " "reflect.Call or runtime.SetFinalizer"); +#elif defined(__s390__) && !defined(FFI_TYPE_COMPLEX) + runtime_throw("the libffi library does not support Complex128 type with " + "reflect.Call or runtime.SetFinalizer"); #else if (sizeof (double) == 8) return go_complex_to_ffi (&ffi_type_double); -- 1.8.4.2