ObjFW  Check-in [fb79b7f369]

Overview
Comment:Print an error when OFApplication is subclassed.

It seems subclassing OFApplication instead of OFObject for the
application delegate is a common mistake.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fb79b7f369185aae41ef3d8ee78190bba9caf008d9b877d73a2c066c9060fdc5
User & Date: js on 2013-02-22 12:15:19
Other Links: manifest | tags
Context
2013-02-23
10:03
Update to BinaryPack1pre1. check-in: 19f5a60438 user: js tags: trunk
2013-02-22
12:15
Print an error when OFApplication is subclassed. check-in: fb79b7f369 user: js tags: trunk
11:32
Fix ObjC++. check-in: 09bd870f8c user: js tags: trunk
Changes

Modified src/OFApplication.m from [10883a3ba0] to [ca5bc2d367].

72
73
74
75
76
77
78
79
80

81
82
83
84












85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116



117
118
119
120
121
122
123







-
-
+




+
+
+
+
+
+
+
+
+
+
+
+










+










-
-
-







SIGNAL_HANDLER(SIGUSR2)
#endif
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];
	id <OFApplicationDelegate> delegate;
#ifdef _WIN32
	wchar_t **wargv, **wenvp;
	int wargc, si = 0;
#endif

	if ([cls isSubclassOfClass: [OFApplication class]]) {
		fprintf(stderr, "FATAL ERROR:\n  Class %s is a subclass of "
		    "class OFApplication, but class\n  %s was specified as "
		    "application delegate!\n  Most likely, you wanted to "
		    "subclass OFObject instead or specified\n  the wrong class "
		    "with OF_APPLICATION_DELEGATE().\n",
		    class_getName(cls), class_getName(cls));
		exit(1);
	}

	app = [[OFApplication alloc] init];

	[app OF_setArgumentCount: argc
	       andArgumentValues: argv];

#ifdef _WIN32
	__wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si);
	[app OF_setArgumentCount: wargc
	   andWideArgumentValues: wargv];
#endif

	delegate = [[cls alloc] init];
	[app setDelegate: delegate];

	[app run];

	return 0;
}

@implementation OFApplication
+ (OFApplication*)sharedApplication
{
	if (app == nil)
		app = [[self alloc] init];

	return app;
}

+ (OFString*)programName
{
	return [app programName];
}