Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / runtime / go-interface-eface-compare.c
1 /* go-interface-eface-compare.c -- compare non-empty and empty interface.
2
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.  */
6
7 #include "runtime.h"
8 #include "go-type.h"
9 #include "interface.h"
10
11 /* Compare a non-empty interface value with an empty interface value.
12    Return 0 for equal, not zero for not equal (return value is like
13    strcmp).  */
14
15 intgo
16 __go_interface_empty_compare (struct __go_interface left,
17                               struct __go_empty_interface right)
18 {
19   const struct __go_type_descriptor *left_descriptor;
20
21   if (((uintptr_t) right.__type_descriptor & reflectFlags) != 0)
22     runtime_panicstring ("invalid interface value");
23   if (left.__methods == NULL && right.__type_descriptor == NULL)
24     return 0;
25   if (left.__methods == NULL || right.__type_descriptor == NULL)
26     return 1;
27   left_descriptor = left.__methods[0];
28   if (!__go_type_descriptors_equal (left_descriptor, right.__type_descriptor))
29     return 1;
30   if (__go_is_pointer_type (left_descriptor))
31     return left.__object == right.__object ? 0 : 1;
32   if (!left_descriptor->__equalfn (left.__object, right.__object,
33                                    left_descriptor->__size))
34     return 1;
35   return 0;
36 }