libgupc/
[official-gcc.git] / libgo / runtime / go-interface-eface-compare.c
blobdb03b914c8443dad34d68454ce335595f8dd8423
1 /* go-interface-eface-compare.c -- compare non-empty and empty interface.
3 Copyright 2011 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "runtime.h"
8 #include "interface.h"
10 /* Compare a non-empty interface value with an empty interface value.
11 Return 0 for equal, not zero for not equal (return value is like
12 strcmp). */
14 int
15 __go_interface_empty_compare (struct __go_interface left,
16 struct __go_empty_interface right)
18 const struct __go_type_descriptor *left_descriptor;
20 if (((uintptr_t) right.__type_descriptor & reflectFlags) != 0)
21 runtime_panicstring ("invalid interface value");
22 if (left.__methods == NULL && right.__type_descriptor == NULL)
23 return 0;
24 if (left.__methods == NULL || right.__type_descriptor == NULL)
25 return 1;
26 left_descriptor = left.__methods[0];
27 if (!__go_type_descriptors_equal (left_descriptor, right.__type_descriptor))
28 return 1;
29 if (__go_is_pointer_type (left_descriptor))
30 return left.__object == right.__object ? 0 : 1;
31 if (!left_descriptor->__equalfn (left.__object, right.__object,
32 left_descriptor->__size))
33 return 1;
34 return 0;