* Backport reflect.Call fixes to 4.8 branch
@ 2013-11-28 3:51 Michael Hudson-Doyle
2013-12-03 1:51 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: Michael Hudson-Doyle @ 2013-11-28 3:51 UTC (permalink / raw)
To: gcc-patches; +Cc: Ian Lance Taylor
This patch brings the recent fix for calling a function or method that
takes or returns an empty struct via reflection to the 4.8 branch.
Cheers,
mwh
diff --git a/libgo/go/reflect/all_test.go b/libgo/go/reflect/all_test.go
index 526f09b..eecc459 100644
--- a/libgo/go/reflect/all_test.go
+++ b/libgo/go/reflect/all_test.go
@@ -1430,6 +1430,46 @@ func TestFunc(t *testing.T) {
}
}
+type emptyStruct struct{}
+
+type nonEmptyStruct struct {
+ member int
+}
+
+func returnEmpty() emptyStruct {
+ return emptyStruct{}
+}
+
+func takesEmpty(e emptyStruct) {
+}
+
+func returnNonEmpty(i int) nonEmptyStruct {
+ return nonEmptyStruct{member: i}
+}
+
+func takesNonEmpty(n nonEmptyStruct) int {
+ return n.member
+}
+
+func TestCallWithStruct(t *testing.T) {
+ r := ValueOf(returnEmpty).Call([]Value{})
+ if len(r) != 1 || r[0].Type() != TypeOf(emptyStruct{}) {
+ t.Errorf("returning empty struct returned %s instead", r)
+ }
+ r = ValueOf(takesEmpty).Call([]Value{ValueOf(emptyStruct{})})
+ if len(r) != 0 {
+ t.Errorf("takesEmpty returned values: %s", r)
+ }
+ r = ValueOf(returnNonEmpty).Call([]Value{ValueOf(42)})
+ if len(r) != 1 || r[0].Type() != TypeOf(nonEmptyStruct{}) || r[0].Field(0).Int() != 42 {
+ t.Errorf("returnNonEmpty returned %s", r)
+ }
+ r = ValueOf(takesNonEmpty).Call([]Value{ValueOf(nonEmptyStruct{member: 42})})
+ if len(r) != 1 || r[0].Type() != TypeOf(1) || r[0].Int() != 42 {
+ t.Errorf("takesNonEmpty returned %s", r)
+ }
+}
+
func TestMakeFunc(t *testing.T) {
switch runtime.GOARCH {
case "amd64", "386":
diff --git a/libgo/runtime/go-reflect-call.c b/libgo/runtime/go-reflect-call.c
index 5cf3707..12bd0d7 100644
--- a/libgo/runtime/go-reflect-call.c
+++ b/libgo/runtime/go-reflect-call.c
@@ -98,9 +98,12 @@ go_struct_to_ffi (const struct __go_struct_type *descriptor)
const struct __go_struct_field *fields;
int i;
+ field_count = descriptor->__fields.__count;
+ if (field_count == 0) {
+ return &ffi_type_void;
+ }
ret = (ffi_type *) __go_alloc (sizeof (ffi_type));
ret->type = FFI_TYPE_STRUCT;
- field_count = descriptor->__fields.__count;
fields = (const struct __go_struct_field *) descriptor->__fields.__values;
ret->elements = (ffi_type **) __go_alloc ((field_count + 1)
* sizeof (ffi_type *));
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Backport reflect.Call fixes to 4.8 branch
2013-11-28 3:51 Backport reflect.Call fixes to 4.8 branch Michael Hudson-Doyle
@ 2013-12-03 1:51 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2013-12-03 1:51 UTC (permalink / raw)
To: Michael Hudson-Doyle; +Cc: gcc-patches
On Wed, Nov 27, 2013 at 3:01 PM, Michael Hudson-Doyle
<michael.hudson@linaro.org> wrote:
> This patch brings the recent fix for calling a function or method that
> takes or returns an empty struct via reflection to the 4.8 branch.
Thanks. Committed to 4.8 branch.
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-12-03 1:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28 3:51 Backport reflect.Call fixes to 4.8 branch Michael Hudson-Doyle
2013-12-03 1:51 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).