ObjFW  Check-in [b885b6fdfa]

Overview
Comment:Add OF_NO_RETURN and OF_UNREACHABLE
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b885b6fdfa08a777d65d0d0525b93d0e864862e4c4cf4ad1aaae464a7d2094b9
User & Date: js on 2014-05-05 02:43:51
Other Links: manifest | tags
Context
2014-05-06
21:37
Update buildsys check-in: 9ca6458c5a user: js tags: trunk
2014-05-05
02:43
Add OF_NO_RETURN and OF_UNREACHABLE check-in: b885b6fdfa user: js tags: trunk
02:13
Check for and use __builtin_bswap{16,32,64} check-in: 2729104cf6 user: js tags: trunk
Changes

Modified src/OFApplication.h from [6ad0d38bc0] to [f01ba7a135].

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 * @return The environment of the application
 */
+ (OFDictionary*)environment;

/*!
 * @brief Terminates the application.
 */
+ (void)terminate;

/*!
 * @brief Terminates the application with the specified status.
 *
 * @param status The status with which the application will terminate
 */
+ (void)terminateWithStatus: (int)status;

/*!
 * @brief Gets args and argv.
 *
 * @param argc A pointer where a pointer to argc should be stored
 * @param argv A pointer where a pointer to argv should be stored
 */







|






|







160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 * @return The environment of the application
 */
+ (OFDictionary*)environment;

/*!
 * @brief Terminates the application.
 */
+ (void)terminate OF_NO_RETURN;

/*!
 * @brief Terminates the application with the specified status.
 *
 * @param status The status with which the application will terminate
 */
+ (void)terminateWithStatus: (int)status OF_NO_RETURN;

/*!
 * @brief Gets args and argv.
 *
 * @param argc A pointer where a pointer to argc should be stored
 * @param argv A pointer where a pointer to argv should be stored
 */

Modified src/OFDeflateStream.m from [a82b6b33ea] to [cefc6bbea9].

741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
			CTX.state = AWAIT_DISTANCE;
		}

		break;
#undef CTX
	}

	/* Get rid of a warning, never reached anyway */
	OF_ENSURE(0);
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}
@end







<
|







741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
			CTX.state = AWAIT_DISTANCE;
		}

		break;
#undef CTX
	}


	OF_UNREACHABLE
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}
@end

Modified src/OFMutableString_UTF8.m from [c7dede3563] to [d5efe167c0].

263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
		@try {
			_s->cString = [self
			    resizeMemory: _s->cString
				    size: _s->cStringLength + 1];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't really care, as we only made it smaller */
		}
	} else
		assert(0);

}

- (void)appendUTF8String: (const char*)UTF8String
{
	size_t UTF8StringLength = strlen(UTF8String);
	size_t length;








<
<
>







263
264
265
266
267
268
269


270
271
272
273
274
275
276
277
		@try {
			_s->cString = [self
			    resizeMemory: _s->cString
				    size: _s->cStringLength + 1];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't really care, as we only made it smaller */
		}


	}
}

