ObjFW  Changes On Branch d559a8b0a38c6b18

Changes In Branch 0.8 Through [d559a8b0a3] Excluding Merge-Ins

This is equivalent to a diff from 6b8b7b6a7e to d559a8b0a3

2015-08-26
08:24
OFProcess: Send SIGTERM on close check-in: 397b4ee50b user: js tags: 0.8
2015-08-23
20:54
Documentation improvements check-in: d559a8b0a3 user: js tags: 0.8
10:42
OFBlock: Fix two bugs check-in: e9786625a7 user: js tags: 0.8
2015-08-21
17:51
Set version to 0.9-dev check-in: 9d505a482a user: js tags: trunk
2015-08-14
16:43
Branch for 0.8 check-in: e63c7f6f7d user: js tags: 0.8, 0.8-release
16:41
Update ChangeLog for 0.8 check-in: 6b8b7b6a7e user: js tags: trunk
09:44
ChangeLog: Remove trailing dots check-in: bebee54bff user: js tags: trunk

Modified configure.ac from [f7868ab464] to [42239fc479].

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







AC_INIT(ObjFW, 0.8-dev, js@webkeks.org)
AC_INIT(ObjFW, 0.8, js@webkeks.org)
BUILDSYS_INIT

AS_IF([test configure.ac -nt configure], [
	AC_MSG_ERROR([configure.ac is newer than configure! Run ./autogen.sh!])
])

AC_CONFIG_SRCDIR(src)
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528







-
+







])
test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \
	AC_MSG_ERROR(No asprintf and no snprintf returning required space!)

AC_CHECK_FUNCS([arc4random random], break)

AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl")
AC_CHECK_HEADERS(dlfcn.h)
AC_CHECK_HEADERS_ONCE(dlfcn.h)
case "$host_os" in
	netbsd*)
		dnl dladdr exists on NetBSD, but it is completely broken.
		dnl When using it with code that uses __thread, it freezes the
		dnl process so that it has to be killed using SIGKILL.
		dnl When disabling __thread, it doesn't freeze, but all symbols
		dnl are wrong.
591
592
593
594
595
596
597
598

599
600
601
602
603
604
605
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605







