2012-01-13 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / runtime / go-interface-val-compare.c
blob15898924ac863545c1cc09638843a47f01e1f977
1 /* go-interface-val-compare.c -- compare an interface to a value.
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. */
7 #include "go-type.h"
8 #include "interface.h"
10 /* Compare two interface values. Return 0 for equal, not zero for not
11 equal (return value is like strcmp). */
13 int
14 __go_interface_value_compare (
15 struct __go_interface left,
16 const struct __go_type_descriptor *right_descriptor,
17 const void *val)
19 const struct __go_type_descriptor *left_descriptor;
21 if (left.__methods == NULL)
22 return 1;
23 left_descriptor = left.__methods[0];
24 if (!__go_type_descriptors_equal (left_descriptor, right_descriptor))
25 return 1;
26 if (__go_is_pointer_type (left_descriptor))
27 return left.__object == val ? 0 : 1;
28 if (!left_descriptor->__equalfn (left.__object, val,
29 left_descriptor->__size))
30 return 1;
31 return 0;