1/* Area:	ffi_call
2   Purpose:	Check raising/catching exceptions
3   Limitations:	none.
4   PR:		none.
5   Originator:	Ronald Oussoren */
6
7/* { dg-do run } */
8#include "ffitest.h"
9#import <Foundation/Foundation.h>
10
11static void
12closure_raise(ffi_cif* cif,void* resp,void** args, void* userdata)
13{
14  [NSException raise:NSInvalidArgumentException format:@"Dummy exception"];
15}
16
17
18typedef void (*testfunc)(void);
19
20int main (void)
21{
22  ffi_cif cif;
23  ffi_type *args[MAX_ARGS];
24  void *values[MAX_ARGS];
25  int ok;
26
27#ifndef USING_MMAP
28  static ffi_closure cl;
29#endif
30  ffi_closure *pcl;
31
32#ifdef USING_MMAP
33  pcl = allocate_mmap (sizeof(ffi_closure));
34#else
35  pcl = &cl;
36#endif
37
38 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
39
40
41
42
43
44  /* Initialize the cif */
45  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0,
46		     &ffi_type_void, args) == FFI_OK);
47
48  CHECK(ffi_prep_closure(pcl, &cif, closure_raise,
49                         (void *) 3 /* userdata */) == FFI_OK);
50  ok = 0;
51  NS_DURING
52	((testfunc)pcl)();
53  NS_HANDLER
54 	ok = 1;
55
56  NS_ENDHANDLER
57
58  CHECK(ok);
59
60  [pool release];
61  exit(0);
62}
63