go-type-eface.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* go-type-eface.c -- hash and equality empty interface functions.
  2. Copyright 2010 The Go Authors. All rights reserved.
  3. Use of this source code is governed by a BSD-style
  4. license that can be found in the LICENSE file. */
  5. #include "runtime.h"
  6. #include "interface.h"
  7. #include "go-type.h"
  8. /* A hash function for an empty interface. */
  9. uintptr_t
  10. __go_type_hash_empty_interface (const void *vval,
  11. uintptr_t key_size __attribute__ ((unused)))
  12. {
  13. const struct __go_empty_interface *val;
  14. const struct __go_type_descriptor *descriptor;
  15. uintptr_t size;
  16. val = (const struct __go_empty_interface *) vval;
  17. descriptor = val->__type_descriptor;
  18. if (descriptor == NULL)
  19. return 0;
  20. size = descriptor->__size;
  21. if (__go_is_pointer_type (descriptor))
  22. return descriptor->__hashfn (&val->__object, size);
  23. else
  24. return descriptor->__hashfn (val->__object, size);
  25. }
  26. /* An equality function for an empty interface. */
  27. _Bool
  28. __go_type_equal_empty_interface (const void *vv1, const void *vv2,
  29. uintptr_t key_size __attribute__ ((unused)))
  30. {
  31. const struct __go_empty_interface *v1;
  32. const struct __go_empty_interface *v2;
  33. const struct __go_type_descriptor* v1_descriptor;
  34. const struct __go_type_descriptor* v2_descriptor;
  35. v1 = (const struct __go_empty_interface *) vv1;
  36. v2 = (const struct __go_empty_interface *) vv2;
  37. v1_descriptor = v1->__type_descriptor;
  38. v2_descriptor = v2->__type_descriptor;
  39. if (v1_descriptor == NULL || v2_descriptor == NULL)
  40. return v1_descriptor == v2_descriptor;
  41. if (!__go_type_descriptors_equal (v1_descriptor, v2_descriptor))
  42. return 0;
  43. if (__go_is_pointer_type (v1_descriptor))
  44. return v1->__object == v2->__object;
  45. else
  46. return v1_descriptor->__equalfn (v1->__object, v2->__object,
  47. v1_descriptor->__size);
  48. }