go-check-interface.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* go-check-interface.c -- check an interface type for a conversion
  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-panic.h"
  7. #include "go-type.h"
  8. #include "interface.h"
  9. /* Check that an interface type matches for a conversion to a
  10. non-interface type. This panics if the types are bad. The actual
  11. extraction of the object is inlined. */
  12. void
  13. __go_check_interface_type (
  14. const struct __go_type_descriptor *lhs_descriptor,
  15. const struct __go_type_descriptor *rhs_descriptor,
  16. const struct __go_type_descriptor *rhs_inter_descriptor)
  17. {
  18. if (rhs_descriptor == NULL)
  19. {
  20. struct __go_empty_interface panic_arg;
  21. runtime_newTypeAssertionError(NULL, NULL, lhs_descriptor->__reflection,
  22. NULL, &panic_arg);
  23. __go_panic(panic_arg);
  24. }
  25. if (lhs_descriptor != rhs_descriptor
  26. && !__go_type_descriptors_equal (lhs_descriptor, rhs_descriptor)
  27. && ((lhs_descriptor->__code & GO_CODE_MASK) != GO_UNSAFE_POINTER
  28. || !__go_is_pointer_type (rhs_descriptor))
  29. && ((rhs_descriptor->__code & GO_CODE_MASK) != GO_UNSAFE_POINTER
  30. || !__go_is_pointer_type (lhs_descriptor)))
  31. {
  32. struct __go_empty_interface panic_arg;
  33. runtime_newTypeAssertionError(rhs_inter_descriptor->__reflection,
  34. rhs_descriptor->__reflection,
  35. lhs_descriptor->__reflection,
  36. NULL, &panic_arg);
  37. __go_panic(panic_arg);
  38. }
  39. }