2016-07-13 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / libgo / runtime / go-type-eface.c
blob315c30efb7f609166f2ad217ddba6560aeb1937b
1 /* go-type-eface.c -- hash and equality empty interface functions.
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 "interface.h"
9 #include "go-type.h"
11 /* A hash function for an empty interface. */
13 uintptr_t
14 __go_type_hash_empty_interface (const void *vval,
15 uintptr_t key_size __attribute__ ((unused)))
17 const struct __go_empty_interface *val;
18 const struct __go_type_descriptor *descriptor;
19 uintptr_t size;
21 val = (const struct __go_empty_interface *) vval;
22 descriptor = val->__type_descriptor;
23 if (descriptor == NULL)
24 return 0;
25 size = descriptor->__size;
26 if (__go_is_pointer_type (descriptor))
27 return __go_call_hashfn (descriptor->__hashfn, &val->__object, size);
28 else
29 return __go_call_hashfn (descriptor->__hashfn, val->__object, size);
32 const FuncVal __go_type_hash_empty_interface_descriptor =
33 { (void *) __go_type_hash_empty_interface };
35 /* An equality function for an empty interface. */
37 _Bool
38 __go_type_equal_empty_interface (const void *vv1, const void *vv2,
39 uintptr_t key_size __attribute__ ((unused)))
41 const struct __go_empty_interface *v1;
42 const struct __go_empty_interface *v2;
43 const struct __go_type_descriptor* v1_descriptor;
44 const struct __go_type_descriptor* v2_descriptor;
46 v1 = (const struct __go_empty_interface *) vv1;
47 v2 = (const struct __go_empty_interface *) vv2;
48 v1_descriptor = v1->__type_descriptor;
49 v2_descriptor = v2->__type_descriptor;
50 if (v1_descriptor == NULL || v2_descriptor == NULL)
51 return v1_descriptor == v2_descriptor;
52 if (!__go_type_descriptors_equal (v1_descriptor, v2_descriptor))
53 return 0;
54 if (__go_is_pointer_type (v1_descriptor))
55 return v1->__object == v2->__object;
56 else
57 return __go_call_equalfn (v1_descriptor->__equalfn, v1->__object,
58 v2->__object, v1_descriptor->__size);
61 const FuncVal __go_type_equal_empty_interface_descriptor =
62 { (void *) __go_type_equal_empty_interface };