Importing Upstream version 4.8.2
[platform/upstream/gcc48.git] / libgo / runtime / go-interface-compare.c
1 /* go-interface-compare.c -- compare two interface values.
2
3    Copyright 2009 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.  */
6
7 #include <stddef.h>
8
9 #include "runtime.h"
10 #include "go-type.h"
11 #include "interface.h"
12
13 /* Compare two interface values.  Return 0 for equal, not zero for not
14    equal (return value is like strcmp).  */
15
16 int
17 __go_interface_compare (struct __go_interface left,
18                         struct __go_interface right)
19 {
20   const struct __go_type_descriptor *left_descriptor;
21
22   if (left.__methods == NULL && right.__methods == NULL)
23     return 0;
24   if (left.__methods == NULL || right.__methods == NULL)
25     return 1;
26   left_descriptor = left.__methods[0];
27   if (!__go_type_descriptors_equal (left_descriptor, right.__methods[0]))
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;
35 }