-
+







	AC_DEFINE(OF_HAVE_THREADS, 1, [Whether we have threads])
	AC_SUBST(USE_SRCS_THREADS, '${SRCS_THREADS}')

	AC_ARG_ENABLE(compiler-tls,
		AS_HELP_STRING([--disable-compiler-tls],
			[disable compiler thread local storage]))
	AS_IF([test x"$enable_compiler_tls" != x"no"], [
		AC_CHECK_HEADERS(threads.h, [
		AC_CHECK_HEADER(threads.h, [
			AC_DEFINE(OF_HAVE_THREADS_H, 1,
				[Whether we have threads.h])
		])

		AC_MSG_CHECKING(whether _Thread_local works)
		AC_TRY_LINK([
			static _Thread_local int x = 0;
763
764
765
766
767
768
769
770

771
772
773
774

775
776
777
778
779
780
781
763
764
765
766
767
768
769

770
771
772
773

774
775
776
777
778
779
780
781







-
+



-
+







	AC_CHECK_LIB(network, socket, LIBS="$LIBS -lnetwork")
	AC_CHECK_LIB(ws2_32, main, LIBS="$LIBS -lws2_32")

	AC_CHECK_HEADER(sys/socket.h, [
		AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1,
			[Whether we have sys/socket.h])
	])
	AC_CHECK_HEADERS(netinet/in.h, [
	AC_CHECK_HEADER(netinet/in.h, [
		AC_DEFINE(OF_HAVE_NETINET_IN_H, 1,
			[Whether we have netinet/in.h])
	])
	AC_CHECK_HEADERS(netinet/tcp.h, [
	AC_CHECK_HEADER(netinet/tcp.h, [
		AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1,
			[Whether we have netinet/tcp.h])
	])
	AC_CHECK_HEADERS([arpa/inet.h netdb.h])

	AC_CHECK_FUNCS([paccept accept4])

960
961
962
963
964
965
966
967

968
969
970
971
972
973
974
960
961
962
963
964
965
966

967
968
969
970
971
972
973
974







-
+







		;;
esac
AS_IF([test x"$have_processes" = x"yes"], [
	AC_SUBST(OFPROCESS_M, "OFProcess.m")
	AC_DEFINE(OF_HAVE_PROCESSES, 1, [Whether we have processes])
])

AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS_ONCE([sys/ioctl.h sys/termios.h])

AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
	AC_CHECK_HEADER(Foundation/NSObject.h, [
		AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m")
		AC_SUBST(BRIDGE, "bridge")

		AS_IF([test x"$enable_shared" != x"no"], [

Modified src/OFBlock.m from [c478213743] to [536f7c35b9].

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298

299
300
301
302
303
304

305
306
307
308
309
310
311
237
238
239
240
241
242
243



244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287



288
289
290
291
292
293

294
295
296
297
298
299

300
301
302
303
304
305
306
307







-
-
-





+
-
+


















-
+


















-
-
-





+
-
+





-
+







{
	int flags = flags_ & (OF_BLOCK_FIELD_IS_BLOCK |
	    OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF);

	if (src_ == NULL)
		return;

	if (flags_ & OF_BLOCK_BYREF_CALLER)
		return;

	switch (flags) {
	case OF_BLOCK_FIELD_IS_BLOCK:
		*(of_block_literal_t**)dst_ = _Block_copy(src_);
		break;
	case OF_BLOCK_FIELD_IS_OBJECT:
		if (!(flags_ & OF_BLOCK_BYREF_CALLER))
		*(id*)dst_ = [(id)src_ retain];
			*(id*)dst_ = [(id)src_ retain];
		break;
	case OF_BLOCK_FIELD_IS_BYREF:;
		of_block_byref_t *src = (of_block_byref_t*)src_;
		of_block_byref_t **dst = (of_block_byref_t**)dst_;

		if ((src->flags & OF_BLOCK_REFCOUNT_MASK) == 0) {
			if ((*dst = malloc(src->size)) == NULL) {
				alloc_failed_exception.isa =
				    [OFAllocFailedException class];
				@throw (OFAllocFailedException*)
				    &alloc_failed_exception;
			}

			if (src->forwarding == src)
				(*dst)->forwarding = *dst;

			memcpy(*dst, src, src->size);

			if (src->size >= sizeof(of_block_byref_t))
			if (src->flags & OF_BLOCK_HAS_COPY_DISPOSE)
				src->byref_keep(*dst, src);
		} else
			*dst = src;

		(*dst)->flags++;
		break;
	}
}

void
_Block_object_dispose(const void *obj_, const int flags_)
{
	const int flags = flags_ & (OF_BLOCK_FIELD_IS_BLOCK |
	    OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF);

	if (obj_ == NULL)
		return;

	if (flags_ & OF_BLOCK_BYREF_CALLER)
		return;

	switch (flags) {
	case OF_BLOCK_FIELD_IS_BLOCK:
		_Block_release(obj_);
		break;
	case OF_BLOCK_FIELD_IS_OBJECT:
		if (!(flags_ & OF_BLOCK_BYREF_CALLER))
		[(id)obj_ release];
			[(id)obj_ release];
		break;
	case OF_BLOCK_FIELD_IS_BYREF:;
		of_block_byref_t *obj = (of_block_byref_t*)obj_;

		if ((--obj->flags & OF_BLOCK_REFCOUNT_MASK) == 0) {
			if (obj->size >= sizeof(of_block_byref_t))
			if (obj->flags & OF_BLOCK_HAS_COPY_DISPOSE)
				obj->byref_dispose(obj);

			free(obj);
		}
		break;
	}
}

Modified src/OFFile.h from [03d8a7c1d4] to [26137313b3].

149
150
151
152
153
154
155


156
157
158
159
160
161

162


163

164
165
166
167
168

169



170

171
172
173
174
175

176



177

178
179
180
181
182
183
184
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166

167
168
169
170
171

172
173
174
175
176

177
178
179
180
181

182
183
184
185
186

187
188
189
190
191
192
193
194







+
+





-
+

+
+
-
+




-
+

+
+
+
-
+




-
+

+
+
+
-
+







 * @param path The new directory to change to
 */
+ (void)changeCurrentDirectoryPath: (OFString*)path;

/*!
 * @brief Returns the size of the specified file.
 *
 * @param path The path to the file whose path should be returned
 *
 * @return The size of the specified file
 */
+ (of_offset_t)sizeOfFileAtPath: (OFString*)path;

/*!
 * @brief Returns the last access time of the specified file.
 * @brief Returns the last access time of the specified item.
 *
 * @param path The path to the file whose last access time should be returned
 *
 * @return The last access time of the specified file
 * @return The last access time of the specified item
 */
+ (OFDate*)accessTimeOfItemAtPath: (OFString*)path;

/*!
 * @brief Returns the last modification time of the specified file.
 * @brief Returns the last modification time of the specified item.
 *
 * @param path The path to the file whose last modification time should be
 *	       returned
 *
 * @return The last modification time of the specified file
 * @return The last modification time of the specified item
 */
+ (OFDate*)modificationTimeOfItemAtPath: (OFString*)path;

/*!
 * @brief Returns the last status change time of the specified file.
 * @brief Returns the last status change time of the specified item.
 *
 * @param path The path to the file whose last status change time should be
 *	       returned
 *
 * @return The last status change time of the specified file
 * @return The last status change time of the specified item
 */
+ (OFDate*)statusChangeTimeOfItemAtPath: (OFString*)path;

#ifdef OF_HAVE_CHMOD
/*!
 * @brief Changes the permissions of an item.
 *
280
281
282
283
284
285
286

287
288
289
290
291
292
293
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304







+







+ (void)createSymbolicLinkAtPath: (OFString*)destination
	     withDestinationPath: (OFString*)source;

/*!
 * @brief Returns the destination of the symbolic link at the specified path.
 *
 * @param path The path to the symbolic link
 *
 * @return The destination of the symbolic link at the specified path
 */
+ (OFString*)destinationOfSymbolicLinkAtPath: (OFString*)path;
#endif

/*!
 * @brief Initializes an already allocated OFFile.

Modified src/OFFile.m from [2c4c5b7c7a] to [da1fb6d2d1].

115
116
117
118
119
120
121
122

123
124
125

126
127
128
129
130
131
132
115
116
117
118
119
120
121

122
123
124

125
126
127
128
129
130
131
132







-
+


-
+







# define S_IWOTH 0
#endif

#define DEFAULT_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
#define DIR_MODE DEFAULT_MODE | S_IXUSR | S_IXGRP | S_IXOTH

#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;
static of_mutex_t chownMutex;
#endif
#if !defined(HAVE_READDIR_R) && !defined(_WIN32) && defined(OF_HAVE_THREADS)
static of_mutex_t mutex;
static of_mutex_t readdirMutex;
#endif

int
of_stat(OFString *path, of_stat_t *buffer)
{
#if defined(_WIN32)
	return _wstat64([path UTF16String], buffer);
203
204
205
206
207
208
209
210

211
212
213
214
215
216

217
218
219
220
221
222
223
203
204
205
206
207
208
209

210
211
212
213
214
215

216
217
218
219
220
221
222
223







-
+





-
+







@implementation OFFile
+ (void)initialize
{
	if (self != [OFFile class])
		return;

#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
	if (!of_mutex_new(&mutex))
	if (!of_mutex_new(&chownMutex))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif

#if !defined(HAVE_READDIR_R) && !defined(_WIN32) && defined(OF_HAVE_THREADS)
	if (!of_mutex_new(&mutex))
	if (!of_mutex_new(&readdirMutex))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif

#ifdef __wii__
	if (!fatInitDefault())
		@throw [OFInitializationFailedException
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409







-
+







	encoding = [OFSystemInfo native8BitEncoding];

	if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
		@throw [OFOpenItemFailedException exceptionWithPath: path
							      errNo: errno];

# if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS)
	if (!of_mutex_lock(&mutex))
	if (!of_mutex_lock(&readdirMutex))
		@throw [OFLockFailedException exception];
# endif

	@try {
		for (;;) {
			struct dirent *dirent;
# ifdef HAVE_READDIR_R
444
445
446
447
448
449
450
451

452
453
454
455
456
457
458
444
445
446
447
448
449
450

451
452
453
454
455
456
457
458







-
+







			[files addObject: file];

			objc_autoreleasePoolPop(pool);
		}
	} @finally {
		closedir(dir);
# if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS)
		if (!of_mutex_unlock(&mutex))
		if (!of_mutex_unlock(&readdirMutex))
			@throw [OFUnlockFailedException exception];
# endif
	}
#else
	void *pool = objc_autoreleasePoolPush();
	HANDLE handle;
	WIN32_FIND_DATAW fd;
606
607
608
609
610
611
612
613

614
615
616
617
618
619
620
606
607
608
609
610
611
612

613
614
615
616
617
618
619
620







-
+








	if (path == nil || (owner == nil && group == nil))
		@throw [OFInvalidArgumentException exception];

	encoding = [OFSystemInfo native8BitEncoding];

# ifdef OF_HAVE_THREADS
	if (!of_mutex_lock(&mutex))
	if (!of_mutex_lock(&chownMutex))
		@throw [OFLockFailedException exception];

	@try {
# endif
		if (owner != nil) {
			struct passwd *passwd;

640
641
642
643
644
645
646
647

648
649
650
651
652
653
654
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654







-
+







						group: group
						errNo: errno];

			gid = group_->gr_gid;
		}
# ifdef OF_HAVE_THREADS
	} @finally {
		if (!of_mutex_unlock(&mutex))
		if (!of_mutex_unlock(&chownMutex))
			@throw [OFUnlockFailedException exception];
	}
# endif

	if (chown([path cStringWithEncoding: encoding], uid, gid) != 0)
		@throw [OFChangeOwnerFailedException exceptionWithPath: path
								 owner: owner

Modified utils/ofhttp/ProgressBar.m from [e84b0f1e4e] to [ea91008bdd].

13
14
15
16
17
18
19


20
21
22



23
24
25
26
27
28
29
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+
+



+
+
+







 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <math.h>

#include <unistd.h>

#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_TERMIOS_H
# include <sys/termios.h>
#endif

#import "OFDate.h"
#import "OFStdIOStream.h"
#import "OFTimer.h"

#import "ProgressBar.h"