go-eface-val-compare.c 1022 B

12345678910111213141516171819202122232425262728293031323334
  1. /* go-eface-val-compare.c -- compare an empty interface with a value.
  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 "go-type.h"
  7. #include "interface.h"
  8. /* Compare an empty interface with a value. Return 0 for equal, not
  9. zero for not equal (return value is like strcmp). */
  10. intgo
  11. __go_empty_interface_value_compare (
  12. struct __go_empty_interface left,
  13. const struct __go_type_descriptor *right_descriptor,
  14. const void *val)
  15. {
  16. const struct __go_type_descriptor *left_descriptor;
  17. left_descriptor = left.__type_descriptor;
  18. if (left_descriptor == NULL)
  19. return 1;
  20. if (!__go_type_descriptors_equal (left_descriptor, right_descriptor))
  21. return 1;
  22. if (__go_is_pointer_type (left_descriptor))
  23. return left.__object == val ? 0 : 1;
  24. if (!left_descriptor->__equalfn (left.__object, val,
  25. left_descriptor->__size))
  26. return 1;
  27. return 0;
  28. }