Merge aosp-toolchain/gcc/gcc-4_9 changes.
[official-gcc.git] / gcc-4_8 / libgo / runtime / go-eface-compare.c
blobe738efced80a6bb2b31721894ba7ad70e696404e
1 /* go-eface-compare.c -- compare two empty values.
3 Copyright 2010 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 "go-type.h"
9 #include "interface.h"
11 /* Compare two interface values. Return 0 for equal, not zero for not
12 equal (return value is like strcmp). */
14 intgo
15 __go_empty_interface_compare (struct __go_empty_interface left,
16 struct __go_empty_interface right)
18 const struct __go_type_descriptor *left_descriptor;
20 left_descriptor = left.__type_descriptor;
22 if (((uintptr_t) left_descriptor & reflectFlags) != 0
23 || ((uintptr_t) right.__type_descriptor & reflectFlags) != 0)
24 runtime_panicstring ("invalid interface value");
26 if (left_descriptor == NULL && right.__type_descriptor == NULL)
27 return 0;
28 if (left_descriptor == NULL || right.__type_descriptor == NULL)
29 return 1;
30 if (!__go_type_descriptors_equal (left_descriptor,
31 right.__type_descriptor))
32 return 1;
33 if (__go_is_pointer_type (left_descriptor))
34 return left.__object == right.__object ? 0 : 1;
35 if (!left_descriptor->__equalfn (left.__object, right.__object,
36 left_descriptor->__size))
37 return 1;
38 return 0;