interface.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* interface.h -- the interface type for Go.
  2. Copyright 2009 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. #ifndef LIBGO_INTERFACE_H
  6. #define LIBGO_INTERFACE_H
  7. struct __go_type_descriptor;
  8. /* A variable of interface type is an instance of this struct, if the
  9. interface has any methods. */
  10. struct __go_interface
  11. {
  12. /* A pointer to the interface method table. The first pointer is
  13. the type descriptor of the object. Subsequent pointers are
  14. pointers to functions. This is effectively the vtable for this
  15. interface. The function pointers are in the same order as the
  16. list in the internal representation of the interface, which sorts
  17. them by name. */
  18. const void **__methods;
  19. /* The object. If the object is a pointer--if the type descriptor
  20. code is GO_PTR or GO_UNSAFE_POINTER--then this field is the value
  21. of the object itself. Otherwise this is a pointer to memory
  22. which holds the value. */
  23. void *__object;
  24. };
  25. /* A variable of an empty interface type is an instance of this
  26. struct. */
  27. struct __go_empty_interface
  28. {
  29. /* The type descriptor of the object. */
  30. const struct __go_type_descriptor *__type_descriptor;
  31. /* The object. This is the same as __go_interface above. */
  32. void *__object;
  33. };
  34. extern void *
  35. __go_convert_interface (const struct __go_type_descriptor *,
  36. const struct __go_type_descriptor *);
  37. extern void *
  38. __go_convert_interface_2 (const struct __go_type_descriptor *,
  39. const struct __go_type_descriptor *,
  40. _Bool may_fail);
  41. extern _Bool
  42. __go_can_convert_to_interface(const struct __go_type_descriptor *,
  43. const struct __go_type_descriptor *);
  44. #endif /* !defined(LIBGO_INTERFACE_H) */