- (void)appendUTF8String: (const char*)UTF8String
{
	size_t UTF8StringLength = strlen(UTF8String);
	size_t length;

Modified src/OFObject.h from [2a79ae4f27] to [14f340cddc].

89
90
91
92
93
94
95

96
97

98
99
100
101
102
103
104
#  undef false
#  define false ((bool)0)
# endif
#endif

#if defined(__clang__) || __GCC_VERSION__ >= 406
# define OF_SENTINEL __attribute__((sentinel))

#else
# define OF_SENTINEL

#endif

#if __has_attribute(objc_requires_super)
# define OF_REQUIRES_SUPER __attribute__((objc_requires_super))
#else
# define OF_REQUIRES_SUPER
#endif







>


>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#  undef false
#  define false ((bool)0)
# endif
#endif

#if defined(__clang__) || __GCC_VERSION__ >= 406
# define OF_SENTINEL __attribute__((sentinel))
# define OF_NO_RETURN __attribute__((noreturn))
#else
# define OF_SENTINEL
# define OF_NO_RETURN
#endif

#if __has_attribute(objc_requires_super)
# define OF_REQUIRES_SUPER __attribute__((objc_requires_super))
#else
# define OF_REQUIRES_SUPER
#endif
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
 * @brief Handles messages which are not understood by the receiver.
 *
 * @warning If you override this method, you must make sure that it never
 *	    returns.
 *
 * @param selector The selector not understood by the receiver
 */
- (void)doesNotRecognizeSelector: (SEL)selector;
@end

/*!
 * @protocol OFCopying OFObject.h ObjFW/OFObject.h
 *
 * @brief A protocol for the creation of copies.
 */







|







944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
 * @brief Handles messages which are not understood by the receiver.
 *
 * @warning If you override this method, you must make sure that it never
 *	    returns.
 *
 * @param selector The selector not understood by the receiver
 */
- (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN;
@end

/*!
 * @protocol OFCopying OFObject.h ObjFW/OFObject.h
 *
 * @brief A protocol for the creation of copies.
 */

Modified src/OFThread.h from [7e258abb92] to [bd27888ffe].

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 */
+ (void)yield;

#ifdef OF_HAVE_THREADS
/*!
 * @brief Terminates the current thread, letting it return nil.
 */
+ (void)terminate;

/*!
 * @brief Terminates the current thread, letting it return the specified object.
 *
 * @param object The object which the terminated thread will return
 */
+ (void)terminateWithObject: (id)object;

# ifdef OF_HAVE_BLOCKS
/*!
 * @brief Initializes an already allocated thread with the specified block.
 *
 * @param threadBlock A block which is executed by the thread
 * @return An initialized OFThread.







|






|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 */
+ (void)yield;

#ifdef OF_HAVE_THREADS
/*!
 * @brief Terminates the current thread, letting it return nil.
 */
+ (void)terminate OF_NO_RETURN;

/*!
 * @brief Terminates the current thread, letting it return the specified object.
 *
 * @param object The object which the terminated thread will return
 */
+ (void)terminateWithObject: (id)object OF_NO_RETURN;

# ifdef OF_HAVE_BLOCKS
/*!
 * @brief Initializes an already allocated thread with the specified block.
 *
 * @param threadBlock A block which is executed by the thread
 * @return An initialized OFThread.

Modified src/OFThread.m from [68ca15bbc7] to [75412d8593].

234
235
236
237
238
239
240







241
242
243
244
245
246
247
#endif
}

#ifdef OF_HAVE_THREADS
+ (void)terminate
{
	[self terminateWithObject: nil];







}

+ (void)terminateWithObject: (id)object
{
	OFThread *thread = of_tlskey_get(threadSelfKey);

	if (thread != nil) {







>
>
>
>
>
>
>







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#endif
}

#ifdef OF_HAVE_THREADS
+ (void)terminate
{
	[self terminateWithObject: nil];

	/*
	 * For some reason, Clang thinks terminateWithObject: can return - even
	 * though it is declared noreturn - and warns that terminate returns
	 * while being declared noreturn.
	 */
	OF_UNREACHABLE
}

+ (void)terminateWithObject: (id)object
{
	OFThread *thread = of_tlskey_get(threadSelfKey);

	if (thread != nil) {

Modified src/macros.h from [8621e81b30] to [c9c04d682a].

143
144
145
146
147
148
149






150
151
152
153

154
155
156
157
158
159
160
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)
#define OF_GETTER(ivar, atomic) \
	return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic);
#define OF_SETTER(ivar, value, atomic, copy) \
	objc_setProperty(self, _cmd, OF_IVAR_OFFSET(ivar), value, atomic, copy);







#define OF_UNRECOGNIZED_SELECTOR		\
	[self doesNotRecognizeSelector: _cmd];	\
	abort();

#define OF_INVALID_INIT_METHOD				\
	@try {						\
		[self doesNotRecognizeSelector: _cmd];	\
	} @catch (id e) {				\
		[self release];				\
		@throw e;				\
	}						\







>
>
>
>
>
>



<
>







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

159
160
161
162
163
164
165
166
extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, signed char);

#define OF_IVAR_OFFSET(ivar) ((intptr_t)&ivar - (intptr_t)self)
#define OF_GETTER(ivar, atomic) \
	return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic);
#define OF_SETTER(ivar, value, atomic, copy) \
	objc_setProperty(self, _cmd, OF_IVAR_OFFSET(ivar), value, atomic, copy);

#if defined(__clang__) || __GCC_VERSION__ >= 405
# define OF_UNREACHABLE __builtin_unreachable();
#else
# define OF_UNREACHABLE abort();
#endif

#define OF_UNRECOGNIZED_SELECTOR		\
	[self doesNotRecognizeSelector: _cmd];	\

	OF_UNREACHABLE
#define OF_INVALID_INIT_METHOD				\
	@try {						\
		[self doesNotRecognizeSelector: _cmd];	\
	} @catch (id e) {				\
		[self release];				\
		@throw e;				\
	}						\

Modified src/threading.h from [a65488fd6f] to [79cb0c24fe].

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	/* FIXME */
	return true;
#else
# error of_thread_detach not implemented!
#endif
}

static OF_INLINE void
of_thread_exit(void)
{
#if defined(OF_HAVE_PTHREADS)
	pthread_exit(NULL);
#elif defined(_WIN32)
	ExitThread(0);
#else







|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	/* FIXME */
	return true;
#else
# error of_thread_detach not implemented!
#endif
}

static OF_INLINE void OF_NO_RETURN
of_thread_exit(void)
{
#if defined(OF_HAVE_PTHREADS)
	pthread_exit(NULL);
#elif defined(_WIN32)
	ExitThread(0);
#else