1 /* go-typedesc-equal.c -- return whether two type descriptors are equal. 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 "runtime.h" 8 #include "go-string.h" 9 #include "go-type.h" 10 11 /* Compare type descriptors for equality. This is necessary because 12 types may have different descriptors in different shared libraries. 13 Also, unnamed types may have multiple type descriptors even in a 14 single shared library. */ 15 16 _Bool __go_type_descriptors_equal(const struct __go_type_descriptor * td1,const struct __go_type_descriptor * td2)17__go_type_descriptors_equal (const struct __go_type_descriptor *td1, 18 const struct __go_type_descriptor *td2) 19 { 20 if (td1 == td2) 21 return 1; 22 /* In a type switch we can get a NULL descriptor. */ 23 if (td1 == NULL || td2 == NULL) 24 return 0; 25 if (td1->__code != td2->__code || td1->__hash != td2->__hash) 26 return 0; 27 if (td1->__uncommon != NULL && td1->__uncommon->__name != NULL) 28 { 29 if (td2->__uncommon == NULL || td2->__uncommon->__name == NULL) 30 return 0; 31 return (__go_ptr_strings_equal (td1->__uncommon->__name, 32 td2->__uncommon->__name) 33 && __go_ptr_strings_equal (td1->__uncommon->__pkg_path, 34 td2->__uncommon->__pkg_path)); 35 } 36 if (td2->__uncommon != NULL && td2->__uncommon->__name != NULL) 37 return 0; 38 return __go_ptr_strings_equal (td1->__reflection, td2->__reflection); 39 } 40