callback_c_gc.c 591 B

12345678910111213141516171819202122232425
  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build gc
  5. #include "_cgo_export.h"
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. /* Test calling panic from C. This is what SWIG does. */
  10. extern void crosscall2(void (*fn)(void *, int), void *, int);
  11. extern void _cgo_panic(void *, int);
  12. extern void _cgo_allocate(void *, int);
  13. void
  14. callPanic(void)
  15. {
  16. struct { const char *p; } a;
  17. a.p = "panic from C";
  18. crosscall2(_cgo_panic, &a, sizeof a);
  19. *(int*)1 = 1;
  20. }