OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc/] [execute/] [exceptions/] [catchall-1.m] - Blame information for rev 859

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 307 jeremybenn
/* Test out '@catch(id foo) {...}', which should catch all uncaught
2
   exceptions.  */
3
/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
4
 
5
#include <stdio.h>
6
#include <stdlib.h>
7
#import "../../../objc-obj-c++-shared/Object1.h"
8
 
9
/* The following is not required in actual user code; we include it
10
   here to check that the compiler generates an internal definition of
11
   _setjmp that is consistent with what <setjmp.h> provides.  */
12
#include <setjmp.h>
13
 
14
#define CHECK_IF(expr) if(!(expr)) abort()
15
 
16
@interface Frob: Object
17
@end
18
 
19
@implementation Frob: Object
20
@end
21
 
22
static Frob* _connection = nil;
23
 
24
//--------------------------------------------------------------------
25
 
26
 
27
void test (Object* sendPort)
28
{
29
        int cleanupPorts = 1;
30
        Frob* receivePort = nil;
31
 
32
        @try {
33
                printf ("receivePort = %p\n", receivePort);
34
                printf ("sendPort = %p\n", sendPort);
35
                printf ("cleanupPorts = %d\n", cleanupPorts);
36
                printf ("---\n");
37
 
38
                receivePort = (Frob *) -1;
39
                _connection = (Frob *) -1;
40
                printf ("receivePort = %p\n", receivePort);
41
                printf ("sendPort = %p\n", sendPort);
42
                printf ("cleanupPorts = %d\n", cleanupPorts);
43
                printf ("---\n");
44
 
45
                receivePort = nil;
46
                sendPort = nil;
47
                cleanupPorts = 0;
48
 
49
                printf ("receivePort = %p\n", receivePort);
50
                printf ("sendPort = %p\n", sendPort);
51
                printf ("cleanupPorts = %d\n", cleanupPorts);
52
                printf ("---\n");
53
 
54
                @throw [Object new];
55
        }
56
        @catch(Frob *obj) {
57
                printf ("Exception caught by incorrect handler!\n");
58
                CHECK_IF(0);
59
        }
60
        @catch(id exc) {
61
                printf ("Exception caught by correct handler.\n");
62
                printf ("receivePort = %p (expected 0x0)\n", receivePort);
63
                printf ("sendPort = %p (expected 0x0)\n", sendPort);
64
                printf ("cleanupPorts = %d (expected 0)\n", cleanupPorts);
65
                printf ("---");
66
                CHECK_IF(!receivePort);
67
                CHECK_IF(!sendPort);
68
                CHECK_IF(!cleanupPorts);
69
        }
70
}
71
 
72
int main (void) {
73
 
74
        test((Object *)-1);
75
        return 0;
76
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.