ObjFW  Check-in [54b38752bb]

Overview
Comment:OF_APPLICATION_DELEGATE(): Improve type checking

This is done at compile time now rather than at runtime.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 54b38752bb8316350763f77927fe2b09eb92dd69ae2f3a3a0a7f890a6673ef2c
User & Date: js on 2017-11-22 01:05:29
Other Links: manifest | tags
Context
2017-11-26
14:29
OFData: Change no copy handling check-in: 6cf7d6c33e user: js tags: trunk
2017-11-22
01:05
OF_APPLICATION_DELEGATE(): Improve type checking check-in: 54b38752bb user: js tags: trunk
00:47
OF_APPLICATION_DELEGATE(): Verify conformance check-in: eba39f1c9d user: js tags: trunk
Changes

Modified src/OFApplication.h from [21318ded74] to [b0172a54c9].

27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
@class OFSandbox;
@class OFString;

#define OF_APPLICATION_DELEGATE(cls)					\
	int								\
	main(int argc, char *argv[])					\
	{								\
		return of_application_main(&argc, &argv, [cls class]);	\

	}

#ifdef OF_HAVE_PLEDGE
# define OF_HAVE_SANDBOX
#endif

/*!







|
>







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@class OFSandbox;
@class OFString;

#define OF_APPLICATION_DELEGATE(cls)					\
	int								\
	main(int argc, char *argv[])					\
	{								\
		return of_application_main(&argc, &argv,		\
		    (cls *)[[cls alloc] init]);				\
	}

#ifdef OF_HAVE_PLEDGE
# define OF_HAVE_SANDBOX
#endif

/*!
253
254
255
256
257
258
259
260
261
262
263
264
265
#endif
@end

#ifdef __cplusplus
extern "C" {
#endif
extern int of_application_main(int *_Nonnull,
    char *_Nonnull *_Nonnull[_Nonnull], Class);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END







|





254
255
256
257
258
259
260
261
262
263
264
265
266
#endif
@end

#ifdef __cplusplus
extern "C" {
#endif
extern int of_application_main(int *_Nonnull,
    char *_Nonnull *_Nonnull[_Nonnull], id <OFApplicationDelegate>);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/OFApplication.m from [34ff9074e3] to [9f443dae6c].

111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#endif
#ifdef SIGUSR2
SIGNAL_HANDLER(SIGUSR2)
#endif
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)

{
	id <OFApplicationDelegate> delegate;
#ifdef OF_WINDOWS
	wchar_t **wargv, **wenvp;
	int wargc, si = 0;
#endif

	[[OFLocalization alloc] init];

	if (![cls conformsToProtocol: @protocol(OFApplicationDelegate)]) {
		fprintf(stderr, "FATAL ERROR:\n  Class %s does not conform to "
		    "protocol OFApplicationDelegate,\n  but was specified via "
		    "OF_APPLICATION_DELEGATE()!\n", class_getName(cls));
		exit(1);
	}

	app = [[OFApplication alloc] of_init];

	[app of_setArgumentCount: argc
	       andArgumentValues: argv];

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

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

	[app of_run];

	[delegate release];

	return 0;







|
>

<







<
<
<
<
<
<
<











<







111
112
113
114
115
116
117
118
119
120

121
122
123
124
125
126
127







128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
#endif
#ifdef SIGUSR2
SIGNAL_HANDLER(SIGUSR2)
#endif
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[],
    id <OFApplicationDelegate> delegate)
{

#ifdef OF_WINDOWS
	wchar_t **wargv, **wenvp;
	int wargc, si = 0;
#endif

	[[OFLocalization alloc] init];








	app = [[OFApplication alloc] of_init];

	[app of_setArgumentCount: argc
	       andArgumentValues: argv];

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


	[app setDelegate: delegate];

	[app of_run];

	[delegate release];

	return 0;

Modified tests/TestsAppDelegate.m from [32055328b2] to [c62c58f9b6].

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	consoleInit(GFX_TOP, NULL);
#endif

#if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \
	defined(OF_NINTENDO_3DS)
	@try {
		return of_application_main(&argc, &argv,
		    [TestsAppDelegate class]);
	} @catch (id e) {
		TestsAppDelegate *delegate =
		    [[OFApplication sharedApplication] delegate];
		OFString *string = [OFString stringWithFormat:
		    @"\nRuntime error: Unhandled exception:\n%@\n", e];
		OFString *backtrace = [OFString stringWithFormat:
		    @"\nBacktrace:\n  %@\n\n",







|







144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	consoleInit(GFX_TOP, NULL);
#endif

#if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \
	defined(OF_NINTENDO_3DS)
	@try {
		return of_application_main(&argc, &argv,
		    [[TestsAppDelegate alloc] init]);
	} @catch (id e) {
		TestsAppDelegate *delegate =
		    [[OFApplication sharedApplication] delegate];
		OFString *string = [OFString stringWithFormat:
		    @"\nRuntime error: Unhandled exception:\n%@\n", e];
		OFString *backtrace = [OFString stringWithFormat:
		    @"\nBacktrace:\n  %@\n\n",
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
			gspWaitForVBlank();
		}
# else
		abort();
# endif
	}
#else
	return of_application_main(&argc, &argv, [TestsAppDelegate class]);

#endif
}

@implementation TestsAppDelegate
- (void)outputString: (OFString *)str
	     inColor: (int)color
{







|
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
			gspWaitForVBlank();
		}
# else
		abort();
# endif
	}
#else
	return of_application_main(&argc, &argv,
	    [[TestsAppDelegate alloc] init]);
#endif
}

@implementation TestsAppDelegate
- (void)outputString: (OFString *)str
	     inColor: (int)color
{