ObjFW  Check-in [cf4be9e865]

Overview
Comment:Don't try to use SIG{HUP,USR1,USR2} on Windows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.6
Files: files | file ages | folders
SHA3-256: cf4be9e86569d4f49a7a9523c6f9bc3c70266500f2002dfc4c554cd68049173f
User & Date: js on 2012-02-21 19:59:43
Other Links: branch diff | manifest | tags
Context
2012-02-24
20:38
Don't use OF_INLINE where the function contains a @try block.
Doing so does not work if exceptions are SJLJ.
check-in: c8a5922af2 user: js tags: 0.6
2012-02-21
19:59
Don't try to use SIG{HUP,USR1,USR2} on Windows. check-in: cf4be9e865 user: js tags: 0.6
16:42
Add a missing include. check-in: dadf8a1a1f user: js tags: 0.6
Changes

Modified src/OFApplication.h from [1bcf3be869] to [1aa58a5990].

57
58
59
60
61
62
63

64
65


66
67
68
69
70
71
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
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGINT;


/**
 * \brief A method which is called when the application received a SIGHUP.


 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGHUP;

/**
 * \brief A method which is called when the application received a SIGUSR1.


 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR1;

/**
 * \brief A method which is called when the application received a SIGUSR2.


 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR2;

@end

/**
 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFString *programName;
	OFMutableArray *arguments;
	OFMutableDictionary *environment;
	int *argc;
	char ***argv;
@public
	id <OFApplicationDelegate> delegate;
	void (*SIGINTHandler)(id, SEL);

	void (*SIGHUPHandler)(id, SEL);
	void (*SIGUSR1Handler)(id, SEL);
	void (*SIGUSR2Handler)(id, SEL);

}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, assign) OFString *programName;
@property (readonly, assign) OFArray *arguments;
@property (readonly, assign) OFDictionary *environment;
@property (assign) id <OFApplicationDelegate> delegate;







>


>
>










>
>










>
>







>















>



>







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
124
125
126
127
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGINT;

#ifndef _WIN32
/**
 * \brief A method which is called when the application received a SIGHUP.
 *
 * This signal is not available on Windows.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGHUP;

/**
 * \brief A method which is called when the application received a SIGUSR1.
 *
 * This signal is not available on Windows.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR1;

/**
 * \brief A method which is called when the application received a SIGUSR2.
 *
 * This signal is not available on Windows.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR2;
#endif
@end

/**
 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFString *programName;
	OFMutableArray *arguments;
	OFMutableDictionary *environment;
	int *argc;
	char ***argv;
@public
	id <OFApplicationDelegate> delegate;
	void (*SIGINTHandler)(id, SEL);
#ifndef _WIN32
	void (*SIGHUPHandler)(id, SEL);
	void (*SIGUSR1Handler)(id, SEL);
	void (*SIGUSR2Handler)(id, SEL);
#endif
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, assign) OFString *programName;
@property (readonly, assign) OFArray *arguments;
@property (readonly, assign) OFDictionary *environment;
@property (assign) id <OFApplicationDelegate> delegate;

Modified src/OFApplication.m from [771a8d1673] to [4213526325].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "config.h"

#define OF_APPLICATION_M

#include <stdlib.h>
#include <string.h>

#ifndef _WIN32
# include <signal.h>
#endif

#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"








<
|
<







17
18
19
20
21
22
23

24

25
26
27
28
29
30
31
#include "config.h"

#define OF_APPLICATION_M

#include <stdlib.h>
#include <string.h>


#include <signal.h>


#import "OFApplication.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"

55
56
57
58
59
60
61

62
63
64

65
66
67
68
69
70
71
	static void						\
	handle##sig(int signal)					\
	{							\
		app->sig##Handler(app->delegate,		\
		    @selector(applicationDidReceive##sig));	\
	}
SIGNAL_HANDLER(SIGINT)

SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
SIGNAL_HANDLER(SIGUSR2)

#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];







>



>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	static void						\
	handle##sig(int signal)					\
	{							\
		app->sig##Handler(app->delegate,		\
		    @selector(applicationDidReceive##sig));	\
	}
SIGNAL_HANDLER(SIGINT)
#ifndef _WIN32
SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
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];
260
261
262
263
264
265
266

267
268
269

270
271
272
273
274
275
276
	if (sig##Handler != (void(*)(id, SEL))[OFObject			  \
	    instanceMethodForSelector:					  \
	    @selector(applicationDidReceive##sig)])			  \
		signal(sig, handle##sig);				  \
	else								  \
		signal(sig, SIG_DFL);
	REGISTER_SIGNAL(SIGINT)

	REGISTER_SIGNAL(SIGHUP)
	REGISTER_SIGNAL(SIGUSR1)
	REGISTER_SIGNAL(SIGUSR2)

#undef REGISTER_SIGNAL
}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}







>



>







260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
	if (sig##Handler != (void(*)(id, SEL))[OFObject			  \
	    instanceMethodForSelector:					  \
	    @selector(applicationDidReceive##sig)])			  \
		signal(sig, handle##sig);				  \
	else								  \
		signal(sig, SIG_DFL);
	REGISTER_SIGNAL(SIGINT)
#ifndef _WIN32
	REGISTER_SIGNAL(SIGHUP)
	REGISTER_SIGNAL(SIGUSR1)
	REGISTER_SIGNAL(SIGUSR2)
#endif
#undef REGISTER_SIGNAL
}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}