closure1.c 504 B

12345678910111213141516171819202122232425262728
  1. /* { dg-do run } */
  2. #include "ffitest.h"
  3. void doit(ffi_cif *cif, void *rvalue, void **avalue, void *closure)
  4. {
  5. (void)cif;
  6. (void)avalue;
  7. *(void **)rvalue = closure;
  8. }
  9. typedef void * (*FN)(void);
  10. int main()
  11. {
  12. ffi_cif cif;
  13. ffi_go_closure cl;
  14. void *result;
  15. CHECK(ffi_prep_cif(&cif, ABI_NUM, 0, &ffi_type_pointer, NULL) == FFI_OK);
  16. CHECK(ffi_prep_go_closure(&cl, &cif, doit) == FFI_OK);
  17. ffi_call_go(&cif, FFI_FN(*(FN *)&cl), &result, NULL, &cl);
  18. CHECK(result == &cl);
  19. exit(0);
  20